support nix_fetchers_settings extensions
This commit is contained in:
parent
38a8128d32
commit
63996c3579
1 changed files with 162 additions and 10 deletions
|
|
@ -2,6 +2,7 @@ use std::ptr::NonNull;
|
||||||
|
|
||||||
use crate::NixideResult;
|
use crate::NixideResult;
|
||||||
use crate::errors::ErrorContext;
|
use crate::errors::ErrorContext;
|
||||||
|
use crate::stdext::AsCPtr as _;
|
||||||
use crate::sys;
|
use crate::sys;
|
||||||
use crate::util::wrap;
|
use crate::util::wrap;
|
||||||
use crate::util::wrappers::AsInnerPtr;
|
use crate::util::wrappers::AsInnerPtr;
|
||||||
|
|
@ -10,16 +11,6 @@ pub struct FetchersSettings {
|
||||||
inner: NonNull<sys::NixFetchersSettings>,
|
inner: NonNull<sys::NixFetchersSettings>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FetchersSettings {
|
|
||||||
pub fn new() -> NixideResult<Self> {
|
|
||||||
let inner = wrap::nix_ptr_fn!(|ctx: &ErrorContext| unsafe {
|
|
||||||
sys::nix_fetchers_settings_new(ctx.as_ptr())
|
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok(Self { inner })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// impl Clone for FetchersSettings {
|
// impl Clone for FetchersSettings {
|
||||||
// fn clone(&self) -> Self {
|
// fn clone(&self) -> Self {
|
||||||
// wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
// wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
|
|
@ -58,6 +49,167 @@ impl AsInnerPtr<sys::NixFetchersSettings> for FetchersSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FetchersSettings {
|
||||||
|
pub fn new() -> NixideResult<Self> {
|
||||||
|
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<Self> {
|
||||||
|
// XXX: TODO: have a dedicated `self.access_tokens: HashMap<String, String>` 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<Self> {
|
||||||
|
// XXX: TODO: have a dedicated `self.access_tokens: HashMap<String, String>` 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<Self> {
|
||||||
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue