mirror of
https://github.com/NixOS/nix.git
synced 2025-11-19 00:39:37 +01:00
Move openEvalCache to libflake
Most of the eval cache logic is flake-independent and libexpr, but the loading part is not. `nix-flake` is the right component for this, as the eval cache isn't exactly specific to the command line.
This commit is contained in:
parent
ce38b46e06
commit
0387b7d6db
4 changed files with 46 additions and 40 deletions
|
|
@ -1,6 +1,9 @@
|
|||
#include "nix/util/terminal.hh"
|
||||
#include "nix/util/ref.hh"
|
||||
#include "nix/util/environment-variables.hh"
|
||||
#include "nix/flake/flake.hh"
|
||||
#include "nix/expr/eval.hh"
|
||||
#include "nix/expr/eval-cache.hh"
|
||||
#include "nix/expr/eval-settings.hh"
|
||||
#include "nix/flake/lockfile.hh"
|
||||
#include "nix/expr/primops.hh"
|
||||
|
|
@ -924,8 +927,6 @@ void callFlake(EvalState & state, const LockedFlake & lockedFlake, Value & vRes)
|
|||
state.callFunction(*vCallFlake, args, vRes, noPos);
|
||||
}
|
||||
|
||||
} // namespace flake
|
||||
|
||||
std::optional<Fingerprint> LockedFlake::getFingerprint(ref<Store> store, const fetchers::Settings & fetchSettings) const
|
||||
{
|
||||
if (lockFile.isUnlocked(fetchSettings))
|
||||
|
|
@ -953,4 +954,41 @@ std::optional<Fingerprint> LockedFlake::getFingerprint(ref<Store> store, const f
|
|||
|
||||
Flake::~Flake() {}
|
||||
|
||||
ref<eval_cache::EvalCache> openEvalCache(EvalState & state, std::shared_ptr<LockedFlake> lockedFlake)
|
||||
{
|
||||
auto fingerprint = state.settings.useEvalCache && state.settings.pureEval
|
||||
? lockedFlake->getFingerprint(state.store, state.fetchSettings)
|
||||
: std::nullopt;
|
||||
auto rootLoader = [&state, lockedFlake]() {
|
||||
/* For testing whether the evaluation cache is
|
||||
complete. */
|
||||
if (getEnv("NIX_ALLOW_EVAL").value_or("1") == "0")
|
||||
throw Error("not everything is cached, but evaluation is not allowed");
|
||||
|
||||
auto vFlake = state.allocValue();
|
||||
callFlake(state, *lockedFlake, *vFlake);
|
||||
|
||||
state.forceAttrs(*vFlake, noPos, "while parsing cached flake data");
|
||||
|
||||
auto aOutputs = vFlake->attrs()->get(state.symbols.create("outputs"));
|
||||
assert(aOutputs);
|
||||
|
||||
return aOutputs->value;
|
||||
};
|
||||
|
||||
if (fingerprint) {
|
||||
auto search = state.evalCaches.find(fingerprint.value());
|
||||
if (search == state.evalCaches.end()) {
|
||||
search = state.evalCaches
|
||||
.emplace(fingerprint.value(), make_ref<eval_cache::EvalCache>(fingerprint, state, rootLoader))
|
||||
.first;
|
||||
}
|
||||
return search->second;
|
||||
} else {
|
||||
return make_ref<eval_cache::EvalCache>(std::nullopt, state, rootLoader);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace flake
|
||||
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue