snix_store/pathinfoservice/
mod.rs1mod cache;
2mod from_addr;
3mod grpc;
4mod lru;
5mod nix_http;
6mod redb;
7mod signing_wrapper;
8
9#[cfg(test)]
10mod tests;
11
12use auto_impl::auto_impl;
13use futures::stream::BoxStream;
14use snix_castore::composition::{Registry, ServiceBuilder};
15use tonic::async_trait;
16
17use crate::nar::NarCalculationService;
18pub use crate::path_info::PathInfo;
19
20pub use self::cache::{Cache as CachePathInfoService, CacheConfig as CachePathInfoServiceConfig};
21pub use self::from_addr::from_addr;
22pub use self::grpc::{GRPCPathInfoService, GRPCPathInfoServiceConfig};
23pub use self::lru::{LruPathInfoService, LruPathInfoServiceConfig};
24pub use self::nix_http::{NixHTTPPathInfoService, NixHTTPPathInfoServiceConfig};
25pub use self::redb::{RedbPathInfoService, RedbPathInfoServiceConfig};
26pub use self::signing_wrapper::{KeyFileSigningPathInfoServiceConfig, SigningPathInfoService};
27
28#[cfg(test)]
29pub(crate) use self::signing_wrapper::test_signing_service;
30
31#[cfg(feature = "cloud")]
32mod bigtable;
33#[cfg(feature = "cloud")]
34pub use self::bigtable::{BigtableParameters, BigtablePathInfoService};
35
36#[cfg(any(feature = "fuse", feature = "virtiofs"))]
37mod fs;
38
39#[cfg(any(feature = "fuse", feature = "virtiofs"))]
40pub use self::fs::RootNodesWrapper;
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>>;
74
75 fn nar_calculation_service(&self) -> Option<Box<dyn NarCalculationService>> {
78 None
79 }
80}
81
82pub(crate) fn register_pathinfo_services(reg: &mut Registry) {
84 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, CachePathInfoServiceConfig>("cache");
85 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, GRPCPathInfoServiceConfig>("grpc");
86 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, KeyFileSigningPathInfoServiceConfig>("keyfile-signing");
87 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, LruPathInfoServiceConfig>("lru");
88 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, NixHTTPPathInfoServiceConfig>("nix");
89 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, RedbPathInfoServiceConfig>("redb");
90 #[cfg(feature = "cloud")]
91 {
92 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, BigtableParameters>(
93 "bigtable",
94 );
95 }
96}