Skip to main content

snix_store/nar/
mod.rs

1use auto_impl::auto_impl;
2use snix_castore::B3Digest;
3use snix_castore::Node;
4use snix_castore::directoryservice::OrderingError;
5use tonic::async_trait;
6
7mod hashing_reader;
8mod import;
9mod listing;
10mod renderer;
11pub mod seekable;
12
13pub use import::{NarIngestionError, ingest_nar, ingest_nar_and_hash};
14pub use listing::{Error as ListingError, produce_listing};
15pub use renderer::SimpleRenderer;
16pub use renderer::calculate_size_and_sha256;
17pub use renderer::write_nar;
18
19use crate::pathinfoservice;
20
21#[async_trait]
22#[auto_impl(&, &mut, Arc, Box)]
23pub trait NarCalculationService: Send + Sync {
24    /// Return the nar size and nar sha256 digest for a given root node.
25    /// This can be used to calculate NAR-based output paths.
26    async fn calculate_nar(
27        &self,
28        root_node: &Node,
29    ) -> Result<(u64, [u8; 32]), pathinfoservice::Error>;
30}
31
32/// Errors that can encounter while rendering NARs.
33#[derive(Debug, thiserror::Error)]
34pub enum RenderError {
35    #[error("failure talking to a backing directory service")]
36    DirectoryService(#[source] snix_castore::directoryservice::Error),
37
38    #[error("failure talking to a backing blob service")]
39    BlobService(#[source] std::io::Error),
40
41    #[error("unable to find directory {0}, referred from {1:?}")]
42    DirectoryNotFound(B3Digest, bytes::Bytes),
43
44    #[error("Invalid Ordering")]
45    OrderingError(#[source] OrderingError),
46
47    #[error("unable to find blob {0}, referred from {1:?}")]
48    BlobNotFound(B3Digest, bytes::Bytes),
49
50    #[error(
51        "unexpected size in metadata for blob {0}, referred from {1:?} returned, expected {2}, got {3}"
52    )]
53    UnexpectedBlobMeta(B3Digest, bytes::Bytes, u32, u32),
54
55    #[error("failure using the NAR writer: {0}")]
56    NARWriterError(std::io::Error),
57}