Skip to content

Commit d648454

Browse files
committed
use flake inputs
Add a fun little hack to specify the names for unpacking; otherwise you can't have multiple flake inputs as sources (since they all end in "-source").
1 parent 105aa54 commit d648454

File tree

3 files changed

+95
-46
lines changed

3 files changed

+95
-46
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/result
12
build/
23
/private*/
34
# A "local" directory for hiding scripts and artifacts from git.

flake.lock

Lines changed: 61 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,25 @@
66

77
zephyr-nix.url = github:adisbladis/zephyr-nix;
88
zephyr-nix.inputs.nixpkgs.follows = "nixpkgs";
9+
10+
cmsis.url = git+https://chromium.googlesource.com/chromiumos/third_party/zephyr/cmsis?rev=4aa3ff8e4f8a21e31cd9831b943acb7a7cd56ac8&name=cmsis;
11+
cmsis.flake = false;
12+
13+
zephyr.url = github:FrameworkComputer/zephyr?ref=lotus-zephyr&name=zephyr;
14+
zephyr.flake = false;
15+
16+
u-boot.url = git+https://chromium.googlesource.com/chromiumos/third_party/u-boot?ref=upstream/next&name=u-boot;
17+
u-boot.flake = false;
918
};
1019

1120
outputs = {
1221
self,
1322
nixpkgs,
1423
flake-utils,
1524
zephyr-nix,
25+
zephyr,
26+
cmsis,
27+
u-boot,
1628
}:
1729
flake-utils.lib.eachDefaultSystem (system: let
1830
pkgs = import nixpkgs {inherit system;};
@@ -27,36 +39,7 @@
2739
sed -e 's/dynamic = "license"/dynamic = ["license"]/' -i pyproject.toml
2840
'';
2941

30-
ec = pkgs.fetchFromGitHub {
31-
name = "ec";
32-
owner = "FrameworkComputer";
33-
repo = "EmbeddedController";
34-
rev = "fwk-lotus-azalea-19573";
35-
hash = "sha256-37iKyZdOy8K/a8fsvaTjiC9cTkcP0JbvsfB7t1XAIco=";
36-
};
37-
38-
cmsis = pkgs.fetchgit {
39-
name = "cmsis";
40-
url = "https://chromium.googlesource.com/chromiumos/third_party/zephyr/cmsis";
41-
rev = "4aa3ff8e4f8a21e31cd9831b943acb7a7cd56ac8";
42-
hash = "sha256-IKmdIn/K1eHBVxA0sNvzr1i5LpkgJQMAMsks13lmDNw=";
43-
};
44-
45-
zephyr = pkgs.fetchFromGitHub {
46-
name = "zephyr";
47-
owner = "FrameworkComputer";
48-
repo = "zephyr";
49-
rev = "lotus-zephyr";
50-
hash = "sha256-KgTh39Ba9jDByv7+9gDdZHCl2OOku3Y3yxq0Pt4GeBo=";
51-
};
52-
53-
u-boot = pkgs.fetchgit {
54-
name = "u-boot";
55-
url = "https://chromium.googlesource.com/chromiumos/third_party/u-boot";
56-
rev = "refs/heads/upstream/next";
57-
hash = "sha256-h5y0M1dupdO9CNG+OhUYi56UXsWAL5B0PTnhx+gU3FA=";
58-
fetchSubmodules = false;
59-
};
42+
ec = ./.;
6043

6144
build_version = "awawa";
6245

@@ -65,11 +48,22 @@
6548
name = build;
6649

6750
srcs = [
68-
ec
69-
cmsis
70-
zephyr
51+
"${ec}?ec"
52+
"${cmsis}?cmsis"
53+
"${zephyr}?zephyr"
7154
];
7255

56+
preUnpack=''
57+
unpackCmdHooks+=(_unpack_named)
58+
_unpack_named() {
59+
local src="$1"
60+
if ! [[ "$src" =~ ^(.*)\?([a-z]+)$ ]]; then return 1; fi
61+
local path="''${BASH_REMATCH[1]}"
62+
local name="''${BASH_REMATCH[2]}"
63+
cp -pr --reflink=auto -- "$path" "$name"
64+
}
65+
'';
66+
7367
sourceRoot = ".";
7468

7569
postPatch = ''
@@ -120,8 +114,8 @@
120114

121115
packages.zmake = pythonPkgs.buildPythonPackage {
122116
name = "zmake";
123-
src = ec;
124-
sourceRoot = "ec/zephyr/zmake";
117+
src = "${ec}/zephyr/zmake";
118+
125119
pyproject = true;
126120
build-system = [pythonPkgs.setuptools];
127121

@@ -140,10 +134,6 @@
140134
pyproject = false;
141135
build-system = [pythonPkgs.setuptools];
142136

143-
# zmake calls (sys.executable, path-to-binman, ...) on purpose, so we
144-
# can't wrap it. This makes it unsuitable for calling directly, however.
145-
dontWrapPythonPrograms = true;
146-
147137
buildInputs = [
148138
pythonPkgs.pypaBuildHook
149139
pythonPkgs.pipInstallHook
@@ -161,6 +151,10 @@
161151
${setProjectDynamicToLicense}
162152
'';
163153

154+
# zmake calls (sys.executable, path-to-binman, ...) on purpose, so we
155+
# can't wrap it. This makes it unsuitable for calling directly, however.
156+
dontWrapPythonPrograms = true;
157+
164158
# No wrapper => no need for args. I'd like to be able to still do this
165159
# to have a nicer binman derivation.
166160
# makeWrapperArgs = ["--set DYLD_LIBRARY_PATH ${pkgs.dtc}/lib"];

0 commit comments

Comments
 (0)