Skip to content

Add binding for nix_store_build_paths#13

Merged
RossComputerGuy merged 1 commit into
integrationfrom
feat/store-build-paths
Feb 25, 2026
Merged

Add binding for nix_store_build_paths#13
RossComputerGuy merged 1 commit into
integrationfrom
feat/store-build-paths

Conversation

@RossComputerGuy
Copy link
Copy Markdown
Member

@RossComputerGuy RossComputerGuy commented Feb 25, 2026

Summary by CodeRabbit

  • New Features
    • Added support to build multiple store paths in a single operation.
    • Returns a mapping of each requested path to its build result/status.
    • Improves throughput for batch build workflows and simplifies collecting build results.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

Adds a new public method Store::build_paths(&mut self, paths: &[&StorePath]) -> Result<BTreeMap<String, String>> that uses an unsafe extern "C" callback and the raw FFI store_build_paths to collect path→result string mappings and return them.

Changes

Cohort / File(s) Summary
Store FFI Binding
nix-bindings-store/src/store.rs
Added pub fn build_paths(&mut self, paths: &[&StorePath]) -> Result<BTreeMap<String, String>> which constructs an outputs map, defines an unsafe extern "C" callback to accumulate results via a user_data pointer, converts &StorePath to raw pointers, and calls raw::store_build_paths. Gated with #[cfg(nix_at_least = "2.31")] and documented as requiring Determinate Nix 3.11+.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Store as Store::build_paths
    participant Callback as "extern \"C\" callback"
    participant FFI as raw::store_build_paths
    participant Native as NativeStore

    Caller->>Store: build_paths(&paths)
    activate Store
    Store->>Store: create BTreeMap outputs
    Store->>Callback: register extern "C" callback (user_data -> map)
    Store->>Store: convert &StorePath -> raw pointers
    Store->>FFI: call raw::store_build_paths(paths, callback, user_data)
    activate FFI
    FFI->>Native: perform builds
    activate Native
    Native->>Callback: invoke callback with (path, result, user_data)
    activate Callback
    Callback->>Store: append path->result into map via user_data
    deactivate Callback
    deactivate Native
    deactivate FFI
    Store->>Caller: return BTreeMap<String, String>
    deactivate Store
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • cole-h

Poem

🐰 I hopped into Store with a curious wiggle,
Callback in paw, with a tiny giggle,
Paths and results I neatly compile,
Returned as a map with rabbitish style,
Build on, dear devs, I'll cheer from the thicket. 🎩

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a binding for the nix_store_build_paths function, which is directly reflected in the new Store::build_paths method addition.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/store-build-paths

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@nix-bindings-store/src/store.rs`:
- Around line 392-393: The build_paths method must be gated with the same
feature flag as the BTreeMap import to avoid compile errors on Nix 2.26–2.30;
add #[cfg(nix_at_least = "2.31")] above the pub fn build_paths(&mut self, paths:
&[&StorePath]) -> Result<BTreeMap<String, String>> definition so the method
(like realise) is only compiled when nix_at_least = "2.31" is enabled, ensuring
the BTreeMap type and related code are present when build_paths is compiled.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b80fcf and 60ee025.

📒 Files selected for processing (1)
  • nix-bindings-store/src/store.rs

Comment thread nix-bindings-store/src/store.rs
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
nix-bindings-store/src/store.rs (2)

401-418: Inline callback is inconsistent with the rest of the file — consider extracting.

Every other callback in this file (callback_get_result_store_path_set, callback_get_result_derivation, callback_make_drv_outputs) is defined at module level with a companion *_data helper. The inline definition here works but breaks the established pattern.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nix-bindings-store/src/store.rs` around lines 401 - 418, Extract the inline
unsafe extern "C" fn callback into a module-level function following the
existing pattern (e.g., name it callback_get_result_map) and add a companion
helper (e.g., callback_get_result_map_data) to create/pack the userdata pointer
from &mut BTreeMap<String, String>; move the current body (converting
path/result CStrs and inserting into the map) verbatim into that new function
and replace the inline closure call site to pass callback_get_result_map as the
function pointer and callback_get_result_map_data(...) as userdata so it matches
callback_get_result_store_path_set / callback_get_result_derivation /
callback_make_drv_outputs conventions.

392-437: No test coverage for build_paths.

All other gated store methods (realise, derivation_from_json, add_derivation, get_fs_closure) have corresponding tests in this file. build_paths has none, making it difficult to verify correctness of the callback wiring and argument passing.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nix-bindings-store/src/store.rs` around lines 392 - 437, Add a test for
Store::build_paths that mirrors the existing tests for
realise/derivation_from_json/add_derivation/get_fs_closure: create a Store and
one or more StorePath fixtures used elsewhere in the test file, call
build_paths(&[&path1, &path2...]) under the same #[cfg(nix_at_least = "2.31")]
gate, and assert the returned BTreeMap contains expected keys and values (verify
the C callback wiring by checking that the inserted map entries match the
supplied StorePath strings and expected result strings). Ensure the test uses
the same setup/teardown helpers in this module (context/Store construction) and
exercises the path pointer conversion (StorePath::as_ptr()) path so the unsafe
callback path and check_call!(raw::store_build_paths(...)) invocation are
covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@nix-bindings-store/src/store.rs`:
- Around line 401-418: Extract the inline unsafe extern "C" fn callback into a
module-level function following the existing pattern (e.g., name it
callback_get_result_map) and add a companion helper (e.g.,
callback_get_result_map_data) to create/pack the userdata pointer from &mut
BTreeMap<String, String>; move the current body (converting path/result CStrs
and inserting into the map) verbatim into that new function and replace the
inline closure call site to pass callback_get_result_map as the function pointer
and callback_get_result_map_data(...) as userdata so it matches
callback_get_result_store_path_set / callback_get_result_derivation /
callback_make_drv_outputs conventions.
- Around line 392-437: Add a test for Store::build_paths that mirrors the
existing tests for realise/derivation_from_json/add_derivation/get_fs_closure:
create a Store and one or more StorePath fixtures used elsewhere in the test
file, call build_paths(&[&path1, &path2...]) under the same #[cfg(nix_at_least =
"2.31")] gate, and assert the returned BTreeMap contains expected keys and
values (verify the C callback wiring by checking that the inserted map entries
match the supplied StorePath strings and expected result strings). Ensure the
test uses the same setup/teardown helpers in this module (context/Store
construction) and exercises the path pointer conversion (StorePath::as_ptr())
path so the unsafe callback path and check_call!(raw::store_build_paths(...))
invocation are covered.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60ee025 and cd1ddad.

📒 Files selected for processing (1)
  • nix-bindings-store/src/store.rs

@RossComputerGuy RossComputerGuy merged commit 5fd0ec1 into integration Feb 25, 2026
5 checks passed
@RossComputerGuy RossComputerGuy deleted the feat/store-build-paths branch February 25, 2026 23:11
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