1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-29 10:31:15 +02:00

C API: (breaking) remove nix-flake-c global init

This commit is contained in:
Robert Hensing 2025-03-26 08:59:05 +00:00
parent 3c4c0953e0
commit 6a192ec0cd
12 changed files with 124 additions and 69 deletions

View file

@ -1,6 +1,7 @@
#include "nix_api_flake.h"
#include "nix_api_flake_internal.hh"
#include "nix_api_util_internal.h"
#include "nix_api_expr_internal.h"
#include "flake/flake.hh"
@ -18,15 +19,11 @@ void nix_flake_settings_free(nix_flake_settings * settings)
delete settings;
}
nix_err nix_flake_init_global(nix_c_context * context, nix_flake_settings * settings)
nix_err nix_flake_settings_add_to_eval_state_builder(
nix_c_context * context, nix_flake_settings * settings, nix_eval_state_builder * builder)
{
static std::shared_ptr<nix::flake::Settings> registeredSettings;
try {
if (registeredSettings)
throw nix::Error("nix_flake_init_global already initialized");
registeredSettings = settings->settings;
nix::flake::initLib(*registeredSettings);
settings->settings->configureEvalSettings(builder->settings);
}
NIXC_CATCH_ERRS
}

View file

@ -35,9 +35,15 @@ nix_flake_settings * nix_flake_settings_new(nix_c_context * context);
void nix_flake_settings_free(nix_flake_settings * settings);
/**
* @brief Register Flakes support process-wide.
* @brief Initialize a `nix_flake_settings` to contain `builtins.getFlake` and
* potentially more.
*
* @param[out] context Optional, stores error information
* @param[in] settings The settings to use for e.g. `builtins.getFlake`
* @param[in] builder The builder to modify
*/
nix_err nix_flake_init_global(nix_c_context * context, nix_flake_settings * settings);
nix_err nix_flake_settings_add_to_eval_state_builder(
nix_c_context * context, nix_flake_settings * settings, nix_eval_state_builder * builder);
#ifdef __cplusplus
} // extern "C"