diff options
author | regnat <rg@regnat.ovh> | 2022-01-27 15:32:14 +0100 |
---|---|---|
committer | regnat <rg@regnat.ovh> | 2022-01-27 16:26:39 +0100 |
commit | fcdc60ed227ba28f0d0d160d17df27fe179138b0 (patch) | |
tree | 1a2a634502c23fcb9f89282e41aaa2aaab489d00 /src/libexpr/primops.cc | |
parent | 1fe3bfdeaf7c57e9f7044a22edfbdf6fb9629e9d (diff) |
Don’t require `NIX_PATH` entries to be valid paths
It’s totally valid to have entries in `NIX_PATH` that aren’t valid paths
(they can even be arbitrary urls or `channel:<channel-name>`).
Fix #5998 and #5980
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r-- | src/libexpr/primops.cc | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 9d36f72a8..acee71d19 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -92,8 +92,6 @@ StringMap EvalState::realiseContext(const PathSet & context) } struct RealisePathFlags { - // Whether to check whether the path is a valid absolute path - bool requireAbsolutePath = true; // Whether to check that the path is allowed in pure eval mode bool checkForPureEval = true; }; @@ -105,9 +103,7 @@ static Path realisePath(EvalState & state, const Pos & pos, Value & v, const Rea auto path = [&]() { try { - return flags.requireAbsolutePath - ? state.coerceToPath(pos, v, context) - : state.coerceToString(pos, v, context, false, false); + return state.coerceToPath(pos, v, context); } catch (Error & e) { e.addTrace(pos, "while realising the context of a path"); throw; @@ -1489,7 +1485,19 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va pos ); - auto path = realisePath(state, pos, *i->value, { .requireAbsolutePath = false }); + PathSet context; + string path = state.coerceToString(pos, *i->value, context, false, false); + + try { + auto rewrites = state.realiseContext(context); + path = rewriteStrings(path, rewrites); + } catch (InvalidPathError & e) { + throw EvalError({ + .msg = hintfmt("cannot find '%1%', since path '%2%' is not valid", path, e.path), + .errPos = pos + }); + } + searchPath.emplace_back(prefix, path); } |