From 63996c3579868710808e3f51abc0cdd71ab1350a Mon Sep 17 00:00:00 2001 From: _cry64 Date: Fri, 10 Apr 2026 12:56:04 +1000 Subject: [PATCH] support nix_fetchers_settings extensions --- nixide/src/flake/fetchers_settings.rs | 172 ++++++++++++++++++++++++-- 1 file changed, 162 insertions(+), 10 deletions(-) diff --git a/nixide/src/flake/fetchers_settings.rs b/nixide/src/flake/fetchers_settings.rs index 5f8b31b..dc6ed4e 100644 --- a/nixide/src/flake/fetchers_settings.rs +++ b/nixide/src/flake/fetchers_settings.rs @@ -2,6 +2,7 @@ use std::ptr::NonNull; use crate::NixideResult; use crate::errors::ErrorContext; +use crate::stdext::AsCPtr as _; use crate::sys; use crate::util::wrap; use crate::util::wrappers::AsInnerPtr; @@ -10,16 +11,6 @@ pub struct FetchersSettings { inner: NonNull, } -impl FetchersSettings { - pub fn new() -> NixideResult { - let inner = wrap::nix_ptr_fn!(|ctx: &ErrorContext| unsafe { - sys::nix_fetchers_settings_new(ctx.as_ptr()) - })?; - - Ok(Self { inner }) - } -} - // impl Clone for FetchersSettings { // fn clone(&self) -> Self { // wrap::nix_fn!(|ctx: &ErrorContext| unsafe { @@ -58,6 +49,167 @@ impl AsInnerPtr for FetchersSettings { } } +impl FetchersSettings { + pub fn new() -> NixideResult { + let inner = wrap::nix_ptr_fn!(|ctx: &ErrorContext| unsafe { + sys::nix_fetchers_settings_new(ctx.as_ptr()) + })?; + + Ok(Self { inner }) + } + + /// # Errors + /// Fails if the given `token_name` or `token_value` contain 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 add_access_token(self, token_name: &str, token_value: &str) -> NixideResult { + // XXX: TODO: have a dedicated `self.access_tokens: HashMap` instead + let name_ptr = token_name.into_c_ptr()?; + let value_ptr = token_value.into_c_ptr()?; + + wrap::nix_fn!(|ctx: &ErrorContext| unsafe { + sys::nix_fetchers_settings_add_access_token( + ctx.as_ptr(), + self.as_ptr(), + name_ptr, + value_ptr, + ); + }) + .unwrap(); + + Ok(self) + } + + /// # Errors + /// Fails if the given `token_name` or `token_value` contain 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 remove_access_token(self, token_name: &str) -> NixideResult { + // XXX: TODO: have a dedicated `self.access_tokens: HashMap` instead + let name_ptr = token_name.into_c_ptr()?; + + wrap::nix_fn!(|ctx: &ErrorContext| unsafe { + sys::nix_fetchers_settings_remove_access_token(ctx.as_ptr(), self.as_ptr(), name_ptr); + }) + .unwrap(); + + Ok(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_dirty(self, value: bool) -> Self { + wrap::nix_fn!(|ctx: &ErrorContext| unsafe { + sys::nix_fetchers_settings_set_allow_dirty(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 warn_dirty(self, value: bool) -> Self { + wrap::nix_fn!(|ctx: &ErrorContext| unsafe { + sys::nix_fetchers_settings_set_warn_dirty(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_dirty_locks(self, value: bool) -> Self { + wrap::nix_fn!(|ctx: &ErrorContext| unsafe { + sys::nix_fetchers_settings_set_allow_dirty_locks(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 trust_tarballs_from_git_forges(self, value: bool) -> Self { + wrap::nix_fn!(|ctx: &ErrorContext| unsafe { + sys::nix_fetchers_settings_set_trust_tarballs_from_git_forges( + 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 tarball_ttl(self, ttl: u32) -> Self { + wrap::nix_fn!(|ctx: &ErrorContext| unsafe { + sys::nix_fetchers_settings_set_tarball_ttl(ctx.as_ptr(), self.as_ptr(), ttl); + }) + .unwrap(); + + self + } + + /// # Errors + /// Fails if the given `registry` 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 global_flake_registry(self, registry: &str) -> NixideResult { + let registry_ptr = registry.into_c_ptr()?; + + wrap::nix_fn!(|ctx: &ErrorContext| unsafe { + sys::nix_fetchers_settings_set_global_flake_registry( + ctx.as_ptr(), + self.as_ptr(), + registry_ptr, + ); + }) + .unwrap(); + + Ok(self) + } +} + #[cfg(test)] mod tests { use super::*;