forked from FrameworkComputer/EmbeddedController
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
229 lines (184 loc) · 6.23 KB
/
flake.nix
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
{
description = "Framework Laptop Embedded Controller (EC) build environment";
inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-unstable;
zephyr-nix.url = github:adisbladis/zephyr-nix;
zephyr-nix.inputs.nixpkgs.follows = "nixpkgs";
cmsis.url = git+https://chromium.googlesource.com/chromiumos/third_party/zephyr/cmsis?rev=4aa3ff8e4f8a21e31cd9831b943acb7a7cd56ac8&name=cmsis;
cmsis.flake = false;
zephyr.url = github:FrameworkComputer/zephyr?ref=lotus-zephyr&name=zephyr;
zephyr.flake = false;
u-boot.url = git+https://chromium.googlesource.com/chromiumos/third_party/u-boot?ref=upstream/next&name=u-boot;
u-boot.flake = false;
};
outputs = {
self,
nixpkgs,
flake-utils,
zephyr-nix,
zephyr,
cmsis,
u-boot,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
zephyr-sdk = zephyr-nix.packages.${system}.sdk-0_16.override {targets = ["arm-zephyr-eabi"];};
python = pkgs.python312;
pythonPkgs = pkgs.python312Packages;
setProjectDynamicToLicense = ''
${pkgs.toml-cli}/bin/toml set pyproject.toml project.dynamic license | ${pkgs.moreutils}/bin/sponge pyproject.toml
sed -e 's/dynamic = "license"/dynamic = ["license"]/' -i pyproject.toml
'';
ec = ./.;
build_version = "awawa";
mkBuild = packages: build:
pkgs.stdenv.mkDerivation {
name = build;
srcs = [
"${ec}?ec"
"${cmsis}?cmsis"
"${zephyr}?zephyr"
];
preUnpack = ''
unpackCmdHooks+=(_unpack_named)
_unpack_named() {
local src="$1"
if ! [[ "$src" =~ ^(.*)\?([a-z]+)$ ]]; then return 1; fi
local path="''${BASH_REMATCH[1]}"
local name="''${BASH_REMATCH[2]}"
cp -pr --reflink=auto -- "$path" "$name"
}
'';
sourceRoot = ".";
postPatch = ''
mkdir .repo
mkdir -p src/platform
mv ec src/platform/ec
mkdir -p src/third_party/zephyr
mv cmsis src/third_party/zephyr/cmsis
mkdir -p src/third_party/zephyr
mv zephyr src/third_party/zephyr/main
'';
nativeBuildInputs = [
zephyr-sdk
pkgs.cmake
pkgs.git
pkgs.ninja
pythonPkgs.pyyaml
pythonPkgs.pykwalify
pythonPkgs.packaging
pythonPkgs.pyelftools
pythonPkgs.colorama
packages.binman
];
dontUseCmakeConfigure = true;
buildPhase = ''
${packages.zmake}/bin/zmake -j8 build ${build}
'';
installPhase = ''
mkdir $out
cp src/platform/ec/build/zephyr/${build}/output/* $out/
'';
dontFixup = true;
};
in rec {
formatter = pkgs.alejandra;
packages.default = packages.lotus;
packages.lotus = mkBuild packages "lotus";
packages.azalea = mkBuild packages "azalea";
packages.zmake = pythonPkgs.buildPythonPackage {
name = "zmake";
src = "${ec}/zephyr/zmake";
pyproject = true;
build-system = [pythonPkgs.setuptools];
postPatch = ''
sed -e 's#"/bin:/usr/bin"#"/bin:/usr/bin:${pkgs.gcc}/bin:${pkgs.dtc}/bin:${pkgs.ninja}/bin"${
if pkgs.stdenv.hostPlatform.isDarwin
then '',"DYLD_LIBRARY_PATH":"${pkgs.dtc}/lib"''
else ""
}#' -i zmake/jobserver.py
'';
};
packages.binman = pythonPkgs.buildPythonPackage {
name = "binman";
src = "${u-boot}/tools/binman";
pyproject = false;
build-system = [pythonPkgs.setuptools];
buildInputs = [
pythonPkgs.pypaBuildHook
pythonPkgs.pipInstallHook
];
dependencies = [
pythonPkgs.setuptools
packages.u_boot_pylib
pythonPkgs.libfdt
packages.dtoc
];
postPatch = ''
sed -e 's/"pylibfdt"/"libfdt"/' -i pyproject.toml
${setProjectDynamicToLicense}
'';
# zmake calls (sys.executable, path-to-binman, ...) on purpose, so we
# can't wrap it. This makes it unsuitable for calling directly, however.
dontWrapPythonPrograms = true;
# No wrapper => no need for args. I'd like to be able to still do this
# to have a nicer binman derivation.
# makeWrapperArgs = ["--set DYLD_LIBRARY_PATH ${pkgs.dtc}/lib"];
};
packages.dtoc = pythonPkgs.buildPythonPackage {
name = "dtoc";
src = "${u-boot}/tools/dtoc";
pyproject = false;
build-system = [pythonPkgs.setuptools];
buildInputs = [
pythonPkgs.pypaBuildHook
pythonPkgs.pipInstallHook
];
dependencies = [
packages.u_boot_pylib
pythonPkgs.libfdt
];
postPatch = ''
sed -e 's/"pylibfdt"/"libfdt"/' -i pyproject.toml
${setProjectDynamicToLicense}
'';
makeWrapperArgs = ["--set DYLD_LIBRARY_PATH ${pkgs.dtc}/lib"];
};
packages.u_boot_pylib = pythonPkgs.buildPythonPackage {
name = "u_boot_pylib";
src = pkgs.fetchPypi {
pname = "u_boot_pylib";
version = "0.0.6";
sha256 = "mwbw339O51qNObu6Mn4FvLARI7Y6zSkdLxeCx49tNd0=";
};
pyproject = true;
buildInputs = [pythonPkgs.setuptools];
};
devShells.default = pkgs.mkShell {
name = "EmbeddedController";
buildInputs = [
zephyr-sdk
pkgs.cmake
pkgs.git
pkgs.ninja
pythonPkgs.pyyaml
pythonPkgs.pykwalify
pythonPkgs.packaging
pythonPkgs.pyelftools
pythonPkgs.colorama
pythonPkgs.setuptools
packages.zmake
packages.binman
];
shellHook = ''
mkdir -p .repo
rm -rf src
mkdir -p src/platform
ln -fs ../.. src/platform/ec
mkdir -p src/third_party/zephyr
ln -fs ${cmsis} src/third_party/zephyr/cmsis
ln -fs ${zephyr} src/third_party/zephyr/main
'';
};
});
}