Skip to content

Commit

Permalink
Eval cache: fix cache regressions
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
kognise committed Jul 11, 2024
1 parent 0363dbf commit 5f36230
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/libcmd/installable-value.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 (...) {
Expand Down
6 changes: 4 additions & 2 deletions src/libflake/flake/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,10 @@ std::optional<Fingerprint> LockedFlake::getFingerprint(ref<Store> 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);

Expand Down
4 changes: 4 additions & 0 deletions src/nix/develop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 5f36230

Please sign in to comment.