snix_store/pathinfoservice/
mod.rs

1mod cache;
2mod from_addr;
3mod grpc;
4mod lru;
5mod nix_http;
6mod redb;
7mod signing_wrapper;
8
9#[cfg(any(feature = "fuse", feature = "virtiofs"))]
10mod fs;
11
12#[cfg(test)]
13mod tests;
14
15use auto_impl::auto_impl;
16use futures::stream::BoxStream;
17use snix_castore::composition::{Registry, ServiceBuilder};
18use tonic::async_trait;
19
20use crate::nar::NarCalculationService;
21pub use crate::path_info::PathInfo;
22
23pub use self::cache::{Cache as CachePathInfoService, CacheConfig as CachePathInfoServiceConfig};
24pub use self::from_addr::from_addr;
25pub use self::grpc::{GRPCPathInfoService, GRPCPathInfoServiceConfig};
26pub use self::lru::{LruPathInfoService, LruPathInfoServiceConfig};
27pub use self::nix_http::{NixHTTPPathInfoService, NixHTTPPathInfoServiceConfig};
28pub use self::redb::{RedbPathInfoService, RedbPathInfoServiceConfig};
29pub use self::signing_wrapper::{KeyFileSigningPathInfoServiceConfig, SigningPathInfoService};
30
31#[cfg(test)]
32pub(crate) use self::signing_wrapper::test_signing_service;
33
34#[cfg(feature = "cloud")]
35mod bigtable;
36#[cfg(feature = "cloud")]
37pub use self::bigtable::{BigtableParameters, BigtablePathInfoService};
38
39#[cfg(any(feature = "fuse", feature = "virtiofs"))]
40pub use self::fs::make_fs;
41
42pub type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
43
44/// The base trait all PathInfo services need to implement.
45#[async_trait]
46#[auto_impl(&, &mut, Arc, Box)]
47pub trait PathInfoService: Send + Sync {
48    /// Retrieve a PathInfo by the output digest.
49    async fn get(&self, digest: [u8; 20]) -> Result<Option<PathInfo>, Error>;
50
51    /// Check if a PathInfo exists.
52    /// Has a naïve default impl, but store implementations may decide to
53    /// implement their own.
54    async fn has(&self, digest: [u8; 20]) -> Result<bool, Error> {
55        Ok(self.get(digest).await?.is_some())
56    }
57
58    /// Store a PathInfo.
59    async fn put(&self, path_info: PathInfo) -> Result<PathInfo, Error>;
60
61    /// Iterate over all PathInfo objects in the store.
62    /// Implementations can decide to disallow listing.
63    ///
64    /// This returns a pinned, boxed stream. The pinning allows for it to be polled easily,
65    /// and the box allows different underlying stream implementations to be returned since
66    /// Rust doesn't support this as a generic in traits yet. This is the same thing that
67    /// [async_trait] generates, but for streams instead of futures.
68    fn list(&self) -> BoxStream<'static, Result<PathInfo, Error>>;
69
70    /// Returns a (more) suitable NarCalculationService.
71    /// This can be used to offload NAR calculation to the remote side.
72    fn nar_calculation_service(&self) -> Option<Box<dyn NarCalculationService>> {
73        None
74    }
75}
76
77/// Registers the builtin PathInfoService implementations with the registry
78pub(crate) fn register_pathinfo_services(reg: &mut Registry) {
79    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, CachePathInfoServiceConfig>("cache");
80    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, GRPCPathInfoServiceConfig>("grpc");
81    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, KeyFileSigningPathInfoServiceConfig>("keyfile-signing");
82    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, LruPathInfoServiceConfig>("lru");
83    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, NixHTTPPathInfoServiceConfig>("nix");
84    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, RedbPathInfoServiceConfig>("redb");
85    #[cfg(feature = "cloud")]
86    {
87        reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, BigtableParameters>(
88            "bigtable",
89        );
90    }
91}