diff --git a/rust/Cargo.lock b/rust/Cargo.lock index eaa0409..5368463 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -323,6 +323,19 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nix-fetchers" +version = "0.1.0" +dependencies = [ + "anyhow", + "cstr", + "ctor", + "nix-c-raw", + "nix-store", + "nix-util", + "tempfile", +] + [[package]] name = "nix-flake" version = "0.1.0" @@ -333,6 +346,7 @@ dependencies = [ "lazy_static", "nix-c-raw", "nix-expr", + "nix-fetchers", "nix-store", "nix-util", "tempfile", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index d234fbd..f71d8a8 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,9 +1,10 @@ [workspace] members = [ "nix-c-raw", - "nix-flake", "nix-expr", - "nix-util", + "nix-fetchers", + "nix-flake", "nix-store", + "nix-util", ] resolver = "2" diff --git a/rust/nix-fetchers/Cargo.toml b/rust/nix-fetchers/Cargo.toml new file mode 100644 index 0000000..31d12c5 --- /dev/null +++ b/rust/nix-fetchers/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "nix-fetchers" +version = "0.1.0" +edition = "2021" +license = "LGPL-2.1" + +[lib] +path = "src/lib.rs" + +[dependencies] +anyhow = "1.0.79" +nix-store = { path = "../nix-store" } +nix-util = { path = "../nix-util" } +nix-c-raw = { path = "../nix-c-raw" } +ctor = "0.2.7" +tempfile = "3.10.1" +cstr = "0.2.12" diff --git a/rust/nix-fetchers/src/lib.rs b/rust/nix-fetchers/src/lib.rs new file mode 100644 index 0000000..091830c --- /dev/null +++ b/rust/nix-fetchers/src/lib.rs @@ -0,0 +1,38 @@ +use anyhow::{Context as _, Result}; +use nix_c_raw as raw; +use nix_util::context::{self, Context}; +use std::ptr::NonNull; + +pub struct FetchersSettings { + pub(crate) ptr: NonNull, +} +impl Drop for FetchersSettings { + fn drop(&mut self) { + unsafe { + raw::fetchers_settings_free(self.ptr.as_ptr()); + } + } +} +impl FetchersSettings { + pub fn new() -> Result { + let mut ctx = Context::new(); + let ptr = unsafe { context::check_call!(raw::fetchers_settings_new(&mut ctx))? }; + Ok(FetchersSettings { + ptr: NonNull::new(ptr).context("fetchers_settings_new unexpectedly returned null")?, + }) + } + + pub fn raw_ptr(&self) -> *mut raw::fetchers_settings { + self.ptr.as_ptr() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn fetchers_settings_new() { + let _ = FetchersSettings::new().unwrap(); + } +} diff --git a/rust/nix-flake/Cargo.toml b/rust/nix-flake/Cargo.toml index 5b7f2d4..0121902 100644 --- a/rust/nix-flake/Cargo.toml +++ b/rust/nix-flake/Cargo.toml @@ -10,6 +10,7 @@ path = "src/lib.rs" [dependencies] anyhow = "1.0.79" nix-expr = { path = "../nix-expr" } +nix-fetchers = { path = "../nix-fetchers" } nix-store = { path = "../nix-store" } nix-util = { path = "../nix-util" } nix-c-raw = { path = "../nix-c-raw" }