Skip to content

Commit 5e90b64

Browse files
committed
libfetchers: avoid re-copying substituted inputs
Previously when creating the accessor for substituted/cached inputs, Nix would neither: - Ensure a cache entry exists for the substituted inputs (which are already in the store) - Use the cache for substituted inputs. Instead, it attempted to find the always missing fingerprint of the original, unsubstituted input Both of these 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 #11228 The work in #12911 already fixed this in most cases, but here we can ensure it applies to the substituted store paths used for inputs
1 parent ab7feb3 commit 5e90b64

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/libfetchers/fetchers.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,19 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> sto
332332

333333
debug("using substituted/cached input '%s' in '%s'", to_string(), store->printStorePath(storePath));
334334

335-
auto accessor = makeStorePathAccessor(store, storePath);
336-
337-
accessor->fingerprint = getFingerprint(store);
335+
/*
336+
* NOTE: Make sure to use this code path for creating the accessor!! It contains special casing for
337+
* correctly caching paths already in the store, like we're dealing with here
338+
*
339+
* This avoids https://github.com/NixOS/nix/issues/11228, and ensures the workaround introduced in
340+
* https://github.com/NixOS/nix/pull/12911 applies to the substituted input
341+
*/
342+
auto input = fromAttrs(*settings, {{"type", "path"}, {"path", store->printStorePath(storePath)}});
343+
auto [accessor, result] = input.scheme->getAccessor(store, input);
344+
345+
// We can then re-use that nicely cached fingerprint in the new accessor, while continuing to return our
346+
// original Input and its attributes
347+
accessor->fingerprint = result.getFingerprint(store);
338348

339349
accessor->setPathDisplay("«" + to_string() + "»");
340350

0 commit comments

Comments
 (0)