diff --git a/pkgs/build-support/trivial-builders/test.nix b/pkgs/build-support/trivial-builders/test.nix index 0902a5372221..cdc16b8af34d 100644 --- a/pkgs/build-support/trivial-builders/test.nix +++ b/pkgs/build-support/trivial-builders/test.nix @@ -1,5 +1,27 @@ -{ lib, nixosTest, path, writeText, hello, figlet, stdenvNoCC }: +{ lib, nixosTest, pkgs, writeText, hello, figlet, stdenvNoCC }: +# -------------------------------------------------------------------------- # +# +# trivial-builders test +# +# -------------------------------------------------------------------------- # +# +# This file can be run independently (quick): +# +# $ pkgs/build-support/trivial-builders/test.sh +# +# or in the build sandbox with a ~20s VM overhead +# +# $ nix-build -A tests.trivial-builders +# +# -------------------------------------------------------------------------- # + +let + invokeSamples = file: + lib.concatStringsSep " " ( + lib.attrValues (import file { inherit pkgs; }) + ); +in nixosTest { name = "nixpkgs-trivial-builders"; nodes.machine = { ... }: { @@ -10,11 +32,15 @@ nixosTest { environment.etc."pre-built-paths".source = writeText "pre-built-paths" ( builtins.toJSON [hello figlet stdenvNoCC] ); + environment.variables = { + SAMPLE = invokeSamples ./test/sample.nix; + REFERENCES = invokeSamples ./test/invoke-writeReferencesToFile.nix; + DIRECT_REFS = invokeSamples ./test/invoke-writeDirectReferencesToFile.nix; + }; }; testScript = '' machine.succeed(""" - cd ${lib.cleanSource path} - ./pkgs/build-support/trivial-builders/test.sh 2>/dev/console + ${./test.sh} 2>/dev/console """) ''; } diff --git a/pkgs/build-support/trivial-builders/test.sh b/pkgs/build-support/trivial-builders/test.sh index 3e21b0008155..b7c4726a9be0 100755 --- a/pkgs/build-support/trivial-builders/test.sh +++ b/pkgs/build-support/trivial-builders/test.sh @@ -25,33 +25,32 @@ set -euo pipefail cd "$(dirname ${BASH_SOURCE[0]})" # nixpkgs root -testDirectReferences() { - expr="$1" +if [[ -z ${SAMPLE:-} ]]; then + sample=( `nix-build test/sample.nix` ) + directRefs=( `nix-build test/invoke-writeDirectReferencesToFile.nix` ) + references=( `nix-build test/invoke-writeReferencesToFile.nix` ) +else + # Injected by Nix (to avoid evaluating in a derivation) + # turn them into arrays + sample=($SAMPLE) + directRefs=($DIRECT_REFS) + references=($REFERENCES) +fi + +echo >&2 Testing direct references... +for i in "${!sample[@]}"; do + echo >&2 Checking '#'$i ${sample[$i]} ${directRefs[$i]} diff -U3 \ - <(sort <$(nix-build --no-out-link --expr "with import ../../.. {}; writeDirectReferencesToFile ($expr)")) \ - <(nix-store -q --references $(nix-build --no-out-link --expr "with import ../../.. {}; ($expr)") | sort) -} + <(sort <${directRefs[$i]}) \ + <(nix-store -q --references ${sample[$i]} | sort) +done -testDirectReferences 'hello' -testDirectReferences 'figlet' -testDirectReferences 'writeText "hi" "hello"' -testDirectReferences 'writeText "hi" "hello ${hello}"' -testDirectReferences 'writeText "hi" "hello ${hello} ${figlet}"' - - - -testClosure() { - expr="$1" +echo >&2 Testing closure... +for i in "${!sample[@]}"; do + echo >&2 Checking '#'$i ${sample[$i]} ${references[$i]} diff -U3 \ - <(sort <$(nix-build --no-out-link --expr "with import ../../.. {}; writeReferencesToFile ($expr)")) \ - <(nix-store -q --requisites $(nix-build --no-out-link --expr "with import ../../.. {}; ($expr)") | sort) -} - -testClosure 'hello' -testClosure 'figlet' -testClosure 'writeText "hi" "hello"' -testClosure 'writeText "hi" "hello ${hello}"' -testClosure 'writeText "hi" "hello ${hello} ${figlet}"' - + <(sort <${references[$i]}) \ + <(nix-store -q --requisites ${sample[$i]} | sort) +done echo 'OK!' diff --git a/pkgs/build-support/trivial-builders/test/invoke-writeDirectReferencesToFile.nix b/pkgs/build-support/trivial-builders/test/invoke-writeDirectReferencesToFile.nix new file mode 100644 index 000000000000..ead3f7a2f571 --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/invoke-writeDirectReferencesToFile.nix @@ -0,0 +1,4 @@ +{ pkgs ? import ../../../.. { config = {}; overlays = []; } }: +pkgs.lib.mapAttrs + (k: v: pkgs.writeDirectReferencesToFile v) + (import ./sample.nix { inherit pkgs; }) diff --git a/pkgs/build-support/trivial-builders/test/invoke-writeReferencesToFile.nix b/pkgs/build-support/trivial-builders/test/invoke-writeReferencesToFile.nix new file mode 100644 index 000000000000..99c6c2f7dcc4 --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/invoke-writeReferencesToFile.nix @@ -0,0 +1,4 @@ +{ pkgs ? import ../../../.. { config = {}; overlays = []; } }: +pkgs.lib.mapAttrs + (k: v: pkgs.writeReferencesToFile v) + (import ./sample.nix { inherit pkgs; }) diff --git a/pkgs/build-support/trivial-builders/test/sample.nix b/pkgs/build-support/trivial-builders/test/sample.nix new file mode 100644 index 000000000000..060be011093a --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/sample.nix @@ -0,0 +1,15 @@ +{ pkgs ? import ../../../.. { config = {}; overlays = []; } }: +let + inherit (pkgs) + figlet + hello + writeText + ; +in +{ + hello = hello; + figlet = figlet; + norefs = writeText "hi" "hello"; + helloRef = writeText "hi" "hello ${hello}"; + helloFigletRef = writeText "hi" "hello ${hello} ${figlet}"; +}