From 72ab64b612c15b6f2027bd6d730b5459b93afebb Mon Sep 17 00:00:00 2001 From: Peter Bynum Date: Wed, 10 Dec 2025 11:29:03 -0500 Subject: [PATCH] Add nix_store_copy_path C API --- doc/manual/rl-next/c-api-new-store-methods.md | 1 + src/libstore-c/nix_api_store.cc | 22 +++++++++++++++++++ src/libstore-c/nix_api_store.h | 13 +++++++++++ 3 files changed, 36 insertions(+) diff --git a/doc/manual/rl-next/c-api-new-store-methods.md b/doc/manual/rl-next/c-api-new-store-methods.md index 7269847a2c4..28792e7cc42 100644 --- a/doc/manual/rl-next/c-api-new-store-methods.md +++ b/doc/manual/rl-next/c-api-new-store-methods.md @@ -6,3 +6,4 @@ prs: [14766] The C API now includes additional methods: - `nix_store_query_path_from_hash_part()` - Get the full store path given its hash part +- `nix_store_copy_path()` - Copy a single store path between two stores, allows repairs and configuring signature checking diff --git a/src/libstore-c/nix_api_store.cc b/src/libstore-c/nix_api_store.cc index 158c142836c..f069e31de03 100644 --- a/src/libstore-c/nix_api_store.cc +++ b/src/libstore-c/nix_api_store.cc @@ -352,4 +352,26 @@ StorePath * nix_store_query_path_from_hash_part(nix_c_context * context, Store * NIXC_CATCH_ERRS_NULL } +nix_err nix_store_copy_path( + nix_c_context * context, Store * srcStore, Store * dstStore, const StorePath * path, bool repair, bool checkSigs) +{ + if (context) + context->last_err_code = NIX_OK; + try { + if (srcStore == nullptr) + return nix_set_err_msg(context, NIX_ERR_UNKNOWN, "Source store is null"); + + if (dstStore == nullptr) + return nix_set_err_msg(context, NIX_ERR_UNKNOWN, "Destination store is null"); + + if (path == nullptr) + return nix_set_err_msg(context, NIX_ERR_UNKNOWN, "Store path is null"); + + auto repairFlag = repair ? nix::RepairFlag::Repair : nix::RepairFlag::NoRepair; + auto checkSigsFlag = checkSigs ? nix::CheckSigsFlag::CheckSigs : nix::CheckSigsFlag::NoCheckSigs; + nix::copyStorePath(*srcStore->ptr, *dstStore->ptr, path->path, repairFlag, checkSigsFlag); + } + NIXC_CATCH_ERRS +} + } // extern "C" diff --git a/src/libstore-c/nix_api_store.h b/src/libstore-c/nix_api_store.h index 5c58356070f..e60a7d6c0f7 100644 --- a/src/libstore-c/nix_api_store.h +++ b/src/libstore-c/nix_api_store.h @@ -270,6 +270,19 @@ nix_derivation * nix_store_drv_from_store_path(nix_c_context * context, Store * */ StorePath * nix_store_query_path_from_hash_part(nix_c_context * context, Store * store, const char * hash); +/** + * @brief Copy a path from one store to another. + * + * @param[out] context Optional, stores error information + * @param[in] srcStore nix source store reference + * @param[in] dstStore nix destination store reference + * @param[in] path The path to copy + * @param[in] repair Whether to repair the path + * @param[in] checkSigs Whether to check path signatures are trusted before copying + */ +nix_err nix_store_copy_path( + nix_c_context * context, Store * srcStore, Store * dstStore, const StorePath * path, bool repair, bool checkSigs); + // cffi end #ifdef __cplusplus }