|
1 | 1 | { zephyr-src |
2 | 2 | , pyproject-nix |
3 | 3 | , lib |
4 | | -, fetchurl |
5 | | -, python310 |
6 | 4 | , newScope |
7 | 5 | , openocd |
8 | 6 | , gcc_multi |
9 | 7 | , autoreconfHook |
10 | 8 | , fetchFromGitHub |
| 9 | +, pkgs |
11 | 10 | }: |
12 | 11 |
|
13 | | -let |
14 | | - sdk' = lib.importJSON ./sdk.json; |
15 | | - inherit (sdk') version; |
16 | | - |
17 | | - getPlatform = stdenv: |
18 | | - if stdenv.isLinux then "linux" |
19 | | - else if stdenv.isDarwin then "macos" |
20 | | - else throw "Unsupported platform"; |
21 | | - |
22 | | - getArch = stdenv: |
23 | | - if stdenv.isAarch64 then "aarch64" |
24 | | - else if stdenv.isx86_64 then "x86_64" |
25 | | - else throw "Unsupported arch"; |
26 | | - |
27 | | - baseURL = "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${version}"; |
28 | | - |
29 | | - fetchSDKFile = file: fetchurl { |
30 | | - url = "${baseURL}/${file}"; |
31 | | - sha256 = sdk'.files.${file}; |
32 | | - }; |
| 12 | +lib.makeScope newScope (self: let |
| 13 | + inherit (self) callPackage; |
33 | 14 |
|
34 | | - sdkArgs = { |
35 | | - python3 = python310; |
| 15 | + sdk = callPackage (import ./sdk.nix (lib.importJSON ./sdk.json)) { |
| 16 | + python3 = pkgs.python310; |
36 | 17 | }; |
37 | 18 |
|
38 | | -in |
39 | | -lib.makeScope newScope (self: let |
40 | | - inherit (self) callPackage; |
41 | 19 | in { |
| 20 | + inherit (sdk) sdk sdkFull hosttools; |
42 | 21 |
|
43 | 22 | # Zephyr/west Python environment. |
44 | 23 | pythonEnv = callPackage ./python.nix { |
45 | 24 | inherit zephyr-src; |
46 | 25 | inherit pyproject-nix; |
47 | 26 | }; |
48 | 27 |
|
49 | | - # Pre-package Zephyr SDK. |
50 | | - sdk = callPackage |
51 | | - ({ stdenv |
52 | | - , which |
53 | | - , cmake |
54 | | - , autoPatchelfHook |
55 | | - , libxcrypt-legacy |
56 | | - , ncurses |
57 | | - , python3 |
58 | | - , targets ? [ ] |
59 | | - }: |
60 | | - let |
61 | | - platform = getPlatform stdenv; |
62 | | - arch = getArch stdenv; |
63 | | - in |
64 | | - stdenv.mkDerivation { |
65 | | - pname = "zephyr-sdk"; |
66 | | - inherit version; |
67 | | - |
68 | | - srcs = [ |
69 | | - (fetchSDKFile "zephyr-sdk-${version}_${platform}-${arch}_minimal.tar.xz") |
70 | | - ] ++ map fetchSDKFile (map (target: "toolchain_${platform}-${arch}_${target}.tar.xz") targets); |
71 | | - |
72 | | - passthru = { |
73 | | - inherit platform arch targets; |
74 | | - }; |
75 | | - |
76 | | - nativeBuildInputs = |
77 | | - [ which cmake ] |
78 | | - ++ lib.optional (!stdenv.isDarwin) autoPatchelfHook |
79 | | - ; |
80 | | - |
81 | | - buildInputs = [ stdenv.cc.cc ncurses libxcrypt-legacy python3 ]; |
82 | | - |
83 | | - dontBuild = true; |
84 | | - dontUseCmakeConfigure = true; |
85 | | - |
86 | | - sourceRoot = "."; |
87 | | - |
88 | | - installPhase = '' |
89 | | - runHook preInstall |
90 | | -
|
91 | | - rm -f zephyr-sdk-$version/zephyr-sdk-${arch}-hosttools-standalone-*.sh |
92 | | - rm -f env-vars |
93 | | -
|
94 | | - mv zephyr-sdk-$version $out |
95 | | -
|
96 | | - if [ -n "$(ls -A .)" ]; then |
97 | | - mv * $out |
98 | | - fi |
99 | | -
|
100 | | - mkdir -p $out/nix-support |
101 | | - cat <<EOF >> $out/nix-support/setup-hook |
102 | | - export ZEPHYR_SDK_INSTALL_DIR=$out |
103 | | - EOF |
104 | | -
|
105 | | - runHook postInstall |
106 | | - ''; |
107 | | - }) |
108 | | - sdkArgs; |
109 | | - |
110 | | - # # SDK with all targets selected |
111 | | - sdkFull = |
112 | | - let |
113 | | - inherit (self.sdk.passthru) platform arch; |
114 | | - mToolchain = builtins.match "toolchain_${platform}-${arch}_(.+)\.tar\.xz"; |
115 | | - allTargets = map (x: builtins.head (mToolchain x)) (builtins.filter (f: mToolchain f != null) (lib.attrNames sdk'.files)); |
116 | | - in |
117 | | - self.sdk.override { |
118 | | - targets = allTargets; |
119 | | - }; |
120 | | - |
121 | | - # Binary host tools provided by the Zephyr project. |
122 | | - hosttools = callPackage |
123 | | - ({ stdenv |
124 | | - , which |
125 | | - , autoPatchelfHook |
126 | | - , python3 |
127 | | - }: |
128 | | - let |
129 | | - platform = getPlatform stdenv; |
130 | | - arch = getArch stdenv; |
131 | | - in |
132 | | - stdenv.mkDerivation { |
133 | | - pname = "zephyr-sdk-hosttools"; |
134 | | - inherit version; |
135 | | - |
136 | | - src = fetchSDKFile "hosttools_${platform}-${arch}.tar.xz"; |
137 | | - |
138 | | - nativeBuildInputs = |
139 | | - [ which ] |
140 | | - ++ lib.optional (!stdenv.isDarwin) autoPatchelfHook |
141 | | - ; |
142 | | - |
143 | | - buildInputs = [ python3 ]; |
144 | | - |
145 | | - dontBuild = true; |
146 | | - dontFixup = true; |
147 | | - |
148 | | - sourceRoot = "."; |
149 | | - |
150 | | - installPhase = '' |
151 | | - runHook preInstall |
152 | | - mkdir -p $out/usr/share/zephyr/hosttools |
153 | | - ./zephyr-sdk-${arch}-hosttools-standalone-*.sh -d $out/usr/share/zephyr/hosttools |
154 | | - ln -s $out/usr/share/zephyr/hosttools/sysroots/${arch}-pokysdk-${platform}/usr/bin $out/bin |
155 | | - runHook postInstall |
156 | | - ''; |
157 | | - }) |
158 | | - sdkArgs; |
159 | | - |
160 | 28 | openocd-zephyr = openocd.overrideAttrs(old: let |
161 | 29 | pname = "openocd-zephyr"; |
162 | 30 | version = "20220611"; |
|
0 commit comments