use serde::Deserialize; use std::collections::HashMap; use std::fmt; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum SystemType { Nixos, Darwin, } impl SystemType { pub fn parse(s: &str) -> Result { match s { "nixos" => Ok(SystemType::Nixos), "darwin" => Ok(SystemType::Darwin), other => Err(format!("unsupported system type: {other}")), } } } impl fmt::Display for SystemType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { SystemType::Nixos => write!(f, "nixos"), SystemType::Darwin => write!(f, "darwin"), } } } #[derive(Debug, Clone)] pub struct JobSpec { pub hostname: String, pub system: SystemType, pub user: String, pub drv_path: String, } impl JobSpec { /// The SSH target string (`user@hostname`) for this deployment. pub fn target(&self) -> String { format!("{}@{}", self.user, self.hostname) } } /// One entry from `nix build --json`. #[derive(Debug, Clone, Deserialize)] pub struct BuildResult { pub outputs: HashMap, } /// One JSON-Lines record emitted by `nix-eval-jobs`. #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] pub struct NixEvalJobsResult { pub attr: String, pub attr_path: Option>, pub drv_path: Option, pub error: Option, pub extra_value: Option, pub outputs: Option>, pub system: Option, } #[derive(Debug, Clone, Default, Deserialize)] pub struct NodeMetadata { pub hostname: Option, pub user: Option, #[serde(rename = "type")] pub type_name: Option, }