1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 20:16:03 +01:00

Merge pull request #14027 from obsidiansystems/more-ca-tests

More floating content-addressing derivation tests
This commit is contained in:
John Ericson 2025-09-22 17:09:39 -04:00 committed by GitHub
commit d9de675357
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 53 additions and 17 deletions

View file

@ -233,10 +233,12 @@
# Content-addressed test files that use recursive-*looking* sourcing # Content-addressed test files that use recursive-*looking* sourcing
# (cd .. && source <self>), causing shellcheck to loop # (cd .. && source <self>), causing shellcheck to loop
# They're small wrapper scripts with not a lot going on # They're small wrapper scripts with not a lot going on
''^tests/functional/ca/build-delete\.sh$''
''^tests/functional/ca/build-dry\.sh$'' ''^tests/functional/ca/build-dry\.sh$''
''^tests/functional/ca/eval-store\.sh$'' ''^tests/functional/ca/eval-store\.sh$''
''^tests/functional/ca/gc\.sh$'' ''^tests/functional/ca/gc\.sh$''
''^tests/functional/ca/import-from-derivation\.sh$'' ''^tests/functional/ca/import-from-derivation\.sh$''
''^tests/functional/ca/multiple-outputs\.sh$''
''^tests/functional/ca/new-build-cmd\.sh$'' ''^tests/functional/ca/new-build-cmd\.sh$''
''^tests/functional/ca/nix-shell\.sh$'' ''^tests/functional/ca/nix-shell\.sh$''
''^tests/functional/ca/post-hook\.sh$'' ''^tests/functional/ca/post-hook\.sh$''

View file

@ -43,6 +43,10 @@ issue_6572_dependent_outputs() {
nix-store --delete "$p" # Clean up for next test nix-store --delete "$p" # Clean up for next test
# Make sure that 'nix build' tracks input-outputs correctly when a single output is already present. # Make sure that 'nix build' tracks input-outputs correctly when a single output is already present.
if [[ -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
# Resolved derivations interferre with the deletion
nix-store --delete "${NIX_STORE_DIR}"/*.drv
fi
nix-store --delete "$(jq -r <"$TEST_ROOT"/a.json .[0].outputs.second)" nix-store --delete "$(jq -r <"$TEST_ROOT"/a.json .[0].outputs.second)"
p=$(nix build -f multiple-outputs.nix use-a --no-link --print-out-paths) p=$(nix build -f multiple-outputs.nix use-a --no-link --print-out-paths)
cmp "$p" <<EOF cmp "$p" <<EOF

View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
source common.sh
export NIX_TESTS_CA_BY_DEFAULT=1
cd ..
source ./build-delete.sh

View file

@ -9,6 +9,7 @@ suites += {
'deps' : [], 'deps' : [],
'tests' : [ 'tests' : [
'build-cache.sh', 'build-cache.sh',
'build-delete.sh',
'build-with-garbage-path.sh', 'build-with-garbage-path.sh',
'build.sh', 'build.sh',
'concurrent-builds.sh', 'concurrent-builds.sh',
@ -18,6 +19,7 @@ suites += {
'eval-store.sh', 'eval-store.sh',
'gc.sh', 'gc.sh',
'import-from-derivation.sh', 'import-from-derivation.sh',
'multiple-outputs.sh',
'new-build-cmd.sh', 'new-build-cmd.sh',
'nix-copy.sh', 'nix-copy.sh',
'nix-run.sh', 'nix-run.sh',

View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
source common.sh
export NIX_TESTS_CA_BY_DEFAULT=1
cd ..
source ./multiple-outputs.sh

View file

@ -8,11 +8,15 @@ clearStoreIfPossible
rm -f $TEST_ROOT/result* rm -f $TEST_ROOT/result*
# Placeholder strings are opaque, so cannot do this check for floating
# content-addressing derivations.
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
# Test whether the output names match our expectations # Test whether the output names match our expectations
outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.out.outPath) outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.out.outPath)
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a" ] [ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a" ]
outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.dev.outPath) outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.dev.outPath)
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a-dev" ] [ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a-dev" ]
fi
# Test whether read-only evaluation works when referring to the # Test whether read-only evaluation works when referring to the
# drvPath attribute. # drvPath attribute.
@ -29,8 +33,12 @@ grepQuiet 'multiple-outputs-b.drv",\["out"\]' $drvPath
# While we're at it, test the unsafeDiscardOutputDependency primop. # While we're at it, test the unsafeDiscardOutputDependency primop.
outPath=$(nix-build multiple-outputs.nix -A d --no-out-link) outPath=$(nix-build multiple-outputs.nix -A d --no-out-link)
drvPath=$(cat $outPath/drv) drvPath=$(cat $outPath/drv)
if [[ -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
expectStderr 1 nix-store -q $drvPath | grepQuiet "Cannot use output path of floating content-addressing derivation until we know what it is (e.g. by building it)"
else
outPath=$(nix-store -q $drvPath) outPath=$(nix-store -q $drvPath)
(! [ -e "$outPath" ]) (! [ -e "$outPath" ])
fi
# Do a build of something that depends on a derivation with multiple # Do a build of something that depends on a derivation with multiple
# outputs. # outputs.
@ -60,6 +68,7 @@ outPath2=$(nix-build $(nix-instantiate multiple-outputs.nix -A a.second) --no-ou
[[ $(nix-build $(nix-instantiate multiple-outputs.nix -A a.all) --no-out-link | wc -l) -eq 2 ]] [[ $(nix-build $(nix-instantiate multiple-outputs.nix -A a.all) --no-out-link | wc -l) -eq 2 ]]
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
# Delete one of the outputs and rebuild it. This will cause a hash # Delete one of the outputs and rebuild it. This will cause a hash
# rewrite. # rewrite.
env -u NIX_REMOTE nix store delete $TEST_ROOT/result-second --ignore-liveness env -u NIX_REMOTE nix store delete $TEST_ROOT/result-second --ignore-liveness
@ -68,6 +77,7 @@ nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
[ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ] [ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ]
hash2=$(nix-store -q --hash $TEST_ROOT/result-second) hash2=$(nix-store -q --hash $TEST_ROOT/result-second)
[ "$hash1" = "$hash2" ] [ "$hash1" = "$hash2" ]
fi
# Make sure that nix-build works on derivations with multiple outputs. # Make sure that nix-build works on derivations with multiple outputs.
echo "building a.first..." echo "building a.first..."
@ -88,5 +98,9 @@ nix-store --gc --print-roots
rm -rf $NIX_STORE_DIR/.links rm -rf $NIX_STORE_DIR/.links
rmdir $NIX_STORE_DIR rmdir $NIX_STORE_DIR
# TODO inspect why this doesn't work with floating content-addressing
# derivations.
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
expect 1 nix build -f multiple-outputs.nix invalid-output-name-1 2>&1 | grep 'contains illegal character' expect 1 nix build -f multiple-outputs.nix invalid-output-name-1 2>&1 | grep 'contains illegal character'
expect 1 nix build -f multiple-outputs.nix invalid-output-name-2 2>&1 | grep 'contains illegal character' expect 1 nix build -f multiple-outputs.nix invalid-output-name-2 2>&1 | grep 'contains illegal character'
fi