snix_store/pathinfoservice/
mod.rs1mod 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#[async_trait]
46#[auto_impl(&, &mut, Arc, Box)]
47pub trait PathInfoService: Send + Sync {
48 async fn get(&self, digest: [u8; 20]) -> Result<Option<PathInfo>, Error>;
50
51 async fn has(&self, digest: [u8; 20]) -> Result<bool, Error> {
55 Ok(self.get(digest).await?.is_some())
56 }
57
58 async fn put(&self, path_info: PathInfo) -> Result<PathInfo, Error>;
60
61 fn list(&self) -> BoxStream<'static, Result<PathInfo, Error>>;
69
70 fn nar_calculation_service(&self) -> Option<Box<dyn NarCalculationService>> {
73 None
74 }
75}
76
77pub(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}