Newer
Older
packageOverrides = self: super: {
pyparsing = super.pyparsing.overridePythonAttrs( old: rec {
version = "2.3.1";
src = super.fetchPypi {
pname="pyparsing";
inherit version;
sha256="66c9268862641abcac4a96ba74506e594c884e3f57690a696d21ad8210ed667a";
};
});
};
in pkgs.python3.override{inherit packageOverrides;};
python3RequiredPackages = p: with p; [
p.setuptools
p.click
p.pyserial
p.future
p.cryptography
p.pyparsing
p.pyelftools
];
toolchain = pkgs.callPackage ./esp32-toolchain.nix {};
cmake (python3'.withPackages python3RequiredPackages) git ncurses flex bison gperf ninja toolchain
idfWrapper = pkgs.writeShellScriptBin "idf.py" ''
PATH=${pkgs.lib.strings.makeBinPath qthingDependencies}
args=""
[ -n "$QTHING_PATH" ] && args="--project-dir=$QTHING_PATH --build-dir=$QTHING_PATH/build "
exec $IDF_TOOLS_PATH/idf.py $args "$@"
'';
clangdWrapper = pkgs.writeShellScriptBin "clangd" ''
args='--query-driver=${toolchain}/bin/* '
[ -n "$QTHING_PATH" ] && args+="--compile-commands-dir=$QTHING_PATH/build "
exec ${pkgs.llvmPackages_10.clang-unwrapped}/bin/clangd $args "$@"
'';
qthingBaseRepo = pkgs.runCommand "qthing" {} ''
mkdir -p $out/qthing/include
ln -s ${./CMakeLists.txt} $out/CMakeLists.txt
ln -s ${./components} $out/components
ln -s ${./esp-idf} $out/esp-idf
ln -s ${./sdkconfig} $out/sdkconfig
cd ${./qthing}
for file in *; do
[[ "$file" == include ]] && continue
ln -s $(realpath $file) $out/qthing/$file
for file in *; do
[[ "$file" == environment.h ]] && continue
ln -s $(realpath $file) $out/qthing/include/$file
in rec {
shell = pkgs.stdenv.mkDerivation {
name = "esp-idf-env";
buildInputs = qthingDependencies ++ [pkgs.zsh];
envrc = pkgs.writeText ".envrc" ''
PATH_add ${idfWrapper}/bin
PATH_add ${clangdWrapper}/bin
PATH_add ${./bin}
export QTHING_PATH=$(expand_path .)
${shellSetup}
'';
mkProject = { name, src, environment }: let
flashScript = pkgs.writeScript "flash" ''
PATH=${pkgs.esptool}/bin/:$PATH
cd @out@
esptool.py "$@" write_flash @flash_cmdline@
'';
defaultDeviceConfig = pkgs.writeText "device_config.h" ''
#define DEVICE_NAME "${name}"
'';
defaultCMakeLists = pkgs.writeText "CMakeLists.txt" ''
idf_component_register(SRC_DIRS "." INCLUDE_DIRS "." REQUIRES main)
'';
unpackPhase = ''
cp --reflink=auto -r ${qthingBaseRepo}/* ./
cp --reflink=auto -r ${src} ./main
chmod u+w ./qthing/include ./main
if [[ ! -f main/device_config.h ]]; then
ln -s ${defaultDeviceConfig} main/device_config.h
fi
if [[ ! -f main/CMakeLists.txt ]]; then
ln -s ${defaultCMakeLists} main/CMakeLists.txt
fi
cp --reflink=auto ${environment} ./qthing/include/environment.h
configurePhase = shellSetup + ''
patchShebangs esp-idf
ninja -C build -j $NIX_BUILD_CORES
flash_cmdline=$(cat build/flash_project_args | tr '\n' ' ') substituteAll ${flashScript} build/flash
chmod +x build/flash
'';
installPhase = ''
mkdir -p $out/bin
for path in $(cd build; find -iname '*.bin' -and -not -wholename '*/CMakeFiles/*'); do
mkdir -p $out/$(dirname $path)
cp build/$path $out/$path