diff --git a/nixide-sys/libnixide-c/nixide_api_fetchers.cc b/nixide-sys/libnixide-c/nixide_api_fetchers.cc index 9530fb6..6dbbd03 100644 --- a/nixide-sys/libnixide-c/nixide_api_fetchers.cc +++ b/nixide-sys/libnixide-c/nixide_api_fetchers.cc @@ -5,25 +5,26 @@ extern "C" { -nix_err nix_fetchers_settings_add_access_token( - nix_c_context * context, nix_fetchers_settings * settings, char * tokenName, char * tokenValue) -{ - nix_clear_err(context); - try { - settings->settings->accessTokens.get().emplace(std::string(tokenName), std::string(tokenValue)); - } - NIXC_CATCH_ERRS -} +// nix_err nix_fetchers_settings_add_access_token( +// nix_c_context * context, nix_fetchers_settings * settings, char * tokenName, char * tokenValue) +// { +// nix_clear_err(context); +// try { +// settings->settings->accessTokens.emplace(std::string(tokenName), std::string(tokenValue)); +// } +// NIXC_CATCH_ERRS +// } -nix_err -nix_fetchers_settings_remove_access_token(nix_c_context * context, nix_fetchers_settings * settings, char * tokenName) -{ - nix_clear_err(context); - try { - settings->settings->accessTokens.get().erase(std::string(tokenName)); - } - NIXC_CATCH_ERRS -} +// nix_err +// nix_fetchers_settings_remove_access_token(nix_c_context * context, nix_fetchers_settings * settings, char * +// tokenName) +// { +// nix_clear_err(context); +// try { +// settings->settings->accessTokens.erase(std::string(tokenName)); +// } +// NIXC_CATCH_ERRS +// } nix_err nix_fetchers_settings_set_allow_dirty(nix_c_context * context, nix_fetchers_settings * settings, bool value) { diff --git a/nixide/src/flake/fetchers_settings.rs b/nixide/src/flake/fetchers_settings.rs index dc6ed4e..5f8b31b 100644 --- a/nixide/src/flake/fetchers_settings.rs +++ b/nixide/src/flake/fetchers_settings.rs @@ -2,7 +2,6 @@ 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; @@ -11,6 +10,16 @@ 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 { @@ -49,167 +58,6 @@ 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::*; diff --git a/nixide/src/flake/flake_settings.rs b/nixide/src/flake/flake_settings.rs index 3af309a..e021f4f 100644 --- a/nixide/src/flake/flake_settings.rs +++ b/nixide/src/flake/flake_settings.rs @@ -2,7 +2,6 @@ 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; @@ -45,57 +44,4 @@ impl FlakeSettings { Ok(Self { inner }) } - - /// # 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_settings_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 accept_flake_config(self, value: bool) -> Self { - wrap::nix_fn!(|ctx: &ErrorContext| unsafe { - sys::nix_flake_settings_set_accept_flake_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 commit_lock_file_summary(self, summary: &str) -> NixideResult { - let summary_ptr = summary.into_c_ptr()?; - wrap::nix_fn!(|ctx: &ErrorContext| unsafe { - sys::nix_flake_settings_set_commit_lock_file_summary( - ctx.as_ptr(), - self.as_ptr(), - summary_ptr, - ) - }) - .unwrap(); - - Ok(self) - } }