Replace fetchToStore cache by sourcePathToHash cache#14769
Open
Replace fetchToStore cache by sourcePathToHash cache#14769
Conversation
roberth
reviewed
Dec 11, 2025
Comment on lines
-26
to
-27
| // FIXME: add an optimisation for the case where the accessor is | ||
| // a `PosixSourceAccessor` pointing to a store path. |
Member
Author
There was a problem hiding this comment.
Don't think so, the path fetcher has an optimization that does something like that now.
Comment on lines
+342
to
+345
| settings.getCache()->upsert( | ||
| makeSourcePathToHashCacheKey( | ||
| *accessor->fingerprint, ContentAddressMethod::Raw::NixArchive, CanonPath::root), | ||
| {{"hash", store.queryPathInfo(storePath)->narHash.to_string(HashFormat::SRI, true)}}); |
Member
There was a problem hiding this comment.
Suggested change
| settings.getCache()->upsert( | |
| makeSourcePathToHashCacheKey( | |
| *accessor->fingerprint, ContentAddressMethod::Raw::NixArchive, CanonPath::root), | |
| {{"hash", store.queryPathInfo(storePath)->narHash.to_string(HashFormat::SRI, true)}}); |
Tests pass without this code. It could be dead or broken.
Make sure to cover this with the _NIX_TEST_BARF_ON_UNCACHEABLE trick.
Member
Author
There was a problem hiding this comment.
_NIX_TEST_BARF_ON_UNCACHEABLE doesn't test that. It fails on inputs that don't have a fingerprint. If you remove the upsert, it disables caching, but there is nothing that tests that.
Member
There was a problem hiding this comment.
I see, that is a bit different. Not a bad idea though considering how unreliable the caches have been.
(does need a different name it seems)
Ericson2314
reviewed
Feb 4, 2026
| fetchers::Cache::Key makeFetchToStoreCacheKey( | ||
| const std::string & name, const std::string & fingerprint, ContentAddressMethod method, const std::string & path) | ||
| fetchers::Cache::Key | ||
| makeSourcePathToHashCacheKey(std::string_view fingerprint, ContentAddressMethod method, const CanonPath & path) |
Ericson2314
reviewed
Feb 4, 2026
Caching NAR hashes instead of store paths makes the cache more general, because we can always compute the store path from the NAR hash, but not the other way around. This is useful for lazy trees, where we want to compute the NAR hash of an input with caching.
9150f91 to
0f43578
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Caching NAR hashes instead of store paths makes the cache more general, because we can always compute the store path from the NAR hash, but not the other way around. This is useful for lazy trees, where we want to compute the NAR hash of an input with caching.
This PR also cherry-picks DeterminateSystems#157, which adds a
Store::maybeQueryPathInfo()method. This is preferred overisValidPath()because it has better caching.Context
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.