mirror of
https://github.com/NixOS/nix.git
synced 2025-12-12 20:11:03 +01:00
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 https://github.com/NixOS/nix/issues/11228 Using the same method as https://github.com/NixOS/nix/pull/12911, we can create a cache entry for the fingerprint of substituted/cached inputs and avoid this problem entirely
This commit is contained in:
parent
ab7feb3898
commit
74305d5260
2 changed files with 20 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include "nix/util/json-utils.hh"
|
||||
#include "nix/fetchers/store-path-accessor.hh"
|
||||
#include "nix/fetchers/fetch-settings.hh"
|
||||
#include "nix/fetchers/fetch-to-store.hh"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
|
|
@ -336,6 +337,15 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> sto
|
|||
|
||||
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() + "»");
|
||||
|
||||
return {accessor, *this};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue