1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 14:21:48 +02:00

Parser: Respect the accessor of the source file for relative paths

This commit is contained in:
Eelco Dolstra 2025-02-06 16:31:42 +01:00
parent 38f391444b
commit 6e2fcb7e29
2 changed files with 13 additions and 10 deletions

View file

@ -359,11 +359,18 @@ string_parts_interpolated
path_start
: PATH {
Path path(absPath(std::string_view{$1.p, $1.l}, state->basePath.path.abs()));
std::string_view literal({$1.p, $1.l});
Path path(absPath(literal, state->basePath.path.abs()));
/* add back in the trailing '/' to the first segment */
if ($1.p[$1.l-1] == '/' && $1.l > 1)
path += "/";
$$ = new ExprPath(ref<SourceAccessor>(state->rootFS), std::move(path));
if (literal.size() > 1 && literal.back() == '/')
path += '/';
$$ =
/* Absolute paths are always interpreted relative to the
root filesystem accessor, rather than the accessor of the
current Nix expression. */
literal.front() == '/'
? new ExprPath(state->rootFS, std::move(path))
: new ExprPath(state->basePath.accessor, std::move(path));
}
| HPATH {
if (state->settings.pureEval) {

View file

@ -186,9 +186,7 @@ static FlakeInput parseFlakeInput(
url = attr.value->string_view();
else if (attr.value->type() == nPath) {
auto path = attr.value->path();
if (path.accessor != flakeDir.accessor
// FIXME: hack necessary since the parser currently stores all paths as inside rootFS.
&& flakeDir.accessor == state.rootFS)
if (path.accessor != flakeDir.accessor)
throw Error("input attribute path '%s' at %s must be in the same source tree as %s",
path, state.positions[attr.pos], flakeDir);
url = "path:" + flakeDir.path.makeRelative(path.path);
@ -337,9 +335,7 @@ static Flake readFlake(
state.symbols[setting.name],
std::string(state.forceStringNoCtx(*setting.value, setting.pos, "")));
else if (setting.value->type() == nPath) {
// FIXME: hack necessary since the parser currently stores all paths as inside rootFS.
SourcePath path(rootDir.accessor, setting.value->path().path);
auto storePath = fetchToStore(*state.store, path, FetchMode::Copy);
auto storePath = fetchToStore(*state.store, setting.value->path(), FetchMode::Copy);
flake.config.settings.emplace(
state.symbols[setting.name],
state.store->toRealPath(storePath));