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//! - [`sui_castore`] — pluggable storage backends (shared with sui-registry);
9//!   re-exported from here for backward compatibility.
10//! - [`server`] — axum HTTP server implementing the cache protocol
11//! - [`signing`] — ed25519 key management and narinfo signing
12//! - [`push`] — pipeline to push store paths to the cache
13//! - [`gc`] — garbage collection of unreferenced cache entries
14//! - [`config`] — cache configuration types (CacheConfig; BackendConfig is in sui-castore)
15
16pub mod config;
17pub mod gc;
18pub mod push;
19pub mod server;
20pub mod signing;
21
22// ---------------------------------------------------------------------------
23// Backward-compatibility re-exports from sui-castore.
24//
25// Every `sui_cache::X` path that existed before the extract-and-dominate
26// refactor continues to resolve — callers need zero changes. The canonical
27// home is now `sui_castore::X`.
28// ---------------------------------------------------------------------------
29
30/// `CacheError` is now `sui_castore::StoreError` (same variants, same derives).
31/// This type alias preserves every existing `sui_cache::CacheError` use site.
32pub use sui_castore::StoreError as CacheError;
33
34pub use config::CacheConfig;
35
36// BackendConfig lives in sui-castore; re-export at the sui-cache surface so
37// `sui_cache::BackendConfig` still resolves.
38pub use sui_castore::BackendConfig;
39
40pub use gc::GcResult;
41pub use push::PushResult;
42pub use server::{build_router, serve, AppState};
43pub use signing::{verify_narinfo_signature, CacheSigner};
44
45// Storage primitives — all moved to sui-castore, re-exported here.
46pub use sui_castore::{
47    build_backend, LocalStorage, PgCacheConn, PgStorageBackend, PgTable, RedisBackend, RedisConn,
48    S3Storage, StorageBackend, StorageIndex, TieredBackend, TieredTier, WritePolicy,
49    TIERED_BACKEND_TIER,
50};
51
52#[cfg(feature = "redis-client")]
53pub use sui_castore::RedisConnectionManager;
54
55#[cfg(feature = "postgres")]
56pub use sui_castore::SqlxPgCacheConn;
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn cache_error_is_store_error_display() {
64        let e = CacheError::PathNotFound("/nix/store/abc".to_string());
65        assert!(format!("{e}").contains("/nix/store/abc"));
66    }
67
68    #[test]
69    fn cache_error_io_display() {
70        let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "missing");
71        let e = CacheError::Io(io_err);
72        assert!(format!("{e}").contains("missing"));
73    }
74
75    #[test]
76    fn cache_error_signing_display() {
77        let e = CacheError::Signing("bad key".to_string());
78        assert!(format!("{e}").contains("bad key"));
79    }
80
81    #[test]
82    fn cache_error_not_implemented_display() {
83        let e = CacheError::NotImplemented("S3");
84        assert!(format!("{e}").contains("S3"));
85    }
86
87    #[test]
88    fn cache_error_narinfo_display() {
89        let e = CacheError::NarInfo("parse failed".to_string());
90        assert!(format!("{e}").contains("parse failed"));
91    }
92}