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 std::sync::Arc;
13
14use auto_impl::auto_impl;
15use futures::stream::BoxStream;
16use snix_castore::composition::{Registry, ServiceBuilder};
17use tonic::async_trait;
18
19use crate::nar::NarCalculationService;
20pub use crate::path_info::PathInfo;
21
22pub use self::cache::{Cache as CachePathInfoService, CacheConfig as CachePathInfoServiceConfig};
23pub use self::from_addr::from_addr;
24pub use self::grpc::{GRPCPathInfoService, GRPCPathInfoServiceConfig};
25pub use self::lru::{LruPathInfoService, LruPathInfoServiceConfig};
26pub use self::nix_http::{NixHTTPPathInfoService, NixHTTPPathInfoServiceConfig};
27pub use self::redb::{RedbPathInfoService, RedbPathInfoServiceConfig};
28pub use self::signing_wrapper::{KeyFileSigningPathInfoServiceConfig, SigningPathInfoService};
29
30#[cfg(feature = "cloud")]
31mod bigtable;
32#[cfg(feature = "cloud")]
33pub use self::bigtable::{BigtableParameters, BigtablePathInfoService};
34
35#[cfg(feature = "fs")]
36mod fs;
37#[cfg(feature = "fs")]
38pub use self::fs::RootNodesWrapper;
39
40pub type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
41
42#[cfg_attr(any(test, feature = "mocks"), mockall::automock)]
44#[async_trait]
45#[auto_impl(&, &mut, Arc, Box)]
46pub trait PathInfoService: Send + Sync {
47 async fn get(&self, digest: [u8; 20]) -> Result<Option<PathInfo>, Error>;
49
50 async fn has(&self, digest: [u8; 20]) -> Result<bool, Error> {
54 Ok(self.get(digest).await?.is_some())
55 }
56
57 async fn put(&self, path_info: PathInfo) -> Result<PathInfo, Error>;
59
60 fn list(&self) -> BoxStream<'static, Result<PathInfo, Error>>;
73
74 fn nar_calculation_service(&self) -> Option<Arc<dyn NarCalculationService>> {
77 None
78 }
79}
80
81pub(crate) fn register_pathinfo_services(reg: &mut Registry) {
83 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, CachePathInfoServiceConfig>("cache");
84 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, GRPCPathInfoServiceConfig>("grpc");
85 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, KeyFileSigningPathInfoServiceConfig>("keyfile-signing");
86 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, LruPathInfoServiceConfig>("lru");
87 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, NixHTTPPathInfoServiceConfig>("nix");
88 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, RedbPathInfoServiceConfig>("redb");
89 #[cfg(feature = "cloud")]
90 {
91 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, BigtableParameters>(
92 "bigtable",
93 );
94 }
95}