1{ lib
2, stdenv
3, callPackage
4, resholve
5, shunit2
6, fetchFromGitHub
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, util-linux
24, gawk
25, rlwrap
26, gnutar
27, bc
28}:
29
30let
31 default_packages = [ bash file findutils gettext ];
32 parsed_packages = [ coreutils sqlite util-linux gnused gawk findutils rlwrap gnutar bc ];
33in
34rec {
35 module1 = resholve.mkDerivation {
36 pname = "testmod1";
37 version = "unreleased";
38
39 src = rSrc;
40 setSourceRoot = "sourceRoot=$(echo */tests/nix/libressl)";
41
42 installPhase = ''
43 mkdir -p $out/{bin,submodule}
44 install libressl.sh $out/bin/libressl.sh
45 install submodule/helper.sh $out/submodule/helper.sh
46 '';
47
48 solutions = {
49 libressl = {
50 # submodule to demonstrate
51 scripts = [ "bin/libressl.sh" "submodule/helper.sh" ];
52 interpreter = "none";
53 inputs = [ jq module2 libressl.bin ];
54 };
55 };
56
57 is_it_okay_with_arbitrary_envs = "shonuff";
58 };
59 module2 = resholve.mkDerivation {
60 pname = "testmod2";
61 version = "unreleased";
62
63 src = rSrc;
64 setSourceRoot = "sourceRoot=$(echo */tests/nix/openssl)";
65
66 installPhase = ''
67 mkdir -p $out/bin $out/libexec
68 install openssl.sh $out/bin/openssl.sh
69 install libexec.sh $out/libexec/invokeme
70 install profile $out/profile
71 '';
72 # LOGLEVEL="DEBUG";
73 solutions = {
74 openssl = {
75 fix = {
76 aliases = true;
77 };
78 scripts = [ "bin/openssl.sh" "libexec/invokeme" ];
79 interpreter = "none";
80 inputs = [ shunit2 openssl.bin "libexec" "libexec/invokeme" ];
81 execer = [
82 /*
83 This is the same verdict binlore will
84 come up with. It's a no-op just to demo
85 how to fiddle lore via the Nix API.
86 */
87 "cannot:${openssl.bin}/bin/openssl"
88 # different verdict, but not used
89 "can:${openssl.bin}/bin/c_rehash"
90 ];
91 };
92 profile = {
93 scripts = [ "profile" ];
94 interpreter = "none";
95 inputs = [ ];
96 };
97 };
98 };
99 # demonstrate that we could use resholve in larger build
100 module3 = stdenv.mkDerivation {
101 pname = "testmod3";
102 version = "unreleased";
103
104 src = rSrc;
105 setSourceRoot = "sourceRoot=$(echo */tests/nix/future_perfect_tense)";
106
107 installPhase = ''
108 mkdir -p $out/bin
109 install conjure.sh $out/bin/conjure.sh
110 ${resholve.phraseSolution "conjure" {
111 scripts = [ "bin/conjure.sh" ];
112 interpreter = "${bash}/bin/bash";
113 inputs = [ module1 ];
114 fake = {
115 external = [ "jq" "openssl" ];
116 };
117 }}
118 '';
119 };
120
121 cli = stdenv.mkDerivation {
122 name = "resholve-test";
123 src = rSrc;
124 installPhase = ''
125 mkdir $out
126 cp *.ansi $out/
127 '';
128 doCheck = true;
129 buildInputs = [ resholve ];
130 nativeCheckInputs = [ coreutils bats python27 ];
131 # LOGLEVEL="DEBUG";
132
133 # default path
134 RESHOLVE_PATH = "${lib.makeBinPath default_packages}";
135 # but separate packages for combining as needed
136 PKG_FILE = "${lib.makeBinPath [ file ]}";
137 PKG_FINDUTILS = "${lib.makeBinPath [ findutils ]}";
138 PKG_GETTEXT = "${lib.makeBinPath [ gettext ]}";
139 PKG_COREUTILS = "${lib.makeBinPath [ coreutils ]}";
140 RESHOLVE_LORE = "${binlore.collect { drvs = default_packages ++ [ coreutils ] ++ parsed_packages; } }";
141 PKG_PARSED = "${lib.makeBinPath parsed_packages}";
142
143 # explicit interpreter for demo suite; maybe some better way...
144 INTERP = "${bash}/bin/bash";
145
146 checkPhase = ''
147 patchShebangs .
148 mkdir empty_lore
149 touch empty_lore/{execers,wrappers}
150 export EMPTY_LORE=$PWD/empty_lore
151 printf "\033[33m============================= resholve test suite ===================================\033[0m\n" > test.ansi
152 if ./test.sh &>> test.ansi; then
153 cat test.ansi
154 else
155 cat test.ansi && exit 1
156 fi
157 '' + lib.optionalString runDemo ''
158 printf "\033[33m============================= resholve demo ===================================\033[0m\n" > demo.ansi
159 if ./demo &>> demo.ansi; then
160 cat demo.ansi
161 else
162 cat demo.ansi && exit 1
163 fi
164 '';
165 };
166
167 # Caution: ci.nix asserts the equality of both of these w/ diff
168 resholvedScript = resholve.writeScript "resholved-script" {
169 inputs = [ file ];
170 interpreter = "${bash}/bin/bash";
171 } ''
172 echo "Hello"
173 file .
174 '';
175 resholvedScriptBin = resholve.writeScriptBin "resholved-script-bin" {
176 inputs = [ file ];
177 interpreter = "${bash}/bin/bash";
178 } ''
179 echo "Hello"
180 file .
181 '';
182 resholvedScriptBinNone = resholve.writeScriptBin "resholved-script-bin" {
183 inputs = [ file ];
184 interpreter = "none";
185 } ''
186 echo "Hello"
187 file .
188 '';
189}