Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 355 lines 7.6 kB view raw
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 ix, 46 lesspipe, 47 locate-dominating-file, 48 mons, 49 msmtp, 50 nix-direnv, 51 pdf2odt, 52 pdfmm, 53 rancid, 54 s0ix-selftest-tool, 55 unix-privesc-check, 56 wgnord, 57 wsl-vpnkit, 58 xdg-utils, 59 yadm, 60 zxfer, 61}: 62 63let 64 default_packages = [ 65 bash 66 file 67 findutils 68 gettext 69 ]; 70 parsed_packages = [ 71 coreutils 72 sqlite 73 unixtools.script 74 gnused 75 gawk 76 findutils 77 rlwrap 78 gnutar 79 bc 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 '' 223 patchShebangs . 224 mkdir empty_lore 225 touch empty_lore/{execers,wrappers} 226 export EMPTY_LORE=$PWD/empty_lore 227 printf "\033[33m============================= resholve test suite ===================================\033[0m\n" > test.ansi 228 if ./test.sh &>> test.ansi; then 229 cat test.ansi 230 else 231 cat test.ansi && exit 1 232 fi 233 '' 234 + lib.optionalString runDemo '' 235 printf "\033[33m============================= resholve demo ===================================\033[0m\n" > demo.ansi 236 if ./demo &>> demo.ansi; then 237 cat demo.ansi 238 else 239 cat demo.ansi && exit 1 240 fi 241 ''; 242 }; 243 244 # Caution: ci.nix asserts the equality of both of these w/ diff 245 resholvedScript = 246 resholve.writeScript "resholved-script" 247 { 248 inputs = [ file ]; 249 interpreter = "${bash}/bin/bash"; 250 } 251 '' 252 echo "Hello" 253 file . 254 ''; 255 resholvedScriptBin = 256 resholve.writeScriptBin "resholved-script-bin" 257 { 258 inputs = [ file ]; 259 interpreter = "${bash}/bin/bash"; 260 } 261 '' 262 echo "Hello" 263 file . 264 ''; 265 resholvedScriptBinNone = 266 resholve.writeScriptBin "resholved-script-bin" 267 { 268 inputs = [ file ]; 269 interpreter = "none"; 270 } 271 '' 272 echo "Hello" 273 file . 274 ''; 275 # spot-check lore overrides 276 loreOverrides = 277 resholve.writeScriptBin "verify-overrides" 278 { 279 inputs = 280 [ 281 coreutils 282 esh 283 getconf 284 libarchive 285 locale 286 mount 287 ncurses 288 procps 289 ps 290 ] 291 ++ lib.optionals stdenv.hostPlatform.isLinux [ 292 nixos-install-tools 293 nixos-rebuild 294 ]; 295 interpreter = "none"; 296 execer = [ 297 "cannot:${esh}/bin/esh" 298 ]; 299 fix = { 300 mount = true; 301 }; 302 } 303 ( 304 '' 305 env b2sum fake args 306 b2sum fake args 307 esh fake args 308 getconf fake args 309 bsdtar fake args 310 locale fake args 311 mount fake args 312 reset fake args 313 tput fake args 314 tset fake args 315 ps fake args 316 top fake args 317 '' 318 + lib.optionalString stdenv.hostPlatform.isLinux '' 319 nixos-generate-config fake args 320 nixos-rebuild fake args 321 '' 322 ); 323 324 # ensure known consumers in nixpkgs keep working 325 inherit aaxtomp3; 326 inherit bashup-events32; 327 inherit bats; 328 inherit git-ftp; 329 inherit ix; 330 inherit lesspipe; 331 inherit locate-dominating-file; 332 inherit mons; 333 inherit msmtp; 334 inherit nix-direnv; 335 inherit pdf2odt; 336 inherit pdfmm; 337 inherit shunit2; 338 inherit xdg-utils; 339 inherit yadm; 340} 341// lib.optionalAttrs stdenv.hostPlatform.isLinux { 342 inherit arch-install-scripts; 343 inherit dgoss; 344 inherit rancid; 345 inherit unix-privesc-check; 346 inherit wgnord; 347 inherit wsl-vpnkit; 348 inherit zxfer; 349} 350// 351 lib.optionalAttrs 352 (stdenv.hostPlatform.isLinux && (stdenv.hostPlatform.isi686 || stdenv.hostPlatform.isx86_64)) 353 { 354 inherit s0ix-selftest-tool; 355 }