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