Skip to content

C API: Add copy_path to Store API#14768

Merged
xokdvium merged 1 commit intoNixOS:masterfrom
pkpbynum:capi/copy-path
Feb 10, 2026
Merged

C API: Add copy_path to Store API#14768
xokdvium merged 1 commit intoNixOS:masterfrom
pkpbynum:capi/copy-path

Conversation

@pkpbynum
Copy link
Contributor

@pkpbynum pkpbynum commented Dec 10, 2025

Motivation

This provides more granular control over paths as they are copied in a few ways:

  • Ability to control timing of copied paths
  • Ability to repair an individual path
  • Ability to control signature checking

My primary motivation is to be able to monitor copy progress on a per-path basis. AFAIK the alternative way to do this is to log & parse the JSON format--not possible from FFI (?). Secondarily, I'd like to repair individual paths without copying the entire closure (otherwise I'd just add the repair param to the existing copyClosure).

Context

Tested on my fork calling from Rust.


Add 👍 to pull requests you find important.

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

@pkpbynum pkpbynum requested a review from edolstra as a code owner December 10, 2025 16:45
@github-actions github-actions bot added the c api Nix as a C library with a stable interface label Dec 10, 2025
@xokdvium
Copy link
Contributor

xokdvium commented Jan 1, 2026

Sounds good, but needs release notes.

@pkpbynum
Copy link
Contributor Author

Sounds good, but needs release notes.

done

context->last_err_code = NIX_OK;
try {
if (srcStore == nullptr)
return nix_set_err_msg(context, NIX_ERR_UNKNOWN, "Source store is null");
Copy link
Contributor

@xokdvium xokdvium Feb 6, 2026

Choose a reason for hiding this comment

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

I wonder if we should add a new error type like NIX_ERR_INVALID_ARGUMENT for such cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm just following the existing usage here: https://github.com/NixOS/nix/blob/master/src/libmain-c/nix_api_main.cc#L26

Could we save that sort of change for follow-up? It seems like it would/should involve a wider cleanup of error handling in C API:

  1. Improve error types/messages
  2. check inputs for nullptr

Copy link
Member

Choose a reason for hiding this comment

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

Frankly I wouldn't mind if this was just an assert, or not here at all, since both arguments being non-null are morally part of the signature.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can address this in a follow-up I suppose. The current state of things where stuff just segfaults isn't ideal and certainly not the long-term goal. Adding an error code does pose a backwards-compatibility issue and the current set of error codes isn't particularly extensible and the error codes aren't yet documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are there any additional changes I should make, or is this good to merge as-is?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think @roberth has made a comment about having some tests for this, but maybe this can be done in a follow-up.

@xokdvium xokdvium added this pull request to the merge queue Feb 10, 2026
Merged via the queue into NixOS:master with commit f0498b9 Feb 10, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c api Nix as a C library with a stable interface documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants