Skip to content

Conversation

@kalbasit
Copy link
Owner

This implements the Nix Binary Cache Index Protocol as outlined in RFC 0195.
The index provides a way for clients to efficiently determine if a NAR info
hash exists in the cache without querying the server for every hash.

Key changes:

  • Added FileStore interface and implementations for local and S3 storage.
  • Added GetAllNarInfos database query and implementation.
  • Implemented nixcacheindex package for manifest, shard, and delta management.
  • Wired up the index feature into pkg/cache and pkg/server.
  • Added --experimental-cache-index flag to enable the feature.
  • Implemented background index generation using cron.

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jan 15, 2026
@dosubot
Copy link

dosubot bot commented Jan 15, 2026

Related Documentation

Checked 1 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

Copy link
Owner Author

kalbasit commented Jan 15, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@dosubot dosubot bot added enhancement New feature or request go Pull requests that update go code labels Jan 15, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kalbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Nix cache by integrating the Nix Binary Cache Index Protocol. This new functionality allows for the creation and serving of a comprehensive index of all stored NAR infos, enabling Nix clients to perform highly efficient lookups. The change involves adding new storage abstractions for general files, a dedicated package for index management, database query extensions, and a background process for index generation, all configurable via an experimental flag.

Highlights

  • Nix Binary Cache Index Protocol Implementation: This pull request fully implements the Nix Binary Cache Index Protocol (RFC 0195), enabling clients to efficiently determine if a NAR info hash exists in the cache without querying the server for every hash.
  • New FileStore Interface and Implementations: A new FileStore interface has been introduced to handle arbitrary file storage, with concrete implementations for both local disk and S3 storage backends. This is used for storing the generated cache index files.
  • Database Query for All NAR Infos: A new database query, GetAllNarInfos, has been added across MySQL, PostgreSQL, and SQLite to retrieve all NAR info hashes and their associated file metadata, which is crucial for building the cache index.
  • Nix Cache Index Package and Management: A new nixcacheindex package has been created to manage the manifest, shards, and deltas of the cache index. The cache now includes logic to generate and store these index components.
  • Integration and Experimental Flag: The cache index feature is wired into the pkg/cache and pkg/server components. It is controlled by a new --experimental-cache-index flag, allowing for opt-in usage. The server now exposes an endpoint for clients to fetch index files.
  • Background Index Generation: The cache index is generated in the background using a cron job, scheduled to run hourly, ensuring the index remains up-to-date with the cache's contents.
  • Optimized Cache Queries: When enabled, cache queries now leverage the generated index to quickly identify 'definite misses', avoiding unnecessary upstream checks and improving performance.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an implementation of the Nix Binary Cache Index Protocol, which is a significant feature for improving cache query performance. The changes are well-structured, introducing a FileStore interface, a new database query for index generation, and wiring everything up through the cache and server packages. The use of a background cron job for index generation is a good approach.

My review focuses on a critical security vulnerability, a performance and correctness issue in the database query, and an improvement for the feature toggle logic. All original comments have been retained as they align with the repository's best practices and do not contradict any provided rules. Overall, this is a great addition, and with these fixes, it will be even more robust and secure.

@kalbasit kalbasit force-pushed the 01-15-feat_implement_nix_binary_cache_index_protocol branch from 66e0554 to e4660b6 Compare January 16, 2026 08:21
@kalbasit kalbasit force-pushed the 01-14-feat_wire_up_new_index_feature_into_pkg_cache_upstream branch from 17d937d to 998cc26 Compare January 16, 2026 08:21
@kalbasit kalbasit force-pushed the 01-15-feat_implement_nix_binary_cache_index_protocol branch from e4660b6 to b99c9c8 Compare January 16, 2026 08:52
@kalbasit
Copy link
Owner Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request successfully implements the Nix Binary Cache Index Protocol as described in RFC 0195. The changes are well-structured, introducing the feature behind an experimental flag, adding a new FileStore interface with implementations for local and S3 storage, and integrating the index generation and querying into the existing cache logic. The background index generation via a cron job is a good approach.

My review includes one suggestion for a memory efficiency improvement in the shard generation process. Overall, this is a solid implementation of a significant new feature.

@kalbasit kalbasit force-pushed the 01-14-feat_wire_up_new_index_feature_into_pkg_cache_upstream branch from 9b9652b to c11b777 Compare January 16, 2026 10:02
@kalbasit kalbasit force-pushed the 01-15-feat_implement_nix_binary_cache_index_protocol branch 2 times, most recently from 4683858 to d131875 Compare January 16, 2026 10:25
@kalbasit kalbasit force-pushed the 01-14-feat_wire_up_new_index_feature_into_pkg_cache_upstream branch from c11b777 to cd7d68e Compare January 16, 2026 10:25
@kalbasit
Copy link
Owner Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant new feature: the Nix Binary Cache Index Protocol, as described in RFC 0195. The implementation is well-structured, adding a new FileStore interface, implementing it for both local and S3 storage, and integrating the index generation and querying logic into the existing cache and server components. The use of a background cron job for index generation is a good approach. The changes are extensive but follow existing patterns in the codebase. I've identified a couple of areas for improvement related to scalability and robustness, which are detailed in the comments.

@kalbasit kalbasit force-pushed the 01-14-feat_wire_up_new_index_feature_into_pkg_cache_upstream branch from cd7d68e to 5721a56 Compare January 16, 2026 10:32
@kalbasit kalbasit force-pushed the 01-15-feat_implement_nix_binary_cache_index_protocol branch from d131875 to 4aacf9f Compare January 16, 2026 10:32
@kalbasit kalbasit force-pushed the 01-14-feat_wire_up_new_index_feature_into_pkg_cache_upstream branch from 5721a56 to fd73419 Compare January 16, 2026 10:42
@kalbasit kalbasit force-pushed the 01-15-feat_implement_nix_binary_cache_index_protocol branch from 4aacf9f to bec750a Compare January 16, 2026 10:42
@kalbasit kalbasit force-pushed the 01-14-feat_wire_up_new_index_feature_into_pkg_cache_upstream branch from fd73419 to febd8b1 Compare January 16, 2026 10:49
@kalbasit kalbasit force-pushed the 01-15-feat_implement_nix_binary_cache_index_protocol branch from bec750a to f9051f8 Compare January 16, 2026 10:49
@kalbasit
Copy link
Owner Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the Nix Binary Cache Index Protocol as outlined in RFC 0195, which is a great feature for improving client performance. The implementation is well-structured, introducing a FileStore interface for abstracting file storage, with implementations for both local and S3 backends. The cache index generation is handled by a background cron job, and the server is updated with a new endpoint to serve the index files. The code is clean and includes good test coverage, including security tests for path traversal. Overall, this is a solid implementation. The suggestion to improve error handling in the index generation logic is valid and should be considered.

@kalbasit kalbasit force-pushed the 01-15-feat_implement_nix_binary_cache_index_protocol branch from f9051f8 to cba9ca8 Compare January 17, 2026 01:14
@kalbasit kalbasit force-pushed the 01-14-feat_wire_up_new_index_feature_into_pkg_cache_upstream branch from febd8b1 to 15192e0 Compare January 17, 2026 01:14
@kalbasit kalbasit force-pushed the 01-15-feat_implement_nix_binary_cache_index_protocol branch from cba9ca8 to 135b4b2 Compare January 17, 2026 01:34
@kalbasit kalbasit force-pushed the 01-14-feat_wire_up_new_index_feature_into_pkg_cache_upstream branch from 15192e0 to afd3832 Compare January 17, 2026 01:34
@kalbasit kalbasit force-pushed the 01-14-feat_wire_up_new_index_feature_into_pkg_cache_upstream branch from afd3832 to 2d7cb03 Compare January 17, 2026 01:46
@kalbasit kalbasit force-pushed the 01-15-feat_implement_nix_binary_cache_index_protocol branch 2 times, most recently from 52f0e09 to cc91e43 Compare January 17, 2026 03:22
@kalbasit kalbasit force-pushed the 01-14-feat_wire_up_new_index_feature_into_pkg_cache_upstream branch from 2d7cb03 to d67914f Compare January 17, 2026 03:22
@kalbasit kalbasit force-pushed the 01-15-feat_implement_nix_binary_cache_index_protocol branch from cc91e43 to 27e580c Compare January 17, 2026 21:06
@kalbasit kalbasit force-pushed the 01-14-feat_wire_up_new_index_feature_into_pkg_cache_upstream branch from d67914f to b4add2b Compare January 17, 2026 21:06
This implements the Nix Binary Cache Index Protocol as outlined in RFC 0195.
The index provides a way for clients to efficiently determine if a NAR info
hash exists in the cache without querying the server for every hash.

Key changes:
- Added FileStore interface and implementations for local and S3 storage.
- Added GetAllNarInfos database query and implementation.
- Implemented nixcacheindex package for manifest, shard, and delta management.
- Wired up the index feature into pkg/cache and pkg/server.
- Added --experimental-cache-index flag to enable the feature.
- Implemented background index generation using cron.
@kalbasit kalbasit force-pushed the 01-14-feat_wire_up_new_index_feature_into_pkg_cache_upstream branch from b4add2b to cc70de2 Compare January 19, 2026 04:50
@kalbasit kalbasit force-pushed the 01-15-feat_implement_nix_binary_cache_index_protocol branch from 27e580c to dff286a Compare January 19, 2026 04:50
@kalbasit kalbasit marked this pull request as draft January 19, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants