Skip to main content

sui_cache/
lib.rs

1//! Built-in binary cache server and push pipeline for sui.
2//!
3//! Replaces Attic, Cachix, and nix-serve with a single integrated component.
4//! Implements the standard Nix binary cache HTTP protocol (narinfo + NAR).
5//!
6//! # Architecture
7//!
8//! - [`storage`] — pluggable storage backends (local filesystem, S3 stub)
9//! - [`server`] — axum HTTP server implementing the cache protocol
10//! - [`signing`] — ed25519 key management and narinfo signing
11//! - [`push`] — pipeline to push store paths to the cache
12//! - [`gc`] — garbage collection of unreferenced cache entries
13//! - [`config`] — cache configuration types
14
15pub mod config;
16pub mod gc;
17pub mod push;
18pub mod server;
19pub mod signing;
20pub mod storage;
21
22pub use config::{BackendConfig, CacheConfig};
23pub use gc::GcResult;
24pub use push::PushResult;
25pub use server::{build_router, serve, AppState};
26pub use signing::{verify_narinfo_signature, CacheSigner};
27pub use storage::{LocalStorage, S3Storage, StorageBackend, StorageIndex};
28
29/// Errors from cache operations.
30#[derive(Debug, thiserror::Error)]
31pub enum CacheError {
32    /// An I/O operation failed.
33    #[error("io error: {0}")]
34    Io(#[from] std::io::Error),
35
36    /// A store path was not found on the local filesystem.
37    #[error("path not found: {0}")]
38    PathNotFound(String),
39
40    /// A signing or verification operation failed.
41    #[error("signing error: {0}")]
42    Signing(String),
43
44    /// A feature is not yet implemented.
45    #[error("not implemented: {0}")]
46    NotImplemented(&'static str),
47
48    /// A narinfo could not be parsed.
49    #[error("narinfo error: {0}")]
50    NarInfo(String),
51}
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn cache_error_display() {
59        let e = CacheError::PathNotFound("/nix/store/abc".to_string());
60        assert!(format!("{e}").contains("/nix/store/abc"));
61    }
62
63    #[test]
64    fn cache_error_io_display() {
65        let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "missing");
66        let e = CacheError::Io(io_err);
67        assert!(format!("{e}").contains("missing"));
68    }
69
70    #[test]
71    fn cache_error_signing_display() {
72        let e = CacheError::Signing("bad key".to_string());
73        assert!(format!("{e}").contains("bad key"));
74    }
75
76    #[test]
77    fn cache_error_not_implemented_display() {
78        let e = CacheError::NotImplemented("S3");
79        assert!(format!("{e}").contains("S3"));
80    }
81
82    #[test]
83    fn cache_error_narinfo_display() {
84        let e = CacheError::NarInfo("parse failed".to_string());
85        assert!(format!("{e}").contains("parse failed"));
86    }
87}