diff --git a/nixide/src/flake/flake_lock_flags.rs b/nixide/src/flake/flake_lock_flags.rs index 9f5427d..e9b1320 100644 --- a/nixide/src/flake/flake_lock_flags.rs +++ b/nixide/src/flake/flake_lock_flags.rs @@ -1,3 +1,4 @@ +use std::ffi::c_char; use std::ptr::NonNull; use super::{FlakeRef, FlakeSettings}; @@ -77,6 +78,60 @@ impl FlakeLockFlags { 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 { + // 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 { + // 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 { wrap::nix_fn!(|ctx: &ErrorContext| { match mode { @@ -90,33 +145,176 @@ impl FlakeLockFlags { sys::nix_flake_lock_flags_set_mode_check(ctx.as_ptr(), self.as_ptr()) }, }; - }); + })?; Ok(self) } - /// Adds an input override to the lock file that will be produced. - /// The [LockedFlake::lock] operation will not write to the lock file. + /// # Nix C API Internals /// - /// # 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 - /// [FlakeLockMode::Virtual] if `self.mode` is not [FlakeLockMode::Check]. + #[allow(unused)] + 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) - /// * `flakeref` - The flake reference to use as the override - pub fn override_input(&mut self, path: &str, flakeref: &FlakeRef) -> NixideResult<()> { - let input_path = path.as_c_ptr()?; + #[allow(unused)] + pub fn update_lock_file(self, value: bool) -> Self { + wrap::nix_fn!(|ctx: &ErrorContext| unsafe { + 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 { + let path_ptr = path.as_c_ptr()? as *mut c_char; 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(), self.as_ptr(), - input_path, - flakeref.as_ptr(), - ); + path_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 { + 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) } }