nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 callPackage,
5 resholve,
6 shunit2,
7 coreutils,
8 gnused,
9 gnugrep,
10 findutils,
11 jq,
12 bash,
13 bats,
14 libressl,
15 openssl,
16 python27,
17 file,
18 gettext,
19 rSrc,
20 runDemo ? false,
21 binlore,
22 sqlite,
23 unixtools,
24 gawk,
25 rlwrap,
26 gnutar,
27 bc,
28 systemd,
29 # override testing
30 esh,
31 getconf,
32 libarchive,
33 locale,
34 mount,
35 ncurses,
36 nixos-install-tools,
37 procps,
38 ps,
39 # known consumers
40 aaxtomp3,
41 arch-install-scripts,
42 bashup-events32,
43 dgoss,
44 git-ftp,
45 lesspipe,
46 locate-dominating-file,
47 mons,
48 msmtp,
49 nix-direnv,
50 pdf2odt,
51 pdfmm,
52 s0ix-selftest-tool,
53 unix-privesc-check,
54 wgnord,
55 wsl-vpnkit,
56 xdg-utils,
57 yadm,
58 zxfer,
59}:
60
61let
62 default_packages = [
63 bash
64 file
65 findutils
66 gettext
67 ];
68 parsed_packages = [
69 coreutils
70 sqlite
71 unixtools.script
72 gnused
73 gawk
74 findutils
75 rlwrap
76 gnutar
77 bc
78 msmtp
79 ]
80 ++ lib.optionals stdenv.hostPlatform.isLinux [
81 systemd
82 ];
83in
84rec {
85 module1 = resholve.mkDerivation {
86 pname = "testmod1";
87 version = "unreleased";
88
89 src = rSrc;
90 setSourceRoot = "sourceRoot=$(echo */tests/nix/libressl)";
91
92 installPhase = ''
93 mkdir -p $out/{bin,submodule}
94 install libressl.sh $out/bin/libressl.sh
95 install submodule/helper.sh $out/submodule/helper.sh
96 '';
97
98 solutions = {
99 libressl = {
100 # submodule to demonstrate
101 scripts = [
102 "bin/libressl.sh"
103 "submodule/helper.sh"
104 ];
105 interpreter = "none";
106 inputs = [
107 jq
108 module2
109 libressl.bin
110 ];
111 };
112 };
113
114 is_it_okay_with_arbitrary_envs = "shonuff";
115 };
116 module2 = resholve.mkDerivation {
117 pname = "testmod2";
118 version = "unreleased";
119
120 src = rSrc;
121 setSourceRoot = "sourceRoot=$(echo */tests/nix/openssl)";
122
123 installPhase = ''
124 mkdir -p $out/bin $out/libexec
125 install openssl.sh $out/bin/openssl.sh
126 install libexec.sh $out/libexec/invokeme
127 install profile $out/profile
128 '';
129 # LOGLEVEL="DEBUG";
130 solutions = {
131 openssl = {
132 fix = {
133 aliases = true;
134 };
135 scripts = [
136 "bin/openssl.sh"
137 "libexec/invokeme"
138 ];
139 interpreter = "none";
140 inputs = [
141 shunit2
142 openssl.bin
143 "libexec"
144 "libexec/invokeme"
145 ];
146 execer = [
147 /*
148 This is the same verdict binlore will
149 come up with. It's a no-op just to demo
150 how to fiddle lore via the Nix API.
151 */
152 "cannot:${openssl.bin}/bin/openssl"
153 # different verdict, but not used
154 "can:${openssl.bin}/bin/c_rehash"
155 ];
156 };
157 profile = {
158 scripts = [ "profile" ];
159 interpreter = "none";
160 inputs = [ ];
161 };
162 };
163 postResholve = ''
164 echo "not a load-bearing test, just prove we exist"
165 '';
166 };
167 # demonstrate that we could use resholve in larger build
168 module3 = stdenv.mkDerivation {
169 pname = "testmod3";
170 version = "unreleased";
171
172 src = rSrc;
173 setSourceRoot = "sourceRoot=$(echo */tests/nix/future_perfect_tense)";
174
175 installPhase = ''
176 mkdir -p $out/bin
177 install conjure.sh $out/bin/conjure.sh
178 ${resholve.phraseSolution "conjure" {
179 scripts = [ "bin/conjure.sh" ];
180 interpreter = "${bash}/bin/bash";
181 inputs = [ module1 ];
182 fake = {
183 external = [
184 "jq"
185 "openssl"
186 ];
187 };
188 }}
189 '';
190 };
191
192 cli = stdenv.mkDerivation {
193 name = "resholve-test";
194 src = rSrc;
195
196 dontBuild = true;
197
198 installPhase = ''
199 mkdir $out
200 cp *.ansi $out/
201 '';
202
203 doCheck = true;
204 buildInputs = [ resholve ];
205 nativeCheckInputs = [
206 coreutils
207 bats
208 ];
209 # LOGLEVEL="DEBUG";
210
211 # default path
212 RESHOLVE_PATH = "${lib.makeBinPath default_packages}";
213 # but separate packages for combining as needed
214 PKG_FILE = "${lib.makeBinPath [ file ]}";
215 PKG_FINDUTILS = "${lib.makeBinPath [ findutils ]}";
216 PKG_GETTEXT = "${lib.makeBinPath [ gettext ]}";
217 PKG_COREUTILS = "${lib.makeBinPath [ coreutils ]}";
218 RESHOLVE_LORE = "${binlore.collect {
219 drvs = default_packages ++ [ coreutils ] ++ parsed_packages;
220 }}";
221 PKG_PARSED = "${lib.makeBinPath parsed_packages}";
222
223 # explicit interpreter for demo suite; maybe some better way...
224 INTERP = "${bash}/bin/bash";
225
226 checkPhase = ''
227 echo removing parse tests matching no${stdenv.buildPlatform.uname.system}
228 rm tests/parse_*no${stdenv.buildPlatform.uname.system}.sh || true # ok if none exist
229 patchShebangs .
230 mkdir empty_lore
231 touch empty_lore/{execers,wrappers}
232 export EMPTY_LORE=$PWD/empty_lore
233 printf "\033[33m============================= resholve test suite ===================================\033[0m\n" > test.ansi
234 if ./test.sh &>> test.ansi; then
235 cat test.ansi
236 else
237 cat test.ansi && exit 1
238 fi
239 ''
240 + lib.optionalString runDemo ''
241 printf "\033[33m============================= resholve demo ===================================\033[0m\n" > demo.ansi
242 if ./demo &>> demo.ansi; then
243 cat demo.ansi
244 else
245 cat demo.ansi && exit 1
246 fi
247 '';
248 };
249
250 # Caution: ci.nix asserts the equality of both of these w/ diff
251 resholvedScript =
252 resholve.writeScript "resholved-script"
253 {
254 inputs = [ file ];
255 interpreter = "${bash}/bin/bash";
256 }
257 ''
258 echo "Hello"
259 file .
260 '';
261 resholvedScriptBin =
262 resholve.writeScriptBin "resholved-script-bin"
263 {
264 inputs = [ file ];
265 interpreter = "${bash}/bin/bash";
266 }
267 ''
268 echo "Hello"
269 file .
270 '';
271 resholvedScriptBinNone =
272 resholve.writeScriptBin "resholved-script-bin"
273 {
274 inputs = [ file ];
275 interpreter = "none";
276 }
277 ''
278 echo "Hello"
279 file .
280 '';
281 # spot-check lore overrides
282 loreOverrides =
283 resholve.writeScriptBin "verify-overrides"
284 {
285 inputs = [
286 coreutils
287 esh
288 getconf
289 libarchive
290 locale
291 mount
292 ncurses
293 procps
294 ps
295 ]
296 ++ lib.optionals stdenv.hostPlatform.isLinux [
297 nixos-install-tools
298 ];
299 interpreter = "none";
300 execer = [
301 "cannot:${esh}/bin/esh"
302 ];
303 fix = {
304 mount = true;
305 };
306 }
307 (
308 ''
309 env b2sum fake args
310 b2sum fake args
311 esh fake args
312 getconf fake args
313 bsdtar fake args
314 locale fake args
315 mount fake args
316 reset fake args
317 tput fake args
318 tset fake args
319 ps fake args
320 top fake args
321 ''
322 + lib.optionalString stdenv.hostPlatform.isLinux ''
323 nixos-generate-config fake args
324 ''
325 );
326
327 # ensure known consumers in nixpkgs keep working
328 inherit aaxtomp3;
329 inherit bashup-events32;
330 inherit bats;
331 inherit git-ftp;
332 inherit lesspipe;
333 inherit locate-dominating-file;
334 inherit mons;
335 inherit msmtp;
336 inherit nix-direnv;
337 inherit pdf2odt;
338 inherit pdfmm;
339 inherit shunit2;
340 inherit xdg-utils;
341 inherit yadm;
342}
343// lib.optionalAttrs stdenv.hostPlatform.isLinux {
344 inherit arch-install-scripts;
345 inherit dgoss;
346 inherit unix-privesc-check;
347 inherit wgnord;
348 inherit wsl-vpnkit;
349 inherit zxfer;
350}
351//
352 lib.optionalAttrs
353 (stdenv.hostPlatform.isLinux && (stdenv.hostPlatform.isi686 || stdenv.hostPlatform.isx86_64))
354 {
355 inherit s0ix-selftest-tool;
356 }