Skip to content

Commit 099a74e

Browse files
authored
Merge pull request #14041 from getchoo-contrib/getchoo/cache-substituted-inputs
libfetchers: avoid re-copying substituted inputs
2 parents 534b290 + 74305d5 commit 099a74e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
synopsis: "Substituted flake inputs are no longer re-copied to the store"
3+
prs: [14041]
4+
---
5+
6+
Since 2.25, Nix would fail to store a cache entry for substituted flake inputs,
7+
which in turn would cause them to be re-copied to the store on initial
8+
evaluation. Caching these inputs results in a near doubling of a performance in
9+
some cases — especially on I/O-bound machines and when using commands that
10+
fetch many inputs, like `nix flake archive/prefetch-inputs`

src/libfetchers/fetchers.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "nix/fetchers/fetch-to-store.hh"
55
#include "nix/util/json-utils.hh"
66
#include "nix/fetchers/fetch-settings.hh"
7+
#include "nix/fetchers/fetch-to-store.hh"
78

89
#include <nlohmann/json.hpp>
910

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

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

340+
// Store a cache entry for the substituted tree so later fetches
341+
// can reuse the existing nar instead of copying the unpacked
342+
// input back into the store on every evaluation.
343+
if (accessor->fingerprint) {
344+
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive;
345+
auto cacheKey = makeFetchToStoreCacheKey(getName(), *accessor->fingerprint, method, "/");
346+
settings->getCache()->upsert(cacheKey, *store, {}, storePath);
347+
}
348+
339349
accessor->setPathDisplay("«" + to_string() + "»");
340350

341351
return {accessor, *this};

0 commit comments

Comments
 (0)