nix_env_manager/lib.rs
1//! Nix-Env-Manager: Nix Flakes and Attic Integration for AIVCS
2//!
3//! This crate provides the environment versioning layer for AIVCS.
4//! It interfaces with Nix Flakes for deterministic builds and
5//! Attic for binary caching.
6//!
7//! ## Layer 2 - Environment/Tooling
8//!
9//! Focus: Correct hash generation and dependency resolution.
10//!
11//! ## Features
12//!
13//! - Generate content-addressable hashes from Nix Flakes
14//! - Interact with Attic binary cache for environment storage
15//! - Hash Rust source code for logic versioning
16
17mod attic;
18mod error;
19mod flake;
20mod logic;
21
22pub use attic::{AtticClient, AtticConfig};
23pub use error::NixError;
24pub use flake::{
25 generate_environment_hash, get_flake_metadata, FlakeMetadata, HashSource, NixHash,
26};
27pub use logic::generate_logic_hash;
28
29/// Result type for nix-env-manager operations
30pub type Result<T> = std::result::Result<T, NixError>;
31
32/// Check if Nix is available on the system
33pub fn is_nix_available() -> bool {
34 std::process::Command::new("nix")
35 .arg("--version")
36 .output()
37 .map(|o| o.status.success())
38 .unwrap_or(false)
39}
40
41/// Check if Attic CLI is available
42pub fn is_attic_available() -> bool {
43 std::process::Command::new("attic")
44 .arg("--version")
45 .output()
46 .map(|o| o.status.success())
47 .unwrap_or(false)
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_nix_availability_check() {
56 // This test just verifies the function runs without panicking
57 let _ = is_nix_available();
58 }
59
60 #[test]
61 fn test_attic_availability_check() {
62 let _ = is_attic_available();
63 }
64}