From 41fab8a31c3cdaf5bcf96af0a96c405454174755 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Sun, 24 Aug 2025 18:50:32 +0200 Subject: [PATCH] legacy/nix-store: do not crash on cache unsoundness Local store make use of SQLite as a cache for output maps, they can diverge with actual store reality. Causing a crash at realization time. We can just throw an error instead. Change-Id: I943a4bddfd2461a34933e9ec079a6638ab58e5b1 Signed-off-by: Raito Bezarius --- lix/legacy/nix-store.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lix/legacy/nix-store.cc b/lix/legacy/nix-store.cc index 515b7fae0..57545c3ae 100644 --- a/lix/legacy/nix-store.cc +++ b/lix/legacy/nix-store.cc @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -88,6 +89,16 @@ try { if (i == drv.outputs.end()) throw Error("derivation '%s' does not have an output named '%s'", store2->printStorePath(path.path), j); + if (!outputPaths.contains(i->first)) { + throw Error( + "Possible SQLite database corruption: derivation '%s' output map contains only " + "outputs '{%s}', not '%s'\n" + "Note: derivation output maps are stored in the SQLite database.", + store2->printStorePath(path.path), + concatStringsSep(", ", std::views::keys(outputPaths)), + i->first + ); + } auto outPath = outputPaths.at(i->first); auto retPath = store->printStorePath(outPath); if (store2) {