9 , samples ? cleanSamples (callPackage ./samples.nix { })
10 # Filter out the non-string-like attributes such as <pkg>.override added by
12 , cleanSamples ? lib.filterAttrs (n: lib.isStringLike)
14 , writeDirectReferencesToFile
18 # -------------------------------------------------------------------------- #
20 # trivial-builders test
22 # -------------------------------------------------------------------------- #
24 # Execute this build script directly (quick):
27 # $ NIX_PATH="nixpkgs=$PWD" nix-shell -p tests.trivial-builders.references.testScriptBin --run references-test
30 # $ nix run .#tests.trivial-builders.references.testScriptBin
32 # or in the build sandbox with a ~20s VM overhead:
35 # $ nix-build --no-out-link -A tests.trivial-builders.references
38 # $ nix build -L --no-link .#tests.trivial-builders.references
40 # -------------------------------------------------------------------------- #
43 # Map each attribute to an element specification of Bash associative arrary
44 # and concatenate them with white spaces, to be used to define a
45 # one-line Bash associative array.
46 samplesToString = attrs:
47 lib.concatMapStringsSep " " (name: "[${name}]=${lib.escapeShellArg "${attrs.${name}}"}") (builtins.attrNames attrs);
49 closures = lib.mapAttrs (n: v: writeClosure [ v ]) samples;
50 directReferences = lib.mapAttrs (n: v: writeDirectReferencesToFile v) samples;
51 collectiveClosure = writeClosure (lib.attrValues samples);
53 testScriptBin = stdenvNoCC.mkDerivation (finalAttrs: {
54 name = "references-test";
56 src = ./references-test.sh;
63 substitute "$src" "$out/bin/${finalAttrs.meta.mainProgram}" \
64 --replace "@SAMPLES@" ${lib.escapeShellArg (samplesToString samples)} \
65 --replace "@CLOSURES@" ${lib.escapeShellArg (samplesToString closures)} \
66 --replace "@DIRECT_REFS@" ${lib.escapeShellArg (samplesToString directReferences)} \
67 --replace "@COLLECTIVE_CLOSURE@" ${lib.escapeShellArg collectiveClosure}
69 chmod +x "$out/bin/${finalAttrs.meta.mainProgram}"
72 doInstallCheck = true;
73 nativeInstallCheckInputs = [
76 installCheckPhase = ''
77 runHook preInstallCheck
78 shellcheck "$out/bin/${finalAttrs.meta.mainProgram}"
79 runHook postInstallCheck
92 mainProgram = "references-test";
96 testers.runNixOSTest ({ config, lib, ... }:
98 # Use the testScriptBin from guest pkgs.
99 # The attribute path to access the guest version of testScriptBin is
100 # tests.trivial-builders.references.config.node.pkgs.tests.trivial-builders.references.testScriptBin
101 # which is why passthru.guestTestScriptBin is provided.
102 guestTestScriptBin = config.node.pkgs.tests.trivial-builders.references.testScriptBin;
105 name = "nixpkgs-trivial-builders-references";
106 nodes.machine = { config, lib, pkgs, ... }: {
107 virtualisation.writableStore = true;
109 # Test runs without network, so we don't substitute and prepare our deps
110 nix.settings.substituters = lib.mkForce [ ];
111 system.extraDependencies = [ guestTestScriptBin ];
116 ${lib.getExe guestTestScriptBin} 2>/dev/console
127 inherit guestTestScriptBin;
130 maintainers = with lib.maintainers; [