1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-16 23:42:43 +01:00

create cache entry for paths already in the nix store

This allows path:/nix/store/* paths to not be copied twice to the nix
store.

(cherry picked from commit 61c6210dbf)
This commit is contained in:
Jörg Thalheim 2025-04-03 13:27:39 +02:00
parent b47bd02a6a
commit 2a4e2ecd89
3 changed files with 30 additions and 6 deletions

View file

@ -2,6 +2,7 @@
#include "store-api.hh"
#include "archive.hh"
#include "store-path-accessor.hh"
#include "fetch-to-store.hh"
namespace nix::fetchers {
@ -157,6 +158,15 @@ struct PathInputScheme : InputScheme
});
storePath = store->addToStoreFromDump(*src, "source");
}
// To avoid copying the path again to the /nix/store, we need to add a cache entry.
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive;
auto fp = getFingerprint(store, input);
if (fp) {
auto cacheKey = makeFetchToStoreCacheKey(input.getName(), *fp, method, "/");
fetchers::getCache()->upsert(cacheKey, *store, {}, *storePath);
}
input.attrs.insert_or_assign("lastModified", uint64_t(mtime));
return {makeStorePathAccessor(store, *storePath), std::move(input)};