add libnixide-c extensions to FlakeLockFlags
This commit is contained in:
parent
378569ff24
commit
f76658fcfb
1 changed files with 213 additions and 15 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::ffi::c_char;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
use super::{FlakeRef, FlakeSettings};
|
use super::{FlakeRef, FlakeSettings};
|
||||||
|
|
@ -77,6 +78,60 @@ impl FlakeLockFlags {
|
||||||
Ok(FlakeLockFlags { inner })
|
Ok(FlakeLockFlags { inner })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adds an input override to the lock file that will be produced.
|
||||||
|
/// The [LockedFlake::lock] operation will not write to the lock file.
|
||||||
|
///
|
||||||
|
/// # Warning
|
||||||
|
///
|
||||||
|
/// Calling this function will implicitly set the [FlakeLockMode] to
|
||||||
|
/// [FlakeLockMode::Virtual] if `self.mode` is not [FlakeLockMode::Check].
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `path` - The input name/path to override (must not be empty)
|
||||||
|
/// * `flakeref` - The flake reference to use as the override
|
||||||
|
///
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn override_input(self, input: &str, flakeref: &FlakeRef) -> NixideResult<Self> {
|
||||||
|
// XXX: TODO: should `input` be wrapped as `format!("inputs.{input}")`?
|
||||||
|
let input_path = input.as_c_ptr()?;
|
||||||
|
|
||||||
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
|
sys::nix_flake_lock_flags_add_input_override(
|
||||||
|
ctx.as_ptr(),
|
||||||
|
self.as_ptr(),
|
||||||
|
input_path,
|
||||||
|
flakeref.as_ptr(),
|
||||||
|
);
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds an input update to the lock file that will be produced.
|
||||||
|
/// Meaning the current pinned version is ignored, and updated
|
||||||
|
/// to the latest version the fetcher can resolve.
|
||||||
|
///
|
||||||
|
/// This is equivalent to running `nix flake update ${input}`.
|
||||||
|
///
|
||||||
|
/// # Nix C API Internals
|
||||||
|
///
|
||||||
|
/// This binding is **not provided by the Nix C API.**
|
||||||
|
/// It is instead **exposed by the Nixide C API extensions.**
|
||||||
|
///
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn update_input(self, input: &str) -> NixideResult<Self> {
|
||||||
|
// XXX: TODO: should `input` be wrapped as `format!("inputs.{input}")`?
|
||||||
|
let input_path = input.as_c_ptr()?;
|
||||||
|
|
||||||
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
|
sys::nix_flake_lock_flags_add_input_update(ctx.as_ptr(), self.as_ptr(), input_path);
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub fn set_mode(self, mode: FlakeLockMode) -> NixideResult<Self> {
|
pub fn set_mode(self, mode: FlakeLockMode) -> NixideResult<Self> {
|
||||||
wrap::nix_fn!(|ctx: &ErrorContext| {
|
wrap::nix_fn!(|ctx: &ErrorContext| {
|
||||||
match mode {
|
match mode {
|
||||||
|
|
@ -90,33 +145,176 @@ impl FlakeLockFlags {
|
||||||
sys::nix_flake_lock_flags_set_mode_check(ctx.as_ptr(), self.as_ptr())
|
sys::nix_flake_lock_flags_set_mode_check(ctx.as_ptr(), self.as_ptr())
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
})?;
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds an input override to the lock file that will be produced.
|
/// # Nix C API Internals
|
||||||
/// The [LockedFlake::lock] operation will not write to the lock file.
|
|
||||||
///
|
///
|
||||||
/// # Warning
|
/// This binding is **not provided by the Nix C API.**
|
||||||
|
/// It is instead **exposed by the Nixide C API extensions.**
|
||||||
///
|
///
|
||||||
/// Calling this function will implicitly set the [FlakeLockMode] to
|
#[allow(unused)]
|
||||||
/// [FlakeLockMode::Virtual] if `self.mode` is not [FlakeLockMode::Check].
|
pub fn recreate_lock_file(self, value: bool) -> Self {
|
||||||
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
|
sys::nix_flake_lock_flags_set_recreate_lock_file(ctx.as_ptr(), self.as_ptr(), value)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Nix C API Internals
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// This binding is **not provided by the Nix C API.**
|
||||||
|
/// It is instead **exposed by the Nixide C API extensions.**
|
||||||
///
|
///
|
||||||
/// * `path` - The input name/path to override (must not be empty)
|
#[allow(unused)]
|
||||||
/// * `flakeref` - The flake reference to use as the override
|
pub fn update_lock_file(self, value: bool) -> Self {
|
||||||
pub fn override_input(&mut self, path: &str, flakeref: &FlakeRef) -> NixideResult<()> {
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
let input_path = path.as_c_ptr()?;
|
sys::nix_flake_lock_flags_set_update_lock_file(ctx.as_ptr(), self.as_ptr(), value)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Nix C API Internals
|
||||||
|
///
|
||||||
|
/// This binding is **not provided by the Nix C API.**
|
||||||
|
/// It is instead **exposed by the Nixide C API extensions.**
|
||||||
|
///
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn write_lock_file(self, value: bool) -> Self {
|
||||||
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
|
sys::nix_flake_lock_flags_set_write_lock_file(ctx.as_ptr(), self.as_ptr(), value)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Nix C API Internals
|
||||||
|
///
|
||||||
|
/// This binding is **not provided by the Nix C API.**
|
||||||
|
/// It is instead **exposed by the Nixide C API extensions.**
|
||||||
|
///
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn commit_lock_file(self, value: bool) -> Self {
|
||||||
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
|
sys::nix_flake_lock_flags_set_commit_lock_file(ctx.as_ptr(), self.as_ptr(), value)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Nix C API Internals
|
||||||
|
///
|
||||||
|
/// This binding is **not provided by the Nix C API.**
|
||||||
|
/// It is instead **exposed by the Nixide C API extensions.**
|
||||||
|
///
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn allow_unlocked(self, value: bool) -> Self {
|
||||||
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
|
sys::nix_flake_lock_flags_set_allow_unlocked(ctx.as_ptr(), self.as_ptr(), value)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Nix C API Internals
|
||||||
|
///
|
||||||
|
/// This binding is **not provided by the Nix C API.**
|
||||||
|
/// It is instead **exposed by the Nixide C API extensions.**
|
||||||
|
///
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn fail_on_unlocked(self, value: bool) -> Self {
|
||||||
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
|
sys::nix_flake_lock_flags_set_fail_on_unlocked(ctx.as_ptr(), self.as_ptr(), value)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Nix C API Internals
|
||||||
|
///
|
||||||
|
/// This binding is **not provided by the Nix C API.**
|
||||||
|
/// It is instead **exposed by the Nixide C API extensions.**
|
||||||
|
///
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn use_registries(self, value: bool) -> Self {
|
||||||
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
|
sys::nix_flake_lock_flags_set_use_registries(ctx.as_ptr(), self.as_ptr(), value)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Nix C API Internals
|
||||||
|
///
|
||||||
|
/// This binding is **not provided by the Nix C API.**
|
||||||
|
/// It is instead **exposed by the Nixide C API extensions.**
|
||||||
|
///
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn apply_nix_config(self, value: bool) -> Self {
|
||||||
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
|
sys::nix_flake_lock_flags_set_apply_nix_config(ctx.as_ptr(), self.as_ptr(), value)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Fails if the given `path` contains a NUL byte.
|
||||||
|
///
|
||||||
|
/// # Nix C API Internals
|
||||||
|
///
|
||||||
|
/// This binding is **not provided by the Nix C API.**
|
||||||
|
/// It is instead **exposed by the Nixide C API extensions.**
|
||||||
|
///
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn input_lock_file_path(self, path: &str) -> NixideResult<Self> {
|
||||||
|
let path_ptr = path.as_c_ptr()? as *mut c_char;
|
||||||
|
|
||||||
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
sys::nix_flake_lock_flags_add_input_override(
|
sys::nix_flake_lock_flags_set_reference_lock_file_path(
|
||||||
ctx.as_ptr(),
|
ctx.as_ptr(),
|
||||||
self.as_ptr(),
|
self.as_ptr(),
|
||||||
input_path,
|
path_ptr,
|
||||||
flakeref.as_ptr(),
|
)
|
||||||
);
|
|
||||||
})
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Ok(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Fails if the given `path` contains a NUL byte.
|
||||||
|
///
|
||||||
|
/// # Nix C API Internals
|
||||||
|
///
|
||||||
|
/// This binding is **not provided by the Nix C API.**
|
||||||
|
/// It is instead **exposed by the Nixide C API extensions.**
|
||||||
|
///
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn output_lock_file_path(self, path: &str) -> NixideResult<Self> {
|
||||||
|
let path_ptr = path.as_c_ptr()? as *mut c_char;
|
||||||
|
|
||||||
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
|
sys::nix_flake_lock_flags_set_output_lock_file_path(
|
||||||
|
ctx.as_ptr(),
|
||||||
|
self.as_ptr(),
|
||||||
|
path_ptr,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue