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

Add MemoryInputAccessor for corepkgs

This commit is contained in:
Eelco Dolstra 2022-02-07 13:14:52 +01:00
parent c56e17b718
commit ffe0dc9a8c
7 changed files with 86 additions and 38 deletions

View file

@ -451,6 +451,7 @@ EvalState::EvalState(
, repair(NoRepair)
, emptyBindings(0)
, rootFS(makeFSInputAccessor(""))
, corepkgsFS(makeMemoryInputAccessor())
, store(store)
, buildStore(buildStore ? buildStore : store)
, regexCache(makeRegexCache())
@ -500,6 +501,11 @@ EvalState::EvalState(
}
createBaseEnv();
corepkgsFS->addFile(
"/fetchurl.nix",
#include "fetchurl.nix.gen.hh"
);
}

View file

@ -98,6 +98,7 @@ public:
Bindings emptyBindings;
ref<InputAccessor> rootFS;
ref<MemoryInputAccessor> corepkgsFS;
std::unordered_map<size_t, ref<InputAccessor>> inputAccessors;
@ -514,8 +515,6 @@ struct EvalSettings : Config
extern EvalSettings evalSettings;
static const std::string corepkgsPrefix{"/__corepkgs__/"};
}
#include "eval-inline.hh"

View file

@ -788,7 +788,7 @@ Path EvalState::findFile(SearchPath & searchPath, const std::string_view path, c
}
if (hasPrefix(path, "nix/"))
return concatStrings(corepkgsPrefix, path.substr(4));
return packPath(SourcePath {corepkgsFS, (std::string) path.substr(3)});
throw ThrownError({
.msg = hintfmt(evalSettings.pureEval

View file

@ -7,6 +7,7 @@ static constexpr std::string_view marker = "/__virtual/";
Path EvalState::packPath(const SourcePath & path)
{
// FIXME: canonPath(path) ?
printError("PACK %s", path.path);
assert(hasPrefix(path.path, "/"));
inputAccessors.emplace(path.accessor->number, path.accessor);

View file

@ -165,15 +165,6 @@ static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vS
{
auto path = realisePath(state, pos, vPath);
#if 0
// FIXME: use InputAccessor
if (path == corepkgsPrefix + "fetchurl.nix") {
state.eval(state.parseExprFromString(
#include "fetchurl.nix.gen.hh"
, "/"), v);
}
#endif
state.evalFile(path, v);
#if 0
@ -216,13 +207,6 @@ static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vS
state.forceAttrs(v, pos);
}
// FIXME: use InputAccessor
else if (path == corepkgsPrefix + "fetchurl.nix") {
state.eval(state.parseExprFromString(
#include "fetchurl.nix.gen.hh"
, "/"), v);
}
else {
if (!vScope)
state.evalFile(path, v);
@ -1502,7 +1486,6 @@ static RegisterPrimOp primop_readFile({
which are desugared to 'findFile __nixPath "x"'. */
static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Value & v)
{
#if 0
state.forceList(*args[0], pos);
SearchPath searchPath;
@ -1523,7 +1506,18 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va
pos
);
auto path = realisePath(state, pos, *i->value, { .requireAbsolutePath = false });
PathSet context;
auto path = state.coerceToString(pos, *i->value, context, false, false).toOwned();
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);
}
@ -1532,9 +1526,6 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va
// FIXME: checkSourcePath?
v.mkPath(state.findFile(searchPath, path, pos));
#endif
throw UnimplementedError("findFile");
}
static RegisterPrimOp primop_findFile(RegisterPrimOp::Info {