From 7fa6e785ff9f472318e681c6b1372879a9dfd545 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 3 Dec 2024 20:38:41 +0100 Subject: [PATCH] libexpr: associate path config with EvalContext Change-Id: Id25f990ab4ae9d9e76c91c07d7397689acf57eca --- lix/legacy/user-env.cc | 2 +- lix/libcmd/cmd-profiles.cc | 4 ++-- lix/libexpr/eval.cc | 6 +++--- lix/libexpr/flake/flake.cc | 4 ++-- lix/libexpr/primops.cc | 28 +++++++++++++-------------- lix/libexpr/primops/fetchClosure.cc | 6 +++--- lix/libexpr/primops/fetchMercurial.cc | 6 +++--- lix/libexpr/primops/fetchTree.cc | 10 +++++----- lix/libexpr/value-to-json.cc | 2 +- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/lix/legacy/user-env.cc b/lix/legacy/user-env.cc index e19eb9bc5..ea3f9e58a 100644 --- a/lix/legacy/user-env.cc +++ b/lix/legacy/user-env.cc @@ -104,7 +104,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems, /* Construct a Nix expression that calls the user environment builder with the manifest as argument. */ auto attrs = state.ctx.buildBindings(3); - state.paths.mkStorePathString(manifestFile, attrs.alloc("manifest")); + state.ctx.paths.mkStorePathString(manifestFile, attrs.alloc("manifest")); attrs.insert(state.ctx.symbols.create("derivations"), &manifest); Value args; args.mkAttrs(attrs); diff --git a/lix/libcmd/cmd-profiles.cc b/lix/libcmd/cmd-profiles.cc index 983f2889c..2168fa983 100644 --- a/lix/libcmd/cmd-profiles.cc +++ b/lix/libcmd/cmd-profiles.cc @@ -162,8 +162,8 @@ ProfileManifest::ProfileManifest(EvalState & state, const Path & profile) } } else if (pathExists(profile + "/manifest.nix")) { // FIXME: needed because of pure mode; ugly. - state.paths.allowPath(state.ctx.store->followLinksToStore(profile)); - state.paths.allowPath(state.ctx.store->followLinksToStore(profile + "/manifest.nix")); + state.ctx.paths.allowPath(state.ctx.store->followLinksToStore(profile)); + state.ctx.paths.allowPath(state.ctx.store->followLinksToStore(profile + "/manifest.nix")); auto drvInfos = queryInstalled(state, state.ctx.store->followLinksToStore(profile)); diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index 220c4faa3..8ddfec48f 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -939,7 +939,7 @@ struct CachedEvalFile void EvalState::evalFile(const SourcePath & path_, Value & v) { - auto path = paths.checkSourcePath(path_); + auto path = ctx.paths.checkSourcePath(path_); if (auto i = caches.fileEval.find(path); i != caches.fileEval.end()) { v = i->second->result; @@ -953,7 +953,7 @@ void EvalState::evalFile(const SourcePath & path_, Value & v) } debug("evaluating file '%1%'", resolvedPath); - Expr & e = parseExprFromFile(paths.checkSourcePath(resolvedPath)); + Expr & e = parseExprFromFile(ctx.paths.checkSourcePath(resolvedPath)); try { auto dts = ctx.debug @@ -2285,7 +2285,7 @@ BackedStringView EvalState::coerceToString( // slash, as in /foo/${x}. v._path : copyToStore - ? ctx.store->printStorePath(paths.copyPathToStore(context, v.path(), ctx.repair)) + ? ctx.store->printStorePath(ctx.paths.copyPathToStore(context, v.path(), ctx.repair)) : std::string(v.path().path.abs()); } diff --git a/lix/libexpr/flake/flake.cc b/lix/libexpr/flake/flake.cc index 61273686f..bfa36c301 100644 --- a/lix/libexpr/flake/flake.cc +++ b/lix/libexpr/flake/flake.cc @@ -242,8 +242,8 @@ static Flake getFlake( }; // FIXME: symlink attack - auto resolvedFlakeFile = resolveExprPath(state.paths.checkSourcePath(CanonPath(flakeFile))); - Expr & flakeExpr = state.parseExprFromFile(state.paths.checkSourcePath(resolvedFlakeFile)); + auto resolvedFlakeFile = resolveExprPath(state.ctx.paths.checkSourcePath(CanonPath(flakeFile))); + Expr & flakeExpr = state.parseExprFromFile(state.ctx.paths.checkSourcePath(resolvedFlakeFile)); // Enforce that 'flake.nix' is a direct attrset, not a computation. if (!(dynamic_cast(&flakeExpr))) { diff --git a/lix/libexpr/primops.cc b/lix/libexpr/primops.cc index bb3eee446..a2cbedf4e 100644 --- a/lix/libexpr/primops.cc +++ b/lix/libexpr/primops.cc @@ -129,12 +129,12 @@ static SourcePath realisePath(EvalState & state, const PosIdx pos, Value & v, co auto path = state.coerceToPath(noPos, v, context, "while realising the context of a path"); try { - StringMap rewrites = state.paths.realiseContext(context); + StringMap rewrites = state.ctx.paths.realiseContext(context); - auto realPath = CanonPath(state.paths.toRealPath(rewriteStrings(path.path.abs(), rewrites), context)); + auto realPath = CanonPath(state.ctx.paths.toRealPath(rewriteStrings(path.path.abs(), rewrites), context)); return flags.checkForPureEval - ? state.paths.checkSourcePath(realPath) + ? state.ctx.paths.checkSourcePath(realPath) : realPath; } catch (Error & e) { e.addTrace(state.ctx.positions[pos], "while realising the context of path '%s'", path); @@ -323,7 +323,7 @@ void prim_exec(EvalState & state, const PosIdx pos, Value * * args, Value & v) false, false).toOwned()); } try { - auto _ = state.paths.realiseContext(context); // FIXME: Handle CA derivations + auto _ = state.ctx.paths.realiseContext(context); // FIXME: Handle CA derivations } catch (InvalidPathError & e) { e.addTrace(state.ctx.positions[pos], "while realising the context for builtins.exec"); throw; @@ -1173,7 +1173,7 @@ static void prim_storePath(EvalState & state, const PosIdx pos, Value * * args, ).atPos(pos).debugThrow(); NixStringContext context; - auto path = state.paths.checkSourcePath(state.coerceToPath(pos, *args[0], context, "while evaluating the first argument passed to builtins.storePath")).path; + auto path = state.ctx.paths.checkSourcePath(state.coerceToPath(pos, *args[0], context, "while evaluating the first argument passed to builtins.storePath")).path; /* Resolve symlinks in ‘path’, unless ‘path’ itself is a symlink directly in the store. The latter condition is necessary so e.g. nix-push does the right thing. */ @@ -1207,7 +1207,7 @@ static void prim_pathExists(EvalState & state, const PosIdx pos, Value * * args, try { auto checked = state - .paths + .ctx.paths .checkSourcePath(path) .resolveSymlinks(mustBeDir ? SymlinkResolution::Full : SymlinkResolution::Ancestors); @@ -1306,7 +1306,7 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value * * args, V false, false).toOwned(); try { - auto rewrites = state.paths.realiseContext(context); + auto rewrites = state.ctx.paths.realiseContext(context); path = rewriteStrings(path, rewrites); } catch (InvalidPathError & e) { state.ctx.errors.make( @@ -1324,7 +1324,7 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value * * args, V auto path = state.forceStringNoCtx(*args[1], pos, "while evaluating the second argument passed to builtins.findFile"); - v.mkPath(state.paths.checkSourcePath(state.paths.findFile(searchPath, path, pos))); + v.mkPath(state.ctx.paths.checkSourcePath(state.ctx.paths.findFile(searchPath, path, pos))); } /* Return the cryptographic hash of a file in base-16. */ @@ -1479,7 +1479,7 @@ static void prim_toFile(EvalState & state, const PosIdx pos, Value * * args, Val used in args[1]. */ /* Add the output of this to the allowed paths. */ - state.paths.allowAndSetStorePathString(storePath, v); + state.ctx.paths.allowAndSetStorePathString(storePath, v); } static void addPath( @@ -1496,8 +1496,8 @@ static void addPath( try { // FIXME: handle CA derivation outputs (where path needs to // be rewritten to the actual output). - auto rewrites = state.paths.realiseContext(context); - path = state.paths.toRealPath(rewriteStrings(path, rewrites), context); + auto rewrites = state.ctx.paths.realiseContext(context); + path = state.ctx.paths.toRealPath(rewriteStrings(path, rewrites), context); StorePathSet refs; @@ -1513,7 +1513,7 @@ static void addPath( path = evalSettings.pureEval && expectedHash ? path - : state.paths.checkSourcePath(CanonPath(path)).path.abs(); + : state.ctx.paths.checkSourcePath(CanonPath(path)).path.abs(); PathFilter filter = filterFun ? ([&](const Path & path) { auto st = lstat(path); @@ -1553,9 +1553,9 @@ static void addPath( "store path mismatch in (possibly filtered) path added from '%s'", path ).atPos(pos).debugThrow(); - state.paths.allowAndSetStorePathString(dstPath, v); + state.ctx.paths.allowAndSetStorePathString(dstPath, v); } else - state.paths.allowAndSetStorePathString(*expectedStorePath, v); + state.ctx.paths.allowAndSetStorePathString(*expectedStorePath, v); } catch (Error & e) { e.addTrace(state.ctx.positions[pos], "while adding path '%s'", path); throw; diff --git a/lix/libexpr/primops/fetchClosure.cc b/lix/libexpr/primops/fetchClosure.cc index f193d9b01..590df3449 100644 --- a/lix/libexpr/primops/fetchClosure.cc +++ b/lix/libexpr/primops/fetchClosure.cc @@ -58,7 +58,7 @@ static void runFetchClosureWithRewrite(EvalState & state, const PosIdx pos, Stor }); } - state.paths.mkStorePathString(toPath, v); + state.ctx.paths.mkStorePathString(toPath, v); } /** @@ -84,7 +84,7 @@ static void runFetchClosureWithContentAddressedPath(EvalState & state, const Pos }); } - state.paths.mkStorePathString(fromPath, v); + state.ctx.paths.mkStorePathString(fromPath, v); } /** @@ -107,7 +107,7 @@ static void runFetchClosureWithInputAddressedPath(EvalState & state, const PosId }); } - state.paths.mkStorePathString(fromPath, v); + state.ctx.paths.mkStorePathString(fromPath, v); } typedef std::optional StorePathOrGap; diff --git a/lix/libexpr/primops/fetchMercurial.cc b/lix/libexpr/primops/fetchMercurial.cc index 13196891f..45f2588d9 100644 --- a/lix/libexpr/primops/fetchMercurial.cc +++ b/lix/libexpr/primops/fetchMercurial.cc @@ -51,7 +51,7 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value * * a // FIXME: git externals probably can be used to bypass the URI // whitelist. Ah well. - state.paths.checkURI(url); + state.ctx.paths.checkURI(url); if (evalSettings.pureEval && !rev) throw Error("in pure evaluation mode, 'fetchMercurial' requires a Mercurial revision"); @@ -68,7 +68,7 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value * * a auto [tree, input2] = input.fetch(state.ctx.store); auto attrs2 = state.ctx.buildBindings(8); - state.paths.mkStorePathString(tree.storePath, attrs2.alloc(state.ctx.s.outPath)); + state.ctx.paths.mkStorePathString(tree.storePath, attrs2.alloc(state.ctx.s.outPath)); if (input2.getRef()) attrs2.alloc("branch").mkString(*input2.getRef()); // Backward compatibility: set 'rev' to @@ -80,7 +80,7 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value * * a attrs2.alloc("revCount").mkInt(*revCount); v.mkAttrs(attrs2); - state.paths.allowPath(tree.storePath); + state.ctx.paths.allowPath(tree.storePath); } static RegisterPrimOp r_fetchMercurial({ diff --git a/lix/libexpr/primops/fetchTree.cc b/lix/libexpr/primops/fetchTree.cc index 78f314109..f382144dd 100644 --- a/lix/libexpr/primops/fetchTree.cc +++ b/lix/libexpr/primops/fetchTree.cc @@ -74,7 +74,7 @@ void emitTreeAttrs( std::string fixURI(std::string uri, EvalState & state, const std::string & defaultScheme = "file") { - state.paths.checkURI(uri); + state.ctx.paths.checkURI(uri); if (uri.find("://") == std::string::npos) { const auto p = ParsedURL { .scheme = defaultScheme, @@ -194,7 +194,7 @@ static void fetchTree( auto [tree, input2] = input.fetch(state.ctx.store); - state.paths.allowPath(tree.storePath); + state.ctx.paths.allowPath(tree.storePath); emitTreeAttrs(state, tree, input2, v, params.emptyRevFallback, false); } @@ -244,7 +244,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v if (who == "fetchTarball") url = evalSettings.resolvePseudoUrl(*url); - state.paths.checkURI(*url); + state.ctx.paths.checkURI(*url); if (name == "") name = baseNameOf(*url); @@ -263,7 +263,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v }); if (state.ctx.store->isValidPath(expectedPath)) { - state.paths.allowAndSetStorePathString(expectedPath, v); + state.ctx.paths.allowAndSetStorePathString(expectedPath, v); return; } } @@ -290,7 +290,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v } } - state.paths.allowAndSetStorePathString(storePath, v); + state.ctx.paths.allowAndSetStorePathString(storePath, v); } void prim_fetchurl(EvalState & state, const PosIdx pos, Value * * args, Value & v) diff --git a/lix/libexpr/value-to-json.cc b/lix/libexpr/value-to-json.cc index 575e8fa05..4a2ad7062 100644 --- a/lix/libexpr/value-to-json.cc +++ b/lix/libexpr/value-to-json.cc @@ -37,7 +37,7 @@ json printValueAsJSON(EvalState & state, bool strict, case nPath: if (copyToStore) out = state.ctx.store->printStorePath( - state.paths.copyPathToStore(context, v.path(), state.ctx.repair)); + state.ctx.paths.copyPathToStore(context, v.path(), state.ctx.repair)); else out = v.path().path.abs(); break;