libstore: report all differing outputs rather than just the first

Before:

error: derivation '/nix/store/4spy3nz1661zm15gkybsy1h5f36aliwx-python3.11-test-1.0.0.drv' may not be deterministic: output '/nix/store/ccqcp01zg18wp9iadzmzimqzdi3ll08d-python3.11-test-1.0.0-dist' differs from '/nix/store/ccqcp01zg18wp9iadzmzimqzdi3ll08d-python3.11-test-1.0.0-dist.check'

After:

error: derivation '4spy3nz1661zm15gkybsy1h5f36aliwx-python3.11-test-1.0.0.drv' may not be deterministic: outputs differ
         output differs: output '/nix/store/ccqcp01zg18wp9iadzmzimqzdi3ll08d-python3.11-test-1.0.0-dist' differs from '/nix/store/ccqcp01zg18wp9iadzmzimqzdi3ll08d-python3.11-test-1.0.0-dist.check'
         output differs: output '/nix/store/yl59v08356i841c560alb0zmk7q16klb-python3.11-test-1.0.0' differs from '/nix/store/yl59v08356i841c560alb0zmk7q16klb-python3.11-test-1.0.0.check'

Change-Id: Ib2871fa602bf1fa9c00e2565b3a2e1b26f908152
This commit is contained in:
Linus Heckemann
2024-10-29 18:34:54 +01:00
parent f6077314fa
commit 8b0ac51f12
5 changed files with 59 additions and 11 deletions
+19 -5
View File
@@ -2021,6 +2021,8 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
OutputPathMap finalOutputs;
std::vector<std::pair<Path, std::optional<Path>>> nondeterministic;
for (auto & outputName : sortedOutputNames) {
auto output = get(drv->outputs, outputName);
auto scratchPath = get(scratchOutputs, outputName);
@@ -2307,20 +2309,20 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
buildUser ? buildUser->getGID() : getgid(),
finalDestPath, dst, worker.store.printStorePath(drvPath), tmpDir);
throw NotDeterministic("derivation '%s' may not be deterministic: output '%s' differs from '%s'",
worker.store.printStorePath(drvPath), worker.store.toRealPath(finalDestPath), dst);
nondeterministic.push_back(std::make_pair(worker.store.toRealPath(finalDestPath), dst));
} else
throw NotDeterministic("derivation '%s' may not be deterministic: output '%s' differs",
worker.store.printStorePath(drvPath), worker.store.toRealPath(finalDestPath));
nondeterministic.push_back(std::make_pair(worker.store.toRealPath(finalDestPath), std::nullopt));
}
/* Since we verified the build, it's now ultimately trusted. */
if (!oldInfo.ultimate) {
else if (!oldInfo.ultimate) {
oldInfo.ultimate = true;
localStore.signPathInfo(oldInfo);
localStore.registerValidPaths({{oldInfo.path, oldInfo}});
}
/* Don't register anything, since we already have the
previous versions which we're comparing. */
continue;
}
@@ -2351,6 +2353,18 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
}
if (buildMode == bmCheck) {
if (!nondeterministic.empty()) {
std::ostringstream msg;
msg << HintFmt("derivation '%s' may not be deterministic: outputs differ", drvPath.to_string());
for (auto [oldPath, newPath]: nondeterministic) {
if (newPath) {
msg << HintFmt("\n output differs: output '%s' differs from '%s'", oldPath.c_str(), *newPath);
} else {
msg << HintFmt("\n output '%s' differs", oldPath.c_str());
}
}
throw NotDeterministic(msg.str());
}
/* In case of fixed-output derivations, if there are
mismatches on `--check` an error must be thrown as this is
also a source for non-determinism. */