nixfleet_agent/activation/
types.rs1use std::time::Duration;
10
11use anyhow::Result;
12
13#[derive(Debug, Clone)]
23pub struct ActivationTarget {
24 pub closure_hash: String,
25 pub channel_ref: String,
26}
27
28pub const POLL_BUDGET: Duration = Duration::from_secs(300);
30pub const POLL_INTERVAL: Duration = Duration::from_secs(2);
31
32#[derive(Debug)]
33pub enum ActivationOutcome {
34 FiredAndPolled,
35 RealiseFailed {
36 reason: String,
37 },
38 SignatureMismatch {
40 closure_hash: String,
41 stderr_tail: String,
42 },
43 SwitchFailed {
44 phase: String,
45 exit_code: Option<i32>,
46 },
47 VerifyMismatch {
50 expected: String,
51 actual: String,
52 },
53 DeferredPendingReboot {
58 component: String,
59 },
60}
61
62#[derive(Debug)]
63pub enum RollbackOutcome {
64 FiredAndPolled { reverted_to_closure: String },
71 Failed {
72 phase: String,
73 exit_code: Option<i32>,
74 },
75}
76
77impl RollbackOutcome {
78 pub fn success(&self) -> bool {
79 matches!(self, RollbackOutcome::FiredAndPolled { .. })
80 }
81 pub fn exit_code(&self) -> Option<i32> {
82 match self {
83 RollbackOutcome::Failed { exit_code, .. } => *exit_code,
84 RollbackOutcome::FiredAndPolled { .. } => None,
85 }
86 }
87 pub fn phase(&self) -> Option<&str> {
88 match self {
89 RollbackOutcome::Failed { phase, .. } => Some(phase.as_str()),
90 RollbackOutcome::FiredAndPolled { .. } => None,
91 }
92 }
93}
94
95#[cfg(target_os = "macos")]
96pub use super::darwin::DarwinBackend;
97#[cfg(target_os = "linux")]
98pub use super::linux::LinuxBackend;
99
100#[cfg(target_os = "linux")]
101pub type DefaultBackend = LinuxBackend;
102#[cfg(target_os = "macos")]
103pub type DefaultBackend = DarwinBackend;
104
105#[cfg(target_os = "linux")]
106pub const DEFAULT_BACKEND: DefaultBackend = LinuxBackend;
107#[cfg(target_os = "macos")]
108pub const DEFAULT_BACKEND: DefaultBackend = DarwinBackend;
109
110pub trait ActivationBackend: Send + Sync {
111 fn is_switch_in_progress(&self) -> impl std::future::Future<Output = bool> + Send;
112 fn read_unit_exit_code(
113 &self,
114 unit_name: &str,
115 ) -> impl std::future::Future<Output = Option<i32>> + Send;
116 fn fire_switch(
117 &self,
118 target: &ActivationTarget,
119 store_path: &str,
120 ) -> impl std::future::Future<Output = Result<Option<ActivationOutcome>>> + Send;
121 fn fire_rollback(
122 &self,
123 target_basename: &str,
124 ) -> impl std::future::Future<Output = Result<Option<RollbackOutcome>>> + Send;
125}