10 samples ? cleanSamples (callPackage ./samples.nix { }),
11 # Filter out the non-string-like attributes such as <pkg>.override added by
13 cleanSamples ? lib.filterAttrs (n: lib.isStringLike),
15 writeDirectReferencesToFile,
19 # -------------------------------------------------------------------------- #
21 # trivial-builders test
23 # -------------------------------------------------------------------------- #
25 # Execute this build script directly (quick):
28 # $ NIX_PATH="nixpkgs=$PWD" nix-shell -p tests.trivial-builders.references.testScriptBin --run references-test
31 # $ nix run .#tests.trivial-builders.references.testScriptBin
33 # or in the build sandbox with a ~20s VM overhead:
36 # $ nix-build --no-out-link -A tests.trivial-builders.references
39 # $ nix build -L --no-link .#tests.trivial-builders.references
41 # -------------------------------------------------------------------------- #
44 # Map each attribute to an element specification of Bash associative arrary
45 # and concatenate them with white spaces, to be used to define a
46 # one-line Bash associative array.
49 lib.concatMapStringsSep " " (name: "[${name}]=${lib.escapeShellArg "${attrs.${name}}"}") (
50 builtins.attrNames attrs
53 closures = lib.mapAttrs (n: v: writeClosure [ v ]) samples;
54 directReferences = lib.mapAttrs (n: v: writeDirectReferencesToFile v) samples;
55 collectiveClosure = writeClosure (lib.attrValues samples);
57 testScriptBin = stdenvNoCC.mkDerivation (finalAttrs: {
58 name = "references-test";
60 src = ./references-test.sh;
67 substitute "$src" "$out/bin/${finalAttrs.meta.mainProgram}" \
68 --replace "@SAMPLES@" ${lib.escapeShellArg (samplesToString samples)} \
69 --replace "@CLOSURES@" ${lib.escapeShellArg (samplesToString closures)} \
70 --replace "@DIRECT_REFS@" ${lib.escapeShellArg (samplesToString directReferences)} \
71 --replace "@COLLECTIVE_CLOSURE@" ${lib.escapeShellArg collectiveClosure}
73 chmod +x "$out/bin/${finalAttrs.meta.mainProgram}"
76 doInstallCheck = true;
77 nativeInstallCheckInputs = [
80 installCheckPhase = ''
81 runHook preInstallCheck
82 shellcheck "$out/bin/${finalAttrs.meta.mainProgram}"
83 runHook postInstallCheck
96 mainProgram = "references-test";
100 testers.runNixOSTest (
101 { config, lib, ... }:
103 # Use the testScriptBin from guest pkgs.
104 # The attribute path to access the guest version of testScriptBin is
105 # tests.trivial-builders.references.config.node.pkgs.tests.trivial-builders.references.testScriptBin
106 # which is why passthru.guestTestScriptBin is provided.
107 guestTestScriptBin = config.node.pkgs.tests.trivial-builders.references.testScriptBin;
110 name = "nixpkgs-trivial-builders-references";
119 virtualisation.writableStore = true;
121 # Test runs without network, so we don't substitute and prepare our deps
122 nix.settings.substituters = lib.mkForce [ ];
123 system.extraDependencies = [ guestTestScriptBin ];
127 ${lib.getExe guestTestScriptBin} 2>/dev/console
138 inherit guestTestScriptBin;
141 maintainers = with lib.maintainers; [