Merge pull request #11529 from DeterminateSystems/test-ifd-in-chroot

Test IFD/filterSource in chroot stores
This commit is contained in:
Eelco Dolstra 2024-09-18 21:20:04 +02:00 committed by GitHub
commit 96ee5450d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 89 additions and 46 deletions

View file

@ -508,7 +508,7 @@
''^tests/functional/ca/concurrent-builds\.sh$'' ''^tests/functional/ca/concurrent-builds\.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-derivation\.sh$'' ''^tests/functional/ca/import-from-derivation\.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

@ -2,5 +2,5 @@ source common.sh
export NIX_TESTS_CA_BY_DEFAULT=1 export NIX_TESTS_CA_BY_DEFAULT=1
cd .. && source import-derivation.sh cd .. && source import-from-derivation.sh

View file

@ -7,7 +7,7 @@ ca-tests := \
$(d)/duplicate-realisation-in-closure.sh \ $(d)/duplicate-realisation-in-closure.sh \
$(d)/eval-store.sh \ $(d)/eval-store.sh \
$(d)/gc.sh \ $(d)/gc.sh \
$(d)/import-derivation.sh \ $(d)/import-from-derivation.sh \
$(d)/new-build-cmd.sh \ $(d)/new-build-cmd.sh \
$(d)/nix-copy.sh \ $(d)/nix-copy.sh \
$(d)/nix-run.sh \ $(d)/nix-run.sh \

View file

@ -16,7 +16,7 @@ suites += {
'duplicate-realisation-in-closure.sh', 'duplicate-realisation-in-closure.sh',
'eval-store.sh', 'eval-store.sh',
'gc.sh', 'gc.sh',
'import-derivation.sh', 'import-from-derivation.sh',
'new-build-cmd.sh', 'new-build-cmd.sh',
'nix-copy.sh', 'nix-copy.sh',
'nix-run.sh', 'nix-run.sh',

View file

@ -1,26 +0,0 @@
with import ./config.nix;
let
bar = mkDerivation {
name = "bar";
builder = builtins.toFile "builder.sh"
''
echo 'builtins.add 123 456' > $out
'';
};
value =
# Test that pathExists can check the existence of /nix/store paths
assert builtins.pathExists bar;
import bar;
in
mkDerivation {
name = "foo";
builder = builtins.toFile "builder.sh"
''
echo -n FOO${toString value} > $out
'';
}

View file

@ -1,14 +0,0 @@
#!/usr/bin/env bash
source common.sh
clearStoreIfPossible
if nix-instantiate --readonly-mode ./import-derivation.nix; then
echo "read-only evaluation of an imported derivation unexpectedly failed"
exit 1
fi
outPath=$(nix-build ./import-derivation.nix --no-out-link)
[ "$(cat "$outPath")" = FOO579 ]

View file

@ -0,0 +1,33 @@
with import ./config.nix;
rec {
bar = mkDerivation {
name = "bar";
builder = builtins.toFile "builder.sh"
''
echo 'builtins.add 123 456' > $out
'';
};
value =
# Test that pathExists can check the existence of /nix/store paths
assert builtins.pathExists bar;
import bar;
result = mkDerivation {
name = "foo";
builder = builtins.toFile "builder.sh"
''
echo -n FOO${toString value} > $out
'';
};
addPath = mkDerivation {
name = "add-path";
src = builtins.filterSource (path: type: true) result;
builder = builtins.toFile "builder.sh"
''
echo -n BLA$(cat $src) > $out
'';
};
}

View file

@ -0,0 +1,50 @@
#!/usr/bin/env bash
source common.sh
TODO_NixOS
clearStoreIfPossible
if nix-instantiate --readonly-mode ./import-from-derivation.nix -A result; then
echo "read-only evaluation of an imported derivation unexpectedly failed"
exit 1
fi
outPath=$(nix-build ./import-from-derivation.nix -A result --no-out-link)
[ "$(cat "$outPath")" = FOO579 ]
# FIXME: the next tests are broken on CA.
if [[ -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
exit 0
fi
# Test filterSource on the result of a derivation.
outPath2=$(nix-build ./import-from-derivation.nix -A addPath --no-out-link)
[[ "$(cat "$outPath2")" = BLAFOO579 ]]
# Test that IFD works with a chroot store.
if canUseSandbox; then
store2="$TEST_ROOT/store2"
store2_url="$store2?store=$NIX_STORE_DIR"
# Copy the derivation outputs to the chroot store to avoid having
# to actually build anything, as that would fail due to the lack
# of a shell in the sandbox. We only care about testing the IFD
# semantics.
for i in bar result addPath; do
nix copy --to "$store2_url" --no-check-sigs "$(nix-build ./import-from-derivation.nix -A "$i" --no-out-link)"
done
clearStore
outPath_check=$(nix-build ./import-from-derivation.nix -A result --no-out-link --store "$store2_url")
[[ "$outPath" = "$outPath_check" ]]
[[ ! -e "$outPath" ]]
[[ -e "$store2/nix/store/$(basename "$outPath")" ]]
outPath2_check=$(nix-build ./import-from-derivation.nix -A addPath --no-out-link --store "$store2_url")
[[ "$outPath2" = "$outPath2_check" ]]
fi

View file

@ -88,7 +88,7 @@ nix_tests = \
why-depends.sh \ why-depends.sh \
derivation-json.sh \ derivation-json.sh \
derivation-advanced-attributes.sh \ derivation-advanced-attributes.sh \
import-derivation.sh \ import-from-derivation.sh \
nix_path.sh \ nix_path.sh \
nars.sh \ nars.sh \
placeholders.sh \ placeholders.sh \

View file

@ -157,7 +157,7 @@ suites = [
'why-depends.sh', 'why-depends.sh',
'derivation-json.sh', 'derivation-json.sh',
'derivation-advanced-attributes.sh', 'derivation-advanced-attributes.sh',
'import-derivation.sh', 'import-from-derivation.sh',
'nix_path.sh', 'nix_path.sh',
'nars.sh', 'nars.sh',
'placeholders.sh', 'placeholders.sh',