1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-29 23:13:14 +02:00

Interpret absolute paths relative to the root FS rather than the current flake

This commit is contained in:
Eelco Dolstra 2022-10-26 16:33:38 +02:00
parent e2353b9b45
commit 0402dd0298
4 changed files with 27 additions and 3 deletions

View file

@ -472,7 +472,7 @@ EvalState::EvalState(
: std::nullopt, : std::nullopt,
[](const CanonPath & path) -> RestrictedPathError { [](const CanonPath & path) -> RestrictedPathError {
auto modeInformation = evalSettings.pureEval auto modeInformation = evalSettings.pureEval
? "in pure eval mode (use '--impure' to override)" ? "in pure evaluation mode (use '--impure' to override)"
: "in restricted mode"; : "in restricted mode";
throw RestrictedPathError("access to absolute path '%1%' is forbidden %2%", path, modeInformation); throw RestrictedPathError("access to absolute path '%1%' is forbidden %2%", path, modeInformation);
})) }))

View file

@ -508,8 +508,14 @@ string_parts_interpolated
path_start path_start
: PATH { : PATH {
SourcePath path { data->basePath.accessor, CanonPath({$1.p, $1.l}, data->basePath.path) }; std::string_view path({$1.p, $1.l});
$$ = new ExprPath(std::move(path)); $$ = new ExprPath(
/* Absolute paths are always interpreted relative to the
root filesystem accessor, rather than the accessor of the
current Nix expression. */
hasPrefix(path, "/")
? SourcePath{data->state.rootFS, CanonPath(path)}
: SourcePath{data->basePath.accessor, CanonPath(path, data->basePath.path)});
} }
| HPATH { | HPATH {
if (evalSettings.pureEval) { if (evalSettings.pureEval) {

View file

@ -0,0 +1,17 @@
source ./common.sh
requireGit
flake1Dir=$TEST_ROOT/flake1
flake2Dir=$TEST_ROOT/flake2
createGitRepo $flake1Dir
cat > $flake1Dir/flake.nix <<EOF
{
outputs = { self }: { x = builtins.readFile $(pwd)/absolute-paths.sh; };
}
EOF
git -C $flake1Dir add flake.nix
git -C $flake1Dir commit -m Initial
nix eval --impure --json $flake1Dir#x

View file

@ -8,6 +8,7 @@ nix_tests = \
flakes/bundle.sh \ flakes/bundle.sh \
flakes/check.sh \ flakes/check.sh \
flakes/unlocked-override.sh \ flakes/unlocked-override.sh \
flakes/absolute-paths.sh \
ca/gc.sh \ ca/gc.sh \
gc.sh \ gc.sh \
remote-store.sh \ remote-store.sh \