feat: nix-fetchers crate
(cherry picked from commit 27d572403ac98d83d652481da6c22ad50bb00168)
This commit is contained in:
parent
7ae38f296f
commit
bbf245ef1a
5 changed files with 73 additions and 2 deletions
14
rust/Cargo.lock
generated
14
rust/Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
17
rust/nix-fetchers/Cargo.toml
Normal file
17
rust/nix-fetchers/Cargo.toml
Normal file
|
|
@ -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"
|
||||
38
rust/nix-fetchers/src/lib.rs
Normal file
38
rust/nix-fetchers/src/lib.rs
Normal file
|
|
@ -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<raw::fetchers_settings>,
|
||||
}
|
||||
impl Drop for FetchersSettings {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
raw::fetchers_settings_free(self.ptr.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
impl FetchersSettings {
|
||||
pub fn new() -> Result<Self> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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" }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue