Skip to content

Conversation

@edolstra
Copy link
Member

@edolstra edolstra commented Jan 7, 2026

Motivation

Previously, the local NAR cache was indexed by the store path hash. Making it content-addressed (i.e. indexed by NAR hash) provides some potential deduplication, but more importantly, makes it possible to substitute NARs from the local NAR cache with fewer trust issues (see DeterminateSystems#279).

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@edolstra edolstra requested a review from Ericson2314 as a code owner January 7, 2026 21:49
@Ericson2314
Copy link
Member

Do we need to bump a cache version?

@edolstra
Copy link
Member Author

edolstra commented Jan 8, 2026

@Ericson2314 There is no version at the moment. There shouldn't be any upgrade issues since the new file names in the cache have a different length.


ref<SourceAccessor> RemoteFSAccessor::addToCache(std::string_view hashPart, std::string && nar)
ref<SourceAccessor> RemoteFSAccessor::addToCache(
std::string_view hashPart,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string_view hashPart,

}

auto narAccessor = makeNarAccessor(std::move(nar));
nars.emplace(hashPart, narAccessor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nars.emplace(hashPart, narAccessor);

StringSink sink;
store->narFromPath(storePath, sink);
return addToCache(storePath.hashPart(), std::move(sink.s));
return addToCache(storePath.hashPart(), cacheFile, listingFile, std::move(sink.s));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return addToCache(storePath.hashPart(), cacheFile, listingFile, std::move(sink.s));
auto accessor = addToCache(cacheFile, listingFile, std::move(sink.s));
narsHashes.emplace(storePath.hashPart(), info->narHash);
nars.emplace(info->narHash, accessor);
return accessor;

Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no version at the moment. There shouldn't be any upgrade issues since the new file names in the cache have a different length.

sounds good


OK generally looks good, but I would make it a double map (see final comment) so we don't end up opening multiple NAR accessors for the same NAR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants