Compare commits
3 commits
eb2a5d0ec2
...
63996c3579
| Author | SHA1 | Date | |
|---|---|---|---|
| 63996c3579 | |||
| 38a8128d32 | |||
| e3c315050f |
3 changed files with 234 additions and 29 deletions
|
|
@ -5,26 +5,25 @@
|
|||
|
||||
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.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.get().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.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.get().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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<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 {
|
||||
// fn clone(&self) -> Self {
|
||||
// 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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -44,4 +45,57 @@ 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<Self> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue