From 5f362303687a78160fe809467d0cc11657b4135b Mon Sep 17 00:00:00 2001 From: Lexi Mattick Date: Thu, 11 Jul 2024 16:18:24 -0700 Subject: [PATCH] Eval cache: fix cache regressions - Fix eval cache not being persisted in `nix develop` (since #10570) - Fallback to flake path so the eval cache isn't disabled for flakes evaluated by a relative `path:` (since #10149, #10176) - Don't attempt to commit cache transaction if there is no active transaction, which will spew errors in edge cases - Drive-by: trivial typo fix --- src/libcmd/installable-value.hh | 2 +- src/libexpr/eval-cache.cc | 2 +- src/libflake/flake/flake.cc | 6 ++++-- src/nix/develop.cc | 4 ++++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libcmd/installable-value.hh b/src/libcmd/installable-value.hh index f300d392bb52..798cb5e1a00f 100644 --- a/src/libcmd/installable-value.hh +++ b/src/libcmd/installable-value.hh @@ -66,7 +66,7 @@ struct ExtraPathInfoValue : ExtraPathInfo }; /** - * An Installable which corresponds a Nix langauge value, in addition to + * An Installable which corresponds a Nix language value, in addition to * a collection of \ref DerivedPath "derived paths". */ struct InstallableValue : Installable diff --git a/src/libexpr/eval-cache.cc b/src/libexpr/eval-cache.cc index 2630c34d5637..5085fedc2f05 100644 --- a/src/libexpr/eval-cache.cc +++ b/src/libexpr/eval-cache.cc @@ -95,7 +95,7 @@ struct AttrDb { try { auto state(_state->lock()); - if (!failed) + if (!failed && state->txn->active) state->txn->commit(); state->txn.reset(); } catch (...) { diff --git a/src/libflake/flake/flake.cc b/src/libflake/flake/flake.cc index 6f47b5992298..6dcdd96d1d2d 100644 --- a/src/libflake/flake/flake.cc +++ b/src/libflake/flake/flake.cc @@ -947,8 +947,10 @@ std::optional LockedFlake::getFingerprint(ref store) const { if (lockFile.isUnlocked()) return std::nullopt; - auto fingerprint = flake.lockedRef.input.getFingerprint(store); - if (!fingerprint) return std::nullopt; + auto fingerprint = flake.lockedRef.input.getFingerprint(store) + // Fingerprints are null for relative path references so we use + // the flake path as a fallback to avoid losing caching. + .value_or(flake.path.to_string()); *fingerprint += fmt(";%s;%s", flake.lockedRef.subdir, lockFile); diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 6bd3dc9efc6a..b89de5d5c1d7 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -697,6 +697,10 @@ struct CmdDevelop : Common, MixEnvironment } } + // Release our references to eval caches to ensure they are persisted to disk, because + // we are about to exec out of this process without running C++ destructors. + getEvalState()->evalCaches.clear(); + runProgramInStore(store, UseLookupPath::Use, shell, args, buildEnvironment.getSystem()); #endif }