Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/libflake-c/nix_api_flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,20 @@ nix_value * nix_locked_flake_get_output_attrs(
NIXC_CATCH_ERRS_NULL
}

nix_err nix_locked_flake_read_path(
nix_c_context * context,
nix_locked_flake * lockedFlake,
const char * path,
nix_get_string_callback callback,
void * user_data)
{
nix_clear_err(context);
try {
auto source_path = lockedFlake->lockedFlake->flake.path.parent() / nix::CanonPath(path);
auto v = source_path.readFile();
return call_nix_get_string_callback(v, callback, user_data);
}
NIXC_CATCH_ERRS
}

} // extern "C"
17 changes: 17 additions & 0 deletions src/libflake-c/nix_api_flake.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,23 @@ void nix_flake_reference_free(nix_flake_reference * store);
nix_value * nix_locked_flake_get_output_attrs(
nix_c_context * context, nix_flake_settings * settings, EvalState * evalState, nix_locked_flake * lockedFlake);

/**
* @brief Reads a file within the flake.
* @note The callback borrows the string only for the duration of the call.
*
* @param[out] context Optional, stores error information
* @param[in] locked_flake the flake to get the path for
* @param[in] path The path within the flake.
* @param[in] callback The callback to call with the string
* @param[in] user_data Additional data to pass for the callback
*/
nix_err nix_locked_flake_read_path(
nix_c_context * context,
nix_locked_flake * lockedFlake,
const char * path,
nix_get_string_callback callback,
void * user_data);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down