Skip to content

Commit 641c031

Browse files
C API: add nix_locked_flake_get_path for flake path retreival
1 parent 236ebef commit 641c031

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/libflake-c/nix_api_flake.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,15 @@ nix_value * nix_locked_flake_get_output_attrs(
206206
NIXC_CATCH_ERRS_NULL
207207
}
208208

209+
nix_err nix_locked_flake_get_path(
210+
nix_c_context * context, nix_locked_flake * lockedFlake, nix_get_string_callback callback, void * user_data)
211+
{
212+
nix_clear_err(context);
213+
try {
214+
auto v = lockedFlake->lockedFlake->flake.path.parent().to_string();
215+
return call_nix_get_string_callback(v, callback, user_data);
216+
}
217+
NIXC_CATCH_ERRS
218+
}
219+
209220
} // extern "C"

src/libflake-c/nix_api_flake.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,18 @@ void nix_flake_reference_free(nix_flake_reference * store);
238238
nix_value * nix_locked_flake_get_output_attrs(
239239
nix_c_context * context, nix_flake_settings * settings, EvalState * evalState, nix_locked_flake * lockedFlake);
240240

241+
/**
242+
* @brief Get the root path of a flake.
243+
* @note The callback borrows the string only for the duration of the call.
244+
*
245+
* @param[out] context Optional, stores error information
246+
* @param[in] locked_flake the flake to get the path for
247+
* @param[in] callback The callback to call with the string
248+
* @param[in] user_data Additional data to pass for the callback
249+
*/
250+
nix_err nix_locked_flake_get_path(
251+
nix_c_context * context, nix_locked_flake * lockedFlake, nix_get_string_callback callback, void * user_data);
252+
241253
#ifdef __cplusplus
242254
} // extern "C"
243255
#endif

0 commit comments

Comments
 (0)