From 7096acc74db0d8d1197a9706cc9f079e93a1356a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 6 Feb 2025 16:31:42 +0100 Subject: [PATCH] Parser: Respect the accessor of the source file for relative paths Previously we only returned paths in rootFS, which is wrong and only worked because currently all our source trees are in rootFS. --- src/libexpr/parser.y | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index 944c7b1af..bde721401 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -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(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) {