1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

Merge pull request #14041 from getchoo-contrib/getchoo/cache-substituted-inputs

libfetchers: avoid re-copying substituted inputs
This commit is contained in:
Jörg Thalheim 2025-09-25 13:27:02 +02:00 committed by GitHub
commit 099a74e9f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View file

@ -0,0 +1,10 @@
---
synopsis: "Substituted flake inputs are no longer re-copied to the store"
prs: [14041]
---
Since 2.25, Nix would fail to store a cache entry for substituted flake inputs,
which in turn would cause them to be re-copied to the store on initial
evaluation. Caching these inputs results in a near doubling of a performance in
some cases — especially on I/O-bound machines and when using commands that
fetch many inputs, like `nix flake archive/prefetch-inputs`

View file

@ -4,6 +4,7 @@
#include "nix/fetchers/fetch-to-store.hh" #include "nix/fetchers/fetch-to-store.hh"
#include "nix/util/json-utils.hh" #include "nix/util/json-utils.hh"
#include "nix/fetchers/fetch-settings.hh" #include "nix/fetchers/fetch-settings.hh"
#include "nix/fetchers/fetch-to-store.hh"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@ -336,6 +337,15 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> sto
accessor->fingerprint = getFingerprint(store); accessor->fingerprint = getFingerprint(store);
// Store a cache entry for the substituted tree so later fetches
// can reuse the existing nar instead of copying the unpacked
// input back into the store on every evaluation.
if (accessor->fingerprint) {
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive;
auto cacheKey = makeFetchToStoreCacheKey(getName(), *accessor->fingerprint, method, "/");
settings->getCache()->upsert(cacheKey, *store, {}, storePath);
}
accessor->setPathDisplay("«" + to_string() + "»"); accessor->setPathDisplay("«" + to_string() + "»");
return {accessor, *this}; return {accessor, *this};