{ pkgs ? import <nixpkgs> {} }: let # esp-idf as of Nov 2019 requires pyparsing < 2.4 python2 = let packageOverrides = self: super: { pyparsing = super.pyparsing.overridePythonAttrs( old: rec { version = "2.3.1"; src = super.fetchPypi { pname="pyparsing"; inherit version; sha256="66c9268862641abcac4a96ba74506e594c884e3f57690a696d21ad8210ed667a"; }; }); }; in pkgs.python2.override{inherit packageOverrides; self=python2;}; qthingDependencies = with pkgs; [ gawk gperf gettext automake bison flex texinfo help2man libtool autoconf ncurses5 bash (python2.withPackages (ppkgs: with ppkgs; [ pyserial future cryptography pyelftools click ])) (python3.withPackages (ppkgs: with ppkgs; [ paho-mqtt ])) (pkgs.callPackage ./esp32-toolchain.nix {}) ]; shellSetup = '' export NIX_CFLAGS_LINK=-lncurses export IDF_PATH=./esp-idf export IDF_TOOLS_PATH=$IDF_PATH/tools ''; in rec { shell = pkgs.stdenv.mkDerivation { name = "esp-idf-env"; buildInputs = qthingDependencies; shellHook = shellSetup; }; mkProject = { name, device, environment }: let src = pkgs.runCommand "${name}-src" {} '' cp --reflink=auto -r ${./.} $out chmod -R u+w $out cp --reflink=auto -r ${device} $out/main/device cp --reflink=auto ${environment} $out/main/environment.h ''; flashScript = pkgs.writeScript "flash" '' PATH=${pkgs.esptool}/bin/:$PATH cd @out@ esptool.py "$@" write_flash @flash_cmdline@ ''; in pkgs.stdenv.mkDerivation { inherit name src; buildInputs = qthingDependencies; configurePhase = shellSetup + '' patchShebangs esp-idf ''; buildPhase = '' make -j $NIX_BUILD_CORES flash_cmdline=$(make print_flash_cmd) substituteAll ${flashScript} build/flash chmod +x build/flash ''; installPhase = '' mkdir -p $out/bin mkdir -p $out/bootloader cp build/bootloader/bootloader.bin $out/bootloader cp build/{default,qthing}.bin $out cp build/flash $out/bin for path in "$(egrep --only-matching '/build/[^ ]+' $out/bin/flash)"; do cp $path $out/bootloader substituteInPlace $out/bin/flash --replace "$path" "bootloader/$(basename $path)" done ''; }; }