narinfo-rs/src/narinfo/mod.rs

68 lines
2.2 KiB
Rust

mod from_str;
mod to_str;
use crate::sig::Sig;
use alloc::{borrow::Cow, vec::Vec};
pub use from_str::*;
pub use to_str::*;
use derive_builder::Builder;
type FileSize = usize;
/// Struct representing the narinfo file fetched from a nix substituter
/// Based on the [unofficial spec](https://fzakaria.github.io/nix-http-binary-cache-api-spec)
/// and the [libstore narinfo parsing code.](https://github.com/NixOS/nix/blob/6776e65fd960e25b55d11a03324f9007b6dc2a0b/src/libstore/nar-info.cc)
#[derive(Builder, Eq, PartialEq, Debug)]
#[builder(no_std)]
#[builder(build_fn(error = "crate::error::ParsingError<'static>"))]
pub struct NarInfo<'a> {
/// The full store path, including the name part (e.g., glibc-2.7). It must match the requested store path.
pub store_path: Cow<'a, str>,
/// The URL of the NAR, relative to the binary cache URL.
pub url: &'a str,
/// The compression method; Usuall xz or bzip2.
#[builder(default)]
pub compression: Option<Cow<'a, str>>,
/// The cryptographic hash of the NAR (decompressed) in base 32.
pub nar_hash: Cow<'a, str>,
/// The size of the decompressed NAR file.
pub nar_size: FileSize,
/// The cryptographic hash of the file to download in base32.
#[builder(default)]
pub file_hash: Option<&'a str>,
/// The size of the downloaded(compressed) NAR file.
#[builder(default)]
pub file_size: Option<FileSize>,
/// The deriver of the store path, without the Nix store prefix. This field is optional.
#[builder(default)]
pub deriver: Option<Cow<'a, str>>,
/// The Nix platform type of this binary(eg. x86_64-linux).
#[builder(default)]
pub system: Option<Cow<'a, str>>,
/// Store paths for direct runtime dependencies.
#[builder(default)]
pub references: Vec<Cow<'a, str>>,
/// A collection of the signatures signing this package.
#[builder(default)]
pub sigs: Vec<Sig<'a>>,
}
impl<'a> NarInfo<'a> {
/// Get the builder for this struct.
/// The builder is generated by [derive_builder](https://lib.rs/crates/derive_builder)
// The builder is is used internally by the parsing code so we might as well expose it.
// If we ever decide to not use derive_builder we can simply hide it behind an optional feature flag
pub fn builder() -> NarInfoBuilder<'a> {
NarInfoBuilder::default()
}
}