Skip to content

Commit c17e3ba

Browse files
committed
libfetchers: avoid re-copying substituted inputs
Previously, Nix would not create a cache entry for substituted/cached inputs This led to severe slowdowns in some scenarios where a large input (like Nixpkgs) had already been unpacked to the store but didn't exist in a users cache, as described in NixOS#11228 Using the same method as NixOS#12911, we can create a cache entry for the fingerprint of substituted/cached inputs and avoid this problem entirely
1 parent ab7feb3 commit c17e3ba

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/libfetchers/fetchers.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "nix/util/json-utils.hh"
66
#include "nix/fetchers/store-path-accessor.hh"
77
#include "nix/fetchers/fetch-settings.hh"
8+
#include "nix/fetchers/fetch-to-store.hh"
89

910
#include <nlohmann/json.hpp>
1011

@@ -336,6 +337,14 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> sto
336337

337338
accessor->fingerprint = getFingerprint(store);
338339

340+
// NOTE: This avoids https://github.com/NixOS/nix/issues/11228!
341+
// See https://github.com/NixOS/nix/pull/12911 & https://github.com/NixOS/nix/pull/14041
342+
if (accessor->fingerprint) {
343+
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive;
344+
auto cacheKey = makeFetchToStoreCacheKey(getName(), *accessor->fingerprint, method, "/");
345+
settings->getCache()->upsert(cacheKey, *store, {}, storePath);
346+
}
347+
339348
accessor->setPathDisplay("«" + to_string() + "»");
340349

341350
return {accessor, *this};

0 commit comments

Comments
 (0)