Add integration for libnixstore
This adds a conditional feature flag for loading data from libnixstore exposed behind a feature flag dependency
This commit is contained in:
parent
6bed1a222e
commit
459ed33bdd
4 changed files with 49 additions and 2 deletions
|
@ -7,5 +7,12 @@ repository = "https://im.badat.dev/bad/narinfo-rs"
|
|||
license = "MIT OR Apache-2.0"
|
||||
keywords = ["nix", "nixos"]
|
||||
|
||||
[features]
|
||||
libnixstore = ["dep:libnixstore"]
|
||||
|
||||
[dependencies]
|
||||
derive_builder = { version = "0.11.2", default-features = false }
|
||||
libnixstore = { version = "0.2.0", optional = true }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
|
10
shell.nix
Normal file
10
shell.nix
Normal file
|
@ -0,0 +1,10 @@
|
|||
with import <nixpkgs> { };
|
||||
mkShell {
|
||||
nativeBuildInputs = [
|
||||
nix
|
||||
nlohmann_json
|
||||
libsodium
|
||||
boost
|
||||
pkg-config
|
||||
];
|
||||
}
|
|
@ -6,10 +6,13 @@ extern crate alloc;
|
|||
|
||||
pub mod error;
|
||||
|
||||
mod narinfo;
|
||||
mod nix_cache_info;
|
||||
pub mod narinfo;
|
||||
pub mod nix_cache_info;
|
||||
mod sig;
|
||||
|
||||
#[cfg(feature = "libnixstore")]
|
||||
mod libnixstore;
|
||||
|
||||
pub use crate::narinfo::NarInfo;
|
||||
pub use nix_cache_info::NixCacheInfo;
|
||||
pub use sig::Sig;
|
||||
|
|
27
src/libnixstore.rs
Normal file
27
src/libnixstore.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
use crate::narinfo::NarInfoBuilder;
|
||||
use crate::Sig;
|
||||
use alloc::borrow::Cow;
|
||||
|
||||
impl<'a> NarInfoBuilder<'a> {
|
||||
/// Read and set the store dir from [`libnixstore`].
|
||||
///
|
||||
/// This function assumes that [`libnixstore::init`] has already been called
|
||||
pub fn store_dir_from_libnixstore(&mut self) -> &Self {
|
||||
let store_dir = libnixstore::get_store_dir();
|
||||
self.store_path(Cow::Owned(store_dir));
|
||||
self
|
||||
}
|
||||
|
||||
/// Read and set `path`, `references` and `sigs` from a [`libnixstore::PathInfo`]
|
||||
pub fn attr_from_libnixstore_path(&mut self, path: &'a libnixstore::PathInfo) -> &Self {
|
||||
self.file_size(Some(path.size));
|
||||
self.references(path.refs.iter().map(Cow::from).collect());
|
||||
self.sigs(
|
||||
path.sigs
|
||||
.iter()
|
||||
.map(|v| Sig::parse(v).expect("libnixstore provided signature should be in a valid format"))
|
||||
.collect());
|
||||
|
||||
self
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue