diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 3805942ce..c5a95268b 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -28,7 +28,6 @@ #include "nix/expr/print.hh" #include "nix/util/ref.hh" #include "nix/expr/value.hh" -#include "nix/fetchers/input-cache.hh" #include "nix/util/strings.hh" @@ -459,7 +458,6 @@ ProcessLineResult NixRepl::processLine(std::string line) else if (command == ":l" || command == ":load") { state->resetFileCache(); - fetchers::InputCache::getCache()->clear(); loadFile(arg); } @@ -469,7 +467,6 @@ ProcessLineResult NixRepl::processLine(std::string line) else if (command == ":r" || command == ":reload") { state->resetFileCache(); - fetchers::InputCache::getCache()->clear(); reloadFiles(); } diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 9d60676f5..10a33c042 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -19,6 +19,7 @@ #include "nix/util/url.hh" #include "nix/fetchers/fetch-to-store.hh" #include "nix/fetchers/tarball.hh" +#include "nix/fetchers/input-cache.hh" #include "parser-tab.hh" @@ -310,6 +311,7 @@ EvalState::EvalState( )} , store(store) , buildStore(buildStore ? buildStore : store) + , inputCache(fetchers::InputCache::create()) , debugRepl(nullptr) , debugStop(false) , trylevel(0) @@ -1152,6 +1154,7 @@ void EvalState::resetFileCache() { fileEvalCache.clear(); fileParseCache.clear(); + inputCache->clear(); } diff --git a/src/libexpr/include/nix/expr/eval.hh b/src/libexpr/include/nix/expr/eval.hh index 61da225fc..6a6959bd8 100644 --- a/src/libexpr/include/nix/expr/eval.hh +++ b/src/libexpr/include/nix/expr/eval.hh @@ -33,7 +33,10 @@ namespace nix { constexpr size_t maxPrimOpArity = 8; class Store; -namespace fetchers { struct Settings; } +namespace fetchers { +struct Settings; +struct InputCache; +} struct EvalSettings; class EvalState; class StorePath; @@ -300,6 +303,8 @@ public: RootValue vImportedDrvToDerivation = nullptr; + ref inputCache; + /** * Debugger */ diff --git a/src/libfetchers/include/nix/fetchers/input-cache.hh b/src/libfetchers/include/nix/fetchers/input-cache.hh index 6a7194741..a7ca34487 100644 --- a/src/libfetchers/include/nix/fetchers/input-cache.hh +++ b/src/libfetchers/include/nix/fetchers/input-cache.hh @@ -25,7 +25,7 @@ struct InputCache virtual void clear() = 0; - static ref getCache(); + static ref create(); }; } diff --git a/src/libfetchers/input-cache.cc b/src/libfetchers/input-cache.cc index 6772d67c7..716143899 100644 --- a/src/libfetchers/input-cache.cc +++ b/src/libfetchers/input-cache.cc @@ -72,10 +72,9 @@ struct InputCacheImpl : InputCache } }; -ref InputCache::getCache() +ref InputCache::create() { - static auto cache = make_ref(); - return cache; + return make_ref(); } } diff --git a/src/libflake-c/nix_api_flake.cc b/src/libflake-c/nix_api_flake.cc index 0cc9a6a10..f100bf146 100644 --- a/src/libflake-c/nix_api_flake.cc +++ b/src/libflake-c/nix_api_flake.cc @@ -7,7 +7,6 @@ #include "nix_api_fetchers.h" #include "nix/flake/flake.hh" -#include "nix/fetchers/input-cache.hh" nix_flake_settings * nix_flake_settings_new(nix_c_context * context) { @@ -178,7 +177,7 @@ nix_locked_flake * nix_flake_lock( { nix_clear_err(context); try { - nix::fetchers::InputCache::getCache()->clear(); + eval_state->state.resetFileCache(); auto lockedFlake = nix::make_ref(nix::flake::lockFlake( *flakeSettings->settings, eval_state->state, *flakeReference->flakeRef, *flags->lockFlags)); return new nix_locked_flake{lockedFlake}; diff --git a/src/libflake/flake/flake.cc b/src/libflake/flake/flake.cc index cee39defc..afeefdaec 100644 --- a/src/libflake/flake/flake.cc +++ b/src/libflake/flake/flake.cc @@ -341,7 +341,7 @@ static Flake getFlake( const InputAttrPath & lockRootAttrPath) { // Fetch a lazy tree first. - auto cachedInput = fetchers::InputCache::getCache()->getAccessor(state.store, originalRef.input, useRegistries); + auto cachedInput = state.inputCache->getAccessor(state.store, originalRef.input, useRegistries); auto resolvedRef = FlakeRef(std::move(cachedInput.resolvedInput), originalRef.subdir); auto lockedRef = FlakeRef(std::move(cachedInput.lockedInput), originalRef.subdir); @@ -356,7 +356,7 @@ static Flake getFlake( debug("refetching input '%s' due to self attribute", newLockedRef); // FIXME: need to remove attrs that are invalidated by the changed input attrs, such as 'narHash'. newLockedRef.input.attrs.erase("narHash"); - auto cachedInput2 = fetchers::InputCache::getCache()->getAccessor(state.store, newLockedRef.input, useRegistries); + auto cachedInput2 = state.inputCache->getAccessor(state.store, newLockedRef.input, useRegistries); cachedInput.accessor = cachedInput2.accessor; lockedRef = FlakeRef(std::move(cachedInput2.lockedInput), newLockedRef.subdir); } @@ -717,7 +717,7 @@ LockedFlake lockFlake( if (auto resolvedPath = resolveRelativePath()) { return {*resolvedPath, *input.ref}; } else { - auto cachedInput = fetchers::InputCache::getCache()->getAccessor(state.store, input.ref->input, useRegistries); + auto cachedInput = state.inputCache->getAccessor(state.store, input.ref->input, useRegistries); auto lockedRef = FlakeRef(std::move(cachedInput.lockedInput), input.ref->subdir);