diff --git a/pkgs/build-support/trivial-builders/test/default.nix b/pkgs/build-support/trivial-builders/test/default.nix index 59dbba3f1841..f41372d922bb 100644 --- a/pkgs/build-support/trivial-builders/test/default.nix +++ b/pkgs/build-support/trivial-builders/test/default.nix @@ -26,6 +26,9 @@ recurseIntoAttrs { then references else {}; writeCBin = callPackage ./writeCBin.nix {}; + writeClosure-union = callPackage ./writeClosure-union.nix { + inherit (references) samples; + }; writeShellApplication = callPackage ./writeShellApplication.nix {}; writeScriptBin = callPackage ./writeScriptBin.nix {}; writeShellScript = callPackage ./write-shell-script.nix {}; diff --git a/pkgs/build-support/trivial-builders/test/references/default.nix b/pkgs/build-support/trivial-builders/test/references/default.nix index 3e21c905321e..928cc1d9461f 100644 --- a/pkgs/build-support/trivial-builders/test/references/default.nix +++ b/pkgs/build-support/trivial-builders/test/references/default.nix @@ -12,7 +12,7 @@ , cleanSamples ? lib.filterAttrs (n: lib.isStringLike) # Test targets , writeDirectReferencesToFile -, writeReferencesToFile +, writeClosure }: # -------------------------------------------------------------------------- # @@ -46,8 +46,9 @@ let samplesToString = attrs: lib.concatMapStringsSep " " (name: "[${name}]=${lib.escapeShellArg "${attrs.${name}}"}") (builtins.attrNames attrs); - references = lib.mapAttrs (n: v: writeReferencesToFile v) samples; + closures = lib.mapAttrs (n: v: writeClosure [ v ]) samples; directReferences = lib.mapAttrs (n: v: writeDirectReferencesToFile v) samples; + collectiveClosure = writeClosure (lib.attrValues samples); testScriptBin = stdenvNoCC.mkDerivation (finalAttrs: { name = "references-test"; @@ -61,8 +62,9 @@ let mkdir -p "$out/bin" substitute "$src" "$out/bin/${finalAttrs.meta.mainProgram}" \ --replace "@SAMPLES@" ${lib.escapeShellArg (samplesToString samples)} \ - --replace "@REFERENCES@" ${lib.escapeShellArg (samplesToString references)} \ - --replace "@DIRECT_REFS@" ${lib.escapeShellArg (samplesToString directReferences)} + --replace "@CLOSURES@" ${lib.escapeShellArg (samplesToString closures)} \ + --replace "@DIRECT_REFS@" ${lib.escapeShellArg (samplesToString directReferences)} \ + --replace "@COLLECTIVE_CLOSURE@" ${lib.escapeShellArg collectiveClosure} runHook postInstall chmod +x "$out/bin/${finalAttrs.meta.mainProgram}" ''; @@ -79,8 +81,9 @@ let passthru = { inherit + collectiveClosure directReferences - references + closures samples ; }; @@ -109,8 +112,9 @@ testers.nixosTest { ''; passthru = { inherit + collectiveClosure directReferences - references + closures samples testScriptBin ; diff --git a/pkgs/build-support/trivial-builders/test/references/references-test.sh b/pkgs/build-support/trivial-builders/test/references/references-test.sh index 1b8f8e1504ec..92e4467287ed 100755 --- a/pkgs/build-support/trivial-builders/test/references/references-test.sh +++ b/pkgs/build-support/trivial-builders/test/references/references-test.sh @@ -33,16 +33,17 @@ set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" # nixpkgs root - # Injected by Nix (to avoid evaluating in a derivation) - # turn them into arrays - # shellcheck disable=SC2206 # deliberately unquoted - declare -A samples=( @SAMPLES@ ) - # shellcheck disable=SC2206 # deliberately unquoted - declare -A directRefs=( @DIRECT_REFS@ ) - # shellcheck disable=SC2206 # deliberately unquoted - declare -A references=( @REFERENCES@ ) + # Inject the path to compare from the Nix expression -echo >&2 Testing direct references... + # Associative Arrays + declare -A samples=( @SAMPLES@ ) + declare -A directRefs=( @DIRECT_REFS@ ) + declare -A closures=( @CLOSURES@ ) + + # Path string + collectiveClosure=@COLLECTIVE_CLOSURE@ + +echo >&2 Testing direct closures... for i in "${!samples[@]}"; do echo >&2 Checking "$i" "${samples[$i]}" "${directRefs[$i]}" diff -U3 \ @@ -52,10 +53,16 @@ done echo >&2 Testing closure... for i in "${!samples[@]}"; do - echo >&2 Checking "$i" "${samples[$i]}" "${references[$i]}" + echo >&2 Checking "$i" "${samples[$i]}" "${closures[$i]}" diff -U3 \ - <(sort <"${references[$i]}") \ + <(sort <"${closures[$i]}") \ <(nix-store -q --requisites "${samples[$i]}" | sort) done +echo >&2 Testing mixed closures... +echo >&2 Checking all samples "(${samples[*]})" "$collectiveClosure" +diff -U3 \ + <(sort <"$collectiveClosure") \ + <(nix-store -q --requisites "${samples[@]}" | sort) + echo 'OK!' diff --git a/pkgs/build-support/trivial-builders/test/writeClosure-union.nix b/pkgs/build-support/trivial-builders/test/writeClosure-union.nix new file mode 100644 index 000000000000..92a2bf9f0988 --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/writeClosure-union.nix @@ -0,0 +1,23 @@ +{ lib +, runCommandLocal + # Test targets +, writeClosure +, samples +}: +runCommandLocal "test-trivial-builders-writeClosure-union" { + __structuredAttrs = true; + closures = lib.mapAttrs (n: v: writeClosure [ v ]) samples; + collectiveClosure = writeClosure (lib.attrValues samples); + inherit samples; + meta.maintainers = with lib.maintainers; [ + ShamrockLee + ]; +} '' + set -eu -o pipefail + echo >&2 Testing mixed closures... + echo >&2 Checking all samples "(''${samples[*]})" "$collectiveClosure" + diff -U3 \ + <(sort <"$collectiveClosure") \ + <(cat "''${closures[@]}" | sort | uniq) + touch "$out" +'' diff --git a/pkgs/build-support/trivial-builders/test/writeReferenceClosureToFile-mixed.nix b/pkgs/build-support/trivial-builders/test/writeReferenceClosureToFile-mixed.nix deleted file mode 100644 index fed3a4f2adbc..000000000000 --- a/pkgs/build-support/trivial-builders/test/writeReferenceClosureToFile-mixed.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ lib -, runCommandLocal - # Test targets -, writeClosure -, samples -}: -runCommandLocal "test-trivial-builders-writeClosure-mixed" { - __structuredAttrs = true; - references = lib.mapAttrs (n: v: writeClosure [ v ]) samples; - allRefs = writeClosure (lib.attrValues samples); - inherit samples; - meta.maintainers = with lib.maintainers; [ - ShamrockLee - ]; -} '' - set -eu -o pipefail - echo >&2 Testing mixed closures... - echo >&2 Checking all samples "(''${samples[*]})" "$allRefs" - diff -U3 \ - <(sort <"$allRefs") \ - <(cat "''${references[@]}" | sort | uniq) - touch "$out" -''