libexpr: associate path config with EvalContext
Change-Id: Id25f990ab4ae9d9e76c91c07d7397689acf57eca
This commit is contained in:
parent
1f37fc85ac
commit
7fa6e785ff
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ExprAttrs *>(&flakeExpr))) {
|
||||
|
|
|
@ -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<EvalError>(
|
||||
|
@ -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;
|
||||
|
|
|
@ -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<StorePath> StorePathOrGap;
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue