Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ void EvalState::allowPath(const StorePath & storePath)
rootFS2->allowPrefix(CanonPath(store->toRealPath(storePath)));
}

void EvalState::allowClosure(const StorePath & storePath)
{
if (!rootFS.dynamic_pointer_cast<AllowListSourceAccessor>()) return;

StorePathSet closure;
store->computeFSClosure(storePath, closure);
for (auto & p : closure)
allowPath(p);
}

void EvalState::allowAndSetStorePathString(const StorePath & storePath, Value & v)
{
allowPath(storePath);
Expand Down Expand Up @@ -3090,10 +3100,7 @@ std::optional<std::string> EvalState::resolveLookupPathPath(const LookupPath::Pa
allowPath(path);
if (store->isInStore(path)) {
try {
StorePathSet closure;
store->computeFSClosure(store->toStorePath(path).first, closure);
for (auto & p : closure)
allowPath(p);
allowClosure(store->toStorePath(path).first);
} catch (InvalidPath &) { }
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ public:
*/
void allowPath(const StorePath & storePath);

/**
* Allow access to the closure of a store path.
*/
void allowClosure(const StorePath & storePath);

/**
* Allow access to a store path and return it as a string.
*/
Expand Down
8 changes: 3 additions & 5 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,9 @@ StringMap EvalState::realiseContext(const NixStringContext & context, StorePathS
if (store != buildStore) copyClosure(*buildStore, *store, outputsToCopyAndAllow);

if (isIFD) {
for (auto & outputPath : outputsToCopyAndAllow) {
/* Add the output of this derivations to the allowed
paths. */
allowPath(outputPath);
}
/* Allow access to the output closures of this derivation. */
for (auto & outputPath : outputsToCopyAndAllow)
allowClosure(outputPath);
}

return res;
Expand Down
19 changes: 19 additions & 0 deletions tests/functional/import-from-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,23 @@ rec {
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;
}
5 changes: 5 additions & 0 deletions tests/functional/import-from-derivation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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
Expand All @@ -15,6 +17,9 @@ 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
Expand Down
Loading