-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EvalState::realiseContext(): Allow access to the entire closure
Fixes #11030. (cherry picked from commit 08361f0) # Conflicts: # src/libexpr/eval.cc # tests/functional/import-from-derivation.nix # tests/functional/import-from-derivation.sh
- Loading branch information
1 parent
6a791e9
commit f986f7e
Showing
5 changed files
with
129 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
with import <config>; | ||
|
||
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 | ||
''; | ||
}; | ||
|
||
step1 = mkDerivation { | ||
name = "step1"; | ||
buildCommand = '' | ||
mkdir -p $out | ||
echo 'foo' > $out/bla | ||
''; | ||
}; | ||
|
||
addPathExpr = mkDerivation { | ||
name = "add-path"; | ||
inherit step1; | ||
buildCommand = '' | ||
mkdir -p $out | ||
echo "builtins.path { path = \"$step1\"; sha256 = \"7ptL+pnrZXnSa5hwwB+2SXTLkcSb5264WGGokN8OXto=\"; }" > $out/default.nix | ||
''; | ||
}; | ||
|
||
importAddPathExpr = import addPathExpr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env bash | ||
|
||
source common.sh | ||
|
||
TODO_NixOS | ||
|
||
clearStoreIfPossible | ||
|
||
export NIX_PATH=config="${config_nix}" | ||
|
||
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 ] | ||
|
||
# Check that we can have access to the entire closure of a derivation output. | ||
nix build --no-link --restrict-eval -I src=. -f ./import-from-derivation.nix importAddPathExpr -v | ||
|
||
# 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 |