From c53673e0ad73fecf79be4df61be01e91c0a7f230 Mon Sep 17 00:00:00 2001 From: dramforever Date: Tue, 7 Apr 2026 15:53:57 +0800 Subject: [PATCH 1/2] fetchClosure: Add temproot before checking path This avoids the fetched path from getting garbage collected if it is already valid. --- src/libexpr/primops/fetchClosure.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libexpr/primops/fetchClosure.cc b/src/libexpr/primops/fetchClosure.cc index 0f7eafefe9e6..84bce6116ea3 100644 --- a/src/libexpr/primops/fetchClosure.cc +++ b/src/libexpr/primops/fetchClosure.cc @@ -24,6 +24,8 @@ static void runFetchClosureWithRewrite( const std::optional & toPathMaybe, Value & v) { + if (toPathMaybe) + state.store->addTempRoot(*toPathMaybe); // establish toPath or throw @@ -75,6 +77,7 @@ static void runFetchClosureWithRewrite( static void runFetchClosureWithContentAddressedPath( EvalState & state, const PosIdx pos, Store & fromStore, const StorePath & fromPath, Value & v) { + state.store->addTempRoot(fromPath); if (!state.store->isValidPath(fromPath)) copyClosure(fromStore, *state.store, RealisedPath::Set{fromPath}); @@ -104,6 +107,7 @@ static void runFetchClosureWithContentAddressedPath( static void runFetchClosureWithInputAddressedPath( EvalState & state, const PosIdx pos, Store & fromStore, const StorePath & fromPath, Value & v) { + state.store->addTempRoot(fromPath); if (!state.store->isValidPath(fromPath)) copyClosure(fromStore, *state.store, RealisedPath::Set{fromPath}); From 734a205d58a559a622ebc98256f4af4d968426b7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 3 Jun 2026 16:27:16 +0200 Subject: [PATCH 2/2] copyPaths(): Register temp roots on the destination store Note: this only prevents the paths from being GCed during the copy. You still need to use `nix copy --out-link ...` to prevent GC afterwards. Less ambitious fix than https://github.com/NixOS/nix/pull/15719. --- src/libstore/store-api.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 1145c2574e56..edc8daafc137 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -1040,6 +1040,9 @@ std::map copyPaths( CheckSigsFlag checkSigs, SubstituteFlag substitute) { + for (auto & path : storePaths) + dstStore.addTempRoot(path); + auto valid = dstStore.queryValidPaths(storePaths, substitute); StorePathSet missing;