From 2310539e66e12579d4a4c09a460e85ed6ccbc952 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 29 Jun 2025 20:35:14 +0200 Subject: [PATCH] Revert "libstore: don't delete already valid outputs after build" This reverts commit 4ef56601b5a235949dc14b8852aa05580ffaefd9 as this is an insufficient fix for the critical correctness bug. Change-Id: I7885c437ce4df25002d92654312b3b1bae53bfa3 --- src/libstore/build/local-derivation-goal.cc | 16 +++++++++++----- tests/functional/linux-sandbox.sh | 7 ------- tests/functional/regression-fj883.nix | 15 --------------- 3 files changed, 11 insertions(+), 27 deletions(-) delete mode 100644 tests/functional/regression-fj883.nix diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc index 7918ab8fa..8837ac25d 100644 --- a/src/libstore/build/local-derivation-goal.cc +++ b/src/libstore/build/local-derivation-goal.cc @@ -2098,11 +2098,6 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs() before this for loop. */ if (*scratchPath != finalStorePath) outputRewrites[std::string { scratchPath->hashPart() }] = std::string { finalStorePath.hashPart() }; - /* Cancel automatic deletion of that output if it was a scratch output that we just - * registered. */ - if (auto cleaner = scratchOutputsCleaner.extract(outputName)) { - cleaner.mapped().cancel(); - } }; auto orifu = get(outputReferencesIfUnregistered, outputName); @@ -2418,6 +2413,10 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs() the next iteration */ if (newInfo.ca) { localStore.registerValidPaths({{newInfo.path, newInfo}}); + /* Cancel automatic deletion of that output if it was a scratch output. */ + if (auto cleaner = scratchOutputsCleaner.extract(outputName)) { + cleaner.mapped().cancel(); + } } infos.emplace(outputName, std::move(newInfo)); @@ -2446,6 +2445,13 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs() infos2.insert_or_assign(newInfo.path, newInfo); } localStore.registerValidPaths(infos2); + + /* Cancel automatic deletion of that output if it was a scratch output that we just registered. */ + for (auto & [outputName, _ ] : infos) { + if (auto cleaner = scratchOutputsCleaner.extract(outputName)) { + cleaner.mapped().cancel(); + } + } } /* In case of a fixed-output derivation hash mismatch, throw an diff --git a/tests/functional/linux-sandbox.sh b/tests/functional/linux-sandbox.sh index 526605e5f..82f363a09 100644 --- a/tests/functional/linux-sandbox.sh +++ b/tests/functional/linux-sandbox.sh @@ -81,10 +81,3 @@ testCert present fixed-output "$certsymlink" # Symlinks should be added in the sandbox directly and not followed nix-sandbox-build symlink-derivation.nix - -# Regression fj#883: derivations outputs disappearing after rebuild -# build the derivation for both its outputs and delete one of them. -# simulates substitution or copying only one output from a builder. -nix-store --delete $(nix-sandbox-build --no-out-link ./regression-fj883.nix -A base.lib) -# build a derivation depending on previous one. this should succeed -nix-sandbox-build --no-out-link ./regression-fj883.nix -A downstream diff --git a/tests/functional/regression-fj883.nix b/tests/functional/regression-fj883.nix deleted file mode 100644 index 2317145b7..000000000 --- a/tests/functional/regression-fj883.nix +++ /dev/null @@ -1,15 +0,0 @@ -with import ./config.nix; - -rec { - base = mkDerivation { - name = "base"; - outputs = [ "out" "lib" ]; - buildCommand = "echo > $out; echo > $lib"; - }; - - downstream = mkDerivation { - name = "downstream"; - deps = [ base.out base.lib ]; - buildCommand = "echo $deps > $out"; - }; -}