snix_store/nar/
mod.rs

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