aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2020-09-17 13:36:58 +0200
committerregnat <rg@regnat.ovh>2020-09-17 13:36:58 +0200
commit520895b1dac1b82be9f571df3981a15cfada2968 (patch)
treebfb0b257b959c15a40e6d988dc71ae4bab82bb71
parent609a6d6d9f1a8689c2336301a2e4db01ad20037c (diff)
Fix garbage collection of CA derivations
Fix #4026
-rw-r--r--src/libstore/gc.cc9
-rw-r--r--tests/content-addressed.sh3
2 files changed, 9 insertions, 3 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index e6cbc525d..08b53c702 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -574,9 +574,12 @@ bool LocalStore::canReachRoot(GCState & state, StorePathSet & visited, const Sto
/* If keep-derivations is set and this is a derivation, then
don't delete the derivation if any of the outputs are alive. */
if (state.gcKeepDerivations && path.isDerivation()) {
- for (auto & i : queryDerivationOutputs(path))
- if (isValidPath(i) && queryPathInfo(i)->deriver == path)
- incoming.insert(i);
+ for (auto & [name, maybeOutPath] : queryPartialDerivationOutputMap(path))
+ if (maybeOutPath &&
+ isValidPath(*maybeOutPath) &&
+ queryPathInfo(*maybeOutPath)->deriver == path
+ )
+ incoming.insert(*maybeOutPath);
}
/* If keep-outputs is set, then don't delete this path if there
diff --git a/tests/content-addressed.sh b/tests/content-addressed.sh
index ae9e3c59e..0ae2852d2 100644
--- a/tests/content-addressed.sh
+++ b/tests/content-addressed.sh
@@ -15,3 +15,6 @@ out1=$(nix-build "${commonArgs[@]}" ./content-addressed.nix --arg seed 1)
out2=$(nix-build "${commonArgs[@]}" ./content-addressed.nix --arg seed 2)
test $out1 == $out2
+
+nix-instantiate --experimental-features ca-derivations ./content-addressed.nix -A rootCA --arg seed 5
+nix-collect-garbage --experimental-features ca-derivations --option keep-derivations true