Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{ 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
'';
};
}