Skip to main content

entrenar/sovereign/nix/
system.rs

1//! Target system for Nix builds
2
3use serde::{Deserialize, Serialize};
4
5/// Target system for Nix builds
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
7pub enum NixSystem {
8    /// x86_64 Linux
9    X86_64Linux,
10    /// aarch64 Linux
11    Aarch64Linux,
12    /// x86_64 macOS
13    X86_64Darwin,
14    /// aarch64 macOS (Apple Silicon)
15    Aarch64Darwin,
16}
17
18impl NixSystem {
19    /// Get the Nix system string
20    pub fn as_str(&self) -> &'static str {
21        match self {
22            Self::X86_64Linux => "x86_64-linux",
23            Self::Aarch64Linux => "aarch64-linux",
24            Self::X86_64Darwin => "x86_64-darwin",
25            Self::Aarch64Darwin => "aarch64-darwin",
26        }
27    }
28
29    /// Get all supported systems
30    pub fn all() -> Vec<Self> {
31        vec![Self::X86_64Linux, Self::Aarch64Linux, Self::X86_64Darwin, Self::Aarch64Darwin]
32    }
33
34    /// Get Linux systems only
35    pub fn linux_only() -> Vec<Self> {
36        vec![Self::X86_64Linux, Self::Aarch64Linux]
37    }
38}
39
40impl std::fmt::Display for NixSystem {
41    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42        write!(f, "{}", self.as_str())
43    }
44}