mirror of
https://github.com/NixOS/nix
synced 2025-07-02 21:51:50 +02:00
nix-flake-c: Add lock flags
Going with a slightly more limited, high level API supporting the three main use cases. This should allow the underlying code to evolve more freely.
This commit is contained in:
parent
1a3789e222
commit
8c903e0402
3 changed files with 328 additions and 26 deletions
|
@ -97,7 +97,16 @@ nix_flake_lock_flags * nix_flake_lock_flags_new(nix_c_context * context, nix_fla
|
|||
{
|
||||
nix_clear_err(context);
|
||||
try {
|
||||
auto lockSettings = nix::make_ref<nix::flake::LockFlags>();
|
||||
auto lockSettings = nix::make_ref<nix::flake::LockFlags>(nix::flake::LockFlags{
|
||||
.recreateLockFile = false,
|
||||
.updateLockFile = true, // == `nix_flake_lock_flags_set_mode_write_as_needed`
|
||||
.writeLockFile = true, // == `nix_flake_lock_flags_set_mode_write_as_needed`
|
||||
.failOnUnlocked = false, // == `nix_flake_lock_flags_set_mode_write_as_needed`
|
||||
.useRegistries = false,
|
||||
.allowUnlocked = false, // == `nix_flake_lock_flags_set_mode_write_as_needed`
|
||||
.commitLockFile = false,
|
||||
|
||||
});
|
||||
return new nix_flake_lock_flags{lockSettings};
|
||||
}
|
||||
NIXC_CATCH_ERRS_NULL
|
||||
|
@ -108,16 +117,68 @@ void nix_flake_lock_flags_free(nix_flake_lock_flags * flags)
|
|||
delete flags;
|
||||
}
|
||||
|
||||
nix_err nix_flake_lock_flags_set_mode_virtual(nix_c_context * context, nix_flake_lock_flags * flags)
|
||||
{
|
||||
nix_clear_err(context);
|
||||
try {
|
||||
flags->lockFlags->updateLockFile = true;
|
||||
flags->lockFlags->writeLockFile = false;
|
||||
flags->lockFlags->failOnUnlocked = false;
|
||||
flags->lockFlags->allowUnlocked = true;
|
||||
}
|
||||
NIXC_CATCH_ERRS
|
||||
}
|
||||
|
||||
nix_err nix_flake_lock_flags_set_mode_write_as_needed(nix_c_context * context, nix_flake_lock_flags * flags)
|
||||
{
|
||||
nix_clear_err(context);
|
||||
try {
|
||||
flags->lockFlags->updateLockFile = true;
|
||||
flags->lockFlags->writeLockFile = true;
|
||||
flags->lockFlags->failOnUnlocked = false;
|
||||
flags->lockFlags->allowUnlocked = true;
|
||||
}
|
||||
NIXC_CATCH_ERRS
|
||||
}
|
||||
|
||||
nix_err nix_flake_lock_flags_set_mode_check(nix_c_context * context, nix_flake_lock_flags * flags)
|
||||
{
|
||||
nix_clear_err(context);
|
||||
try {
|
||||
flags->lockFlags->updateLockFile = false;
|
||||
flags->lockFlags->writeLockFile = false;
|
||||
flags->lockFlags->failOnUnlocked = true;
|
||||
flags->lockFlags->allowUnlocked = false;
|
||||
}
|
||||
NIXC_CATCH_ERRS
|
||||
}
|
||||
|
||||
nix_err nix_flake_lock_flags_add_input_override(
|
||||
nix_c_context * context, nix_flake_lock_flags * flags, const char * inputPath, nix_flake_reference * flakeRef)
|
||||
{
|
||||
nix_clear_err(context);
|
||||
try {
|
||||
auto path = nix::flake::parseInputAttrPath(inputPath);
|
||||
flags->lockFlags->inputOverrides.emplace(path, *flakeRef->flakeRef);
|
||||
if (flags->lockFlags->writeLockFile) {
|
||||
return nix_flake_lock_flags_set_mode_virtual(context, flags);
|
||||
}
|
||||
}
|
||||
NIXC_CATCH_ERRS
|
||||
}
|
||||
|
||||
nix_locked_flake * nix_flake_lock(
|
||||
nix_c_context * context,
|
||||
nix_flake_settings * settings,
|
||||
nix_fetchers_settings * fetchSettings,
|
||||
nix_flake_settings * flakeSettings,
|
||||
EvalState * eval_state,
|
||||
nix_flake_lock_flags * flags,
|
||||
nix_flake_reference * flakeReference)
|
||||
{
|
||||
nix_clear_err(context);
|
||||
try {
|
||||
auto lockedFlake = nix::make_ref<nix::flake::LockedFlake>(nix::flake::lockFlake(
|
||||
*settings->settings, eval_state->state, *flakeReference->flakeRef, *flags->lockFlags));
|
||||
*flakeSettings->settings, eval_state->state, *flakeReference->flakeRef, *flags->lockFlags));
|
||||
return new nix_locked_flake{lockedFlake};
|
||||
}
|
||||
NIXC_CATCH_ERRS_NULL
|
||||
|
|
|
@ -126,6 +126,49 @@ nix_flake_lock_flags * nix_flake_lock_flags_new(nix_c_context * context, nix_fla
|
|||
*/
|
||||
void nix_flake_lock_flags_free(nix_flake_lock_flags * settings);
|
||||
|
||||
/**
|
||||
* @brief Put the lock flags in a mode that checks whether the lock is up to date.
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] flags The flags to modify
|
||||
* @return NIX_OK on success, NIX_ERR on failure
|
||||
*
|
||||
* This causes `nix_flake_lock` to fail if the lock needs to be updated.
|
||||
*/
|
||||
nix_err nix_flake_lock_flags_set_mode_check(nix_c_context * context, nix_flake_lock_flags * flags);
|
||||
|
||||
/**
|
||||
* @brief Put the lock flags in a mode that updates the lock file in memory, if needed.
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] flags The flags to modify
|
||||
* @param[in] update Whether to allow updates
|
||||
*
|
||||
* This will cause `nix_flake_lock` to update the lock file in memory, if needed.
|
||||
*/
|
||||
nix_err nix_flake_lock_flags_set_mode_virtual(nix_c_context * context, nix_flake_lock_flags * flags);
|
||||
|
||||
/**
|
||||
* @brief Put the lock flags in a mode that updates the lock file on disk, if needed.
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] flags The flags to modify
|
||||
* @param[in] update Whether to allow updates
|
||||
*
|
||||
* This will cause `nix_flake_lock` to update the lock file on disk, if needed.
|
||||
*/
|
||||
nix_err nix_flake_lock_flags_set_mode_write_as_needed(nix_c_context * context, nix_flake_lock_flags * flags);
|
||||
|
||||
/**
|
||||
* @brief Add input overrides to the lock flags
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] flags The flags to modify
|
||||
* @param[in] inputPath The input path to override
|
||||
* @param[in] flakeRef The flake reference to use as the override
|
||||
*
|
||||
* This switches the `flags` to `nix_flake_lock_flags_set_mode_virtual` if not in mode
|
||||
* `nix_flake_lock_flags_set_mode_check`.
|
||||
*/
|
||||
nix_err nix_flake_lock_flags_add_input_override(
|
||||
nix_c_context * context, nix_flake_lock_flags * flags, const char * inputPath, nix_flake_reference * flakeRef);
|
||||
|
||||
/**
|
||||
* @brief Lock a flake, if not already locked.
|
||||
* @param[out] context Optional, stores error information
|
||||
|
@ -135,6 +178,7 @@ void nix_flake_lock_flags_free(nix_flake_lock_flags * settings);
|
|||
*/
|
||||
nix_locked_flake * nix_flake_lock(
|
||||
nix_c_context * context,
|
||||
nix_fetchers_settings * fetchSettings,
|
||||
nix_flake_settings * settings,
|
||||
EvalState * eval_state,
|
||||
nix_flake_lock_flags * flags,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue