diff --git a/src/action/common/configure_enterprise_edition_init_service.rs b/src/action/common/configure_enterprise_edition_init_service.rs index beb81fe39..53b7cc6f5 100644 --- a/src/action/common/configure_enterprise_edition_init_service.rs +++ b/src/action/common/configure_enterprise_edition_init_service.rs @@ -1,8 +1,6 @@ use std::path::PathBuf; -#[cfg(target_os = "macos")] use serde::{Deserialize, Serialize}; -#[cfg(target_os = "macos")] use tokio::io::AsyncWriteExt; use tokio::process::Command; use tracing::{span, Span}; @@ -12,12 +10,9 @@ use crate::execute_command; use crate::action::{Action, ActionDescription}; -#[cfg(target_os = "macos")] const DARWIN_ENTERPRISE_EDITION_DAEMON_DEST: &str = "/Library/LaunchDaemons/systems.determinate.nix-daemon.plist"; -#[cfg(target_os = "macos")] const DARWIN_LAUNCHD_DOMAIN: &str = "system"; -#[cfg(target_os = "macos")] const DARWIN_LAUNCHD_SERVICE: &str = "systems.determinate.nix-daemon"; /** Configure the init to run the Nix daemon @@ -156,7 +151,6 @@ impl Action for ConfigureEnterpriseEditionInitService { #[derive(Debug, thiserror::Error)] pub enum ConfigureEnterpriseEditionNixDaemonServiceError {} -#[cfg(target_os = "macos")] #[derive(Deserialize, Clone, Debug, Serialize, PartialEq)] #[serde(rename_all = "PascalCase")] pub struct DeterminateNixDaemonPlist { @@ -169,14 +163,12 @@ pub struct DeterminateNixDaemonPlist { soft_resource_limits: ResourceLimits, } -#[cfg(target_os = "macos")] #[derive(Deserialize, Clone, Debug, Serialize, PartialEq)] #[serde(rename_all = "PascalCase")] pub struct ResourceLimits { number_of_files: usize, } -#[cfg(target_os = "macos")] fn generate_plist() -> DeterminateNixDaemonPlist { DeterminateNixDaemonPlist { keep_alive: true, diff --git a/src/action/common/configure_init_service.rs b/src/action/common/configure_init_service.rs index 6d2d7a2b3..7bce092f7 100644 --- a/src/action/common/configure_init_service.rs +++ b/src/action/common/configure_init_service.rs @@ -1,8 +1,6 @@ -#[cfg(target_os = "linux")] use std::path::Path; use std::path::PathBuf; -#[cfg(target_os = "macos")] use serde::{Deserialize, Serialize}; use tokio::process::Command; use tracing::{span, Span}; @@ -13,26 +11,16 @@ use crate::execute_command; use crate::action::{Action, ActionDescription}; use crate::settings::InitSystem; -#[cfg(target_os = "linux")] const SERVICE_SRC: &str = "/nix/var/nix/profiles/default/lib/systemd/system/nix-daemon.service"; -#[cfg(target_os = "linux")] const SERVICE_DEST: &str = "/etc/systemd/system/nix-daemon.service"; -#[cfg(target_os = "linux")] const SOCKET_SRC: &str = "/nix/var/nix/profiles/default/lib/systemd/system/nix-daemon.socket"; -#[cfg(target_os = "linux")] const SOCKET_DEST: &str = "/etc/systemd/system/nix-daemon.socket"; -#[cfg(target_os = "linux")] const TMPFILES_SRC: &str = "/nix/var/nix/profiles/default/lib/tmpfiles.d/nix-daemon.conf"; -#[cfg(target_os = "linux")] const TMPFILES_DEST: &str = "/etc/tmpfiles.d/nix-daemon.conf"; -#[cfg(target_os = "macos")] const DARWIN_NIX_DAEMON_DEST: &str = "/Library/LaunchDaemons/org.nixos.nix-daemon.plist"; -#[cfg(target_os = "macos")] const DARWIN_NIX_DAEMON_SOURCE: &str = "/nix/var/nix/profiles/default/Library/LaunchDaemons/org.nixos.nix-daemon.plist"; -#[cfg(target_os = "macos")] const DARWIN_LAUNCHD_DOMAIN: &str = "system"; -#[cfg(target_os = "macos")] const DARWIN_LAUNCHD_SERVICE: &str = "org.nixos.nix-daemon"; /** Configure the init to run the Nix daemon @@ -44,7 +32,6 @@ pub struct ConfigureInitService { } impl ConfigureInitService { - #[cfg(target_os = "linux")] async fn check_if_systemd_unit_exists(src: &str, dest: &str) -> Result<(), ActionErrorKind> { // TODO: once we have a way to communicate interaction between the library and the cli, // interactively ask for permission to remove the file @@ -80,11 +67,9 @@ impl ConfigureInitService { start_daemon: bool, ) -> Result, ActionError> { match init { - #[cfg(target_os = "macos")] InitSystem::Launchd => { // No plan checks, yet }, - #[cfg(target_os = "linux")] InitSystem::Systemd => { // If `no_start_daemon` is set, then we don't require a running systemd, // so we don't need to check if `/run/systemd/system` exists. @@ -107,7 +92,6 @@ impl ConfigureInitService { .await .map_err(Self::error)?; }, - #[cfg(target_os = "linux")] InitSystem::None => { // Nothing here, no init system }, @@ -125,13 +109,10 @@ impl Action for ConfigureInitService { } fn tracing_synopsis(&self) -> String { match self.init { - #[cfg(target_os = "linux")] InitSystem::Systemd => "Configure Nix daemon related settings with systemd".to_string(), - #[cfg(target_os = "macos")] InitSystem::Launchd => { "Configure Nix daemon related settings with launchctl".to_string() }, - #[cfg(not(target_os = "macos"))] InitSystem::None => "Leave the Nix daemon unconfigured".to_string(), } } @@ -143,7 +124,6 @@ impl Action for ConfigureInitService { fn execute_description(&self) -> Vec { let mut vec = Vec::new(); match self.init { - #[cfg(target_os = "linux")] InitSystem::Systemd => { let mut explanation = vec![ "Run `systemd-tmpfiles --create --prefix=/nix/var/nix`".to_string(), @@ -156,7 +136,6 @@ impl Action for ConfigureInitService { } vec.push(ActionDescription::new(self.tracing_synopsis(), explanation)) }, - #[cfg(target_os = "macos")] InitSystem::Launchd => { let mut explanation = vec![format!( "Copy `{DARWIN_NIX_DAEMON_SOURCE}` to `{DARWIN_NIX_DAEMON_DEST}`" @@ -168,7 +147,6 @@ impl Action for ConfigureInitService { } vec.push(ActionDescription::new(self.tracing_synopsis(), explanation)) }, - #[cfg(not(target_os = "macos"))] InitSystem::None => (), } vec @@ -179,7 +157,6 @@ impl Action for ConfigureInitService { let Self { init, start_daemon } = self; match init { - #[cfg(target_os = "macos")] InitSystem::Launchd => { let daemon_file = DARWIN_NIX_DAEMON_DEST; let domain = DARWIN_LAUNCHD_DOMAIN; @@ -232,7 +209,6 @@ impl Action for ConfigureInitService { .map_err(Self::error)?; } }, - #[cfg(target_os = "linux")] InitSystem::Systemd => { if *start_daemon { execute_command( @@ -357,7 +333,6 @@ impl Action for ConfigureInitService { enable(SOCKET_SRC, false).await.map_err(Self::error)?; } }, - #[cfg(not(target_os = "macos"))] InitSystem::None => { // Nothing here, no init system }, @@ -368,7 +343,6 @@ impl Action for ConfigureInitService { fn revert_description(&self) -> Vec { match self.init { - #[cfg(target_os = "linux")] InitSystem::Systemd => { vec![ActionDescription::new( "Unconfigure Nix daemon related settings with systemd".to_string(), @@ -380,25 +354,21 @@ impl Action for ConfigureInitService { ], )] }, - #[cfg(target_os = "macos")] InitSystem::Launchd => { vec![ActionDescription::new( "Unconfigure Nix daemon related settings with launchctl".to_string(), vec![format!("Run `launchctl bootout {DARWIN_NIX_DAEMON_DEST}`")], )] }, - #[cfg(not(target_os = "macos"))] InitSystem::None => Vec::new(), } } #[tracing::instrument(level = "debug", skip_all)] async fn revert(&mut self) -> Result<(), ActionError> { - #[cfg_attr(target_os = "macos", allow(unused_mut))] let mut errors = vec![]; match self.init { - #[cfg(target_os = "macos")] InitSystem::Launchd => { execute_command( Command::new("launchctl") @@ -409,7 +379,6 @@ impl Action for ConfigureInitService { .await .map_err(Self::error)?; }, - #[cfg(target_os = "linux")] InitSystem::Systemd => { // We separate stop and disable (instead of using `--now`) to avoid cases where the service isn't started, but is enabled. @@ -505,7 +474,6 @@ impl Action for ConfigureInitService { errors.push(err); } }, - #[cfg(not(target_os = "macos"))] InitSystem::None => { // Nothing here, no init }, @@ -533,7 +501,6 @@ pub enum ConfigureNixDaemonServiceError { InitNotSupported, } -#[cfg(target_os = "macos")] #[derive(Deserialize, Clone, Debug, Serialize, PartialEq)] #[serde(rename_all = "PascalCase")] pub struct DeterminateNixDaemonPlist { @@ -546,14 +513,12 @@ pub struct DeterminateNixDaemonPlist { soft_resource_limits: ResourceLimits, } -#[cfg(target_os = "macos")] #[derive(Deserialize, Clone, Debug, Serialize, PartialEq)] #[serde(rename_all = "PascalCase")] pub struct ResourceLimits { number_of_files: usize, } -#[cfg(target_os = "linux")] async fn stop(unit: &str) -> Result<(), ActionErrorKind> { let mut command = Command::new("systemctl"); command.arg("stop"); @@ -571,7 +536,6 @@ async fn stop(unit: &str) -> Result<(), ActionErrorKind> { } } -#[cfg(target_os = "linux")] async fn enable(unit: &str, now: bool) -> Result<(), ActionErrorKind> { let mut command = Command::new("systemctl"); command.arg("enable"); @@ -592,7 +556,6 @@ async fn enable(unit: &str, now: bool) -> Result<(), ActionErrorKind> { } } -#[cfg(target_os = "linux")] async fn disable(unit: &str, now: bool) -> Result<(), ActionErrorKind> { let mut command = Command::new("systemctl"); command.arg("disable"); @@ -613,7 +576,6 @@ async fn disable(unit: &str, now: bool) -> Result<(), ActionErrorKind> { } } -#[cfg(target_os = "linux")] async fn is_active(unit: &str) -> Result { let mut command = Command::new("systemctl"); command.arg("is-active"); @@ -631,7 +593,6 @@ async fn is_active(unit: &str) -> Result { } } -#[cfg(target_os = "linux")] async fn is_enabled(unit: &str) -> Result { let mut command = Command::new("systemctl"); command.arg("is-enabled"); diff --git a/src/action/common/mod.rs b/src/action/common/mod.rs index 1bca186cd..1f89815a8 100644 --- a/src/action/common/mod.rs +++ b/src/action/common/mod.rs @@ -1,6 +1,5 @@ //! [`Action`](crate::action::Action)s which only call other base plugins -#[cfg(target_os = "macos")] pub(crate) mod configure_enterprise_edition_init_service; pub(crate) mod configure_init_service; pub(crate) mod configure_nix; @@ -11,7 +10,6 @@ pub(crate) mod delete_users; pub(crate) mod place_nix_configuration; pub(crate) mod provision_nix; -#[cfg(target_os = "macos")] pub use configure_enterprise_edition_init_service::ConfigureEnterpriseEditionInitService; pub use configure_init_service::{ConfigureInitService, ConfigureNixDaemonServiceError}; pub use configure_nix::ConfigureNix; diff --git a/src/action/mod.rs b/src/action/mod.rs index 97cd10a22..a72c2ad3f 100644 --- a/src/action/mod.rs +++ b/src/action/mod.rs @@ -166,6 +166,17 @@ impl Planner for MyPlanner { self.common.ssl_cert_file.clone(), )?) } + + async fn platform_check(&self) -> Result<(), PlannerError> { + use target_lexicon::OperatingSystem; + match target_lexicon::OperatingSystem::host() { + OperatingSystem::MacOSX { .. } | OperatingSystem::Darwin => Ok(()), + host_os => Err(PlannerError::IncompatibleOperatingSystem { + planner: self.typetag_name(), + host_os, + }), + } + } } # async fn custom_planner_install() -> color_eyre::Result<()> { diff --git a/src/plan.rs b/src/plan.rs index 6543f0cbc..be8fb19fb 100644 --- a/src/plan.rs +++ b/src/plan.rs @@ -50,6 +50,8 @@ impl InstallPlan { where P: Planner + 'static, { + planner.platform_check().await?; + #[cfg(feature = "diagnostics")] let diagnostic_data = Some(planner.diagnostic_data().await?); @@ -67,11 +69,13 @@ impl InstallPlan { } pub async fn pre_uninstall_check(&self) -> Result<(), NixInstallerError> { + self.planner.platform_check().await?; self.planner.pre_uninstall_check().await?; Ok(()) } pub async fn pre_install_check(&self) -> Result<(), NixInstallerError> { + self.planner.platform_check().await?; self.planner.pre_install_check().await?; Ok(()) } @@ -156,7 +160,7 @@ impl InstallPlan { cancel_channel: impl Into>>, ) -> Result<(), NixInstallerError> { self.check_compatible()?; - self.planner.pre_install_check().await?; + self.pre_install_check().await?; let Self { actions, .. } = self; let mut cancel_channel = cancel_channel.into(); @@ -327,7 +331,7 @@ impl InstallPlan { cancel_channel: impl Into>>, ) -> Result<(), NixInstallerError> { self.check_compatible()?; - self.planner.pre_uninstall_check().await?; + self.pre_uninstall_check().await?; let Self { actions, .. } = self; let mut cancel_channel = cancel_channel.into(); diff --git a/src/planner/linux.rs b/src/planner/linux.rs index 9fc348764..a16f9891c 100644 --- a/src/planner/linux.rs +++ b/src/planner/linux.rs @@ -139,6 +139,18 @@ impl Planner for Linux { self.settings.ssl_cert_file.clone(), )?) } + + async fn platform_check(&self) -> Result<(), PlannerError> { + use target_lexicon::OperatingSystem; + match target_lexicon::OperatingSystem::host() { + OperatingSystem::Linux => Ok(()), + host_os => Err(PlannerError::IncompatibleOperatingSystem { + planner: self.typetag_name(), + host_os, + }), + } + } + async fn pre_uninstall_check(&self) -> Result<(), PlannerError> { check_not_wsl1()?; diff --git a/src/planner/macos/mod.rs b/src/planner/macos/mod.rs index 4e4139860..f9849e37e 100644 --- a/src/planner/macos/mod.rs +++ b/src/planner/macos/mod.rs @@ -29,7 +29,6 @@ use crate::{ Action, BuiltinPlanner, }; -#[cfg(target_os = "macos")] use crate::action::common::ConfigureEnterpriseEditionInitService; /// A planner for MacOS (Darwin) systems @@ -302,6 +301,17 @@ impl Planner for Macos { )?) } + async fn platform_check(&self) -> Result<(), PlannerError> { + use target_lexicon::OperatingSystem; + match target_lexicon::OperatingSystem::host() { + OperatingSystem::MacOSX { .. } | OperatingSystem::Darwin => Ok(()), + host_os => Err(PlannerError::IncompatibleOperatingSystem { + planner: self.typetag_name(), + host_os, + }), + } + } + async fn pre_uninstall_check(&self) -> Result<(), PlannerError> { check_nix_darwin_not_installed().await?; diff --git a/src/planner/mod.rs b/src/planner/mod.rs index 963804d29..d50d55207 100644 --- a/src/planner/mod.rs +++ b/src/planner/mod.rs @@ -82,6 +82,17 @@ impl Planner for MyPlanner { self.common.ssl_cert_file.clone(), )?) } + + async fn platform_check(&self) -> Result<(), PlannerError> { + use target_lexicon::OperatingSystem; + match target_lexicon::OperatingSystem::host() { + OperatingSystem::MacOSX { .. } | OperatingSystem::Darwin => Ok(()), + host_os => Err(PlannerError::IncompatibleOperatingSystem { + planner: self.typetag_name(), + host_os, + }), + } + } } # async fn custom_planner_install() -> color_eyre::Result<()> { @@ -103,13 +114,9 @@ match plan.install(None).await { ``` */ -#[cfg(target_os = "linux")] pub mod linux; -#[cfg(target_os = "macos")] pub mod macos; -#[cfg(target_os = "linux")] pub mod ostree; -#[cfg(target_os = "linux")] pub mod steam_deck; use std::{collections::HashMap, path::PathBuf, string::FromUtf8Error}; @@ -147,6 +154,8 @@ pub trait Planner: std::fmt::Debug + Send + Sync + dyn_clone::DynClone { Box::new(self) } + async fn platform_check(&self) -> Result<(), PlannerError>; + async fn pre_uninstall_check(&self) -> Result<(), PlannerError> { Ok(()) } @@ -165,17 +174,17 @@ dyn_clone::clone_trait_object!(Planner); #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "cli", derive(clap::Subcommand))] pub enum BuiltinPlanner { - #[cfg(target_os = "linux")] + #[cfg_attr(not(target_os = "linux"), clap(hide = true))] /// A planner for traditional, mutable Linux systems like Debian, RHEL, or Arch Linux(linux::Linux), + #[cfg_attr(not(target_os = "linux"), clap(hide = true))] /// A planner for the Valve Steam Deck running SteamOS - #[cfg(target_os = "linux")] SteamDeck(steam_deck::SteamDeck), + #[cfg_attr(not(target_os = "linux"), clap(hide = true))] /// A planner suitable for immutable systems using ostree, such as Fedora Silverblue - #[cfg(target_os = "linux")] Ostree(ostree::Ostree), + #[cfg_attr(not(target_os = "macos"), clap(hide = true))] /// A planner for MacOS (Darwin) systems - #[cfg(target_os = "macos")] Macos(macos::Macos), } @@ -184,22 +193,17 @@ impl BuiltinPlanner { pub async fn default() -> Result { use target_lexicon::{Architecture, OperatingSystem}; match (Architecture::host(), OperatingSystem::host()) { - #[cfg(target_os = "linux")] (Architecture::X86_64, OperatingSystem::Linux) => Self::detect_linux_distro().await, - #[cfg(target_os = "linux")] (Architecture::X86_32(_), OperatingSystem::Linux) => { Ok(Self::Linux(linux::Linux::default().await?)) }, - #[cfg(target_os = "linux")] (Architecture::Aarch64(_), OperatingSystem::Linux) => { Ok(Self::Linux(linux::Linux::default().await?)) }, - #[cfg(target_os = "macos")] (Architecture::X86_64, OperatingSystem::MacOSX { .. }) | (Architecture::X86_64, OperatingSystem::Darwin) => { Ok(Self::Macos(macos::Macos::default().await?)) }, - #[cfg(target_os = "macos")] (Architecture::Aarch64(_), OperatingSystem::MacOSX { .. }) | (Architecture::Aarch64(_), OperatingSystem::Darwin) => { Ok(Self::Macos(macos::Macos::default().await?)) @@ -208,7 +212,6 @@ impl BuiltinPlanner { } } - #[cfg(target_os = "linux")] async fn detect_linux_distro() -> Result { let is_steam_deck = os_release::OsRelease::new().is_ok_and(|os_release| os_release.id == "steamos"); @@ -231,13 +234,9 @@ impl BuiltinPlanner { pub async fn from_common_settings(settings: CommonSettings) -> Result { let mut built = Self::default().await?; match &mut built { - #[cfg(target_os = "linux")] BuiltinPlanner::Linux(inner) => inner.settings = settings, - #[cfg(target_os = "linux")] BuiltinPlanner::SteamDeck(inner) => inner.settings = settings, - #[cfg(target_os = "linux")] BuiltinPlanner::Ostree(inner) => inner.settings = settings, - #[cfg(target_os = "macos")] BuiltinPlanner::Macos(inner) => inner.settings = settings, } Ok(built) @@ -247,64 +246,44 @@ impl BuiltinPlanner { &self, ) -> Result, PlannerError> { match self { - #[cfg(target_os = "linux")] BuiltinPlanner::Linux(inner) => inner.configured_settings().await, - #[cfg(target_os = "linux")] BuiltinPlanner::SteamDeck(inner) => inner.configured_settings().await, - #[cfg(target_os = "linux")] BuiltinPlanner::Ostree(inner) => inner.configured_settings().await, - #[cfg(target_os = "macos")] BuiltinPlanner::Macos(inner) => inner.configured_settings().await, } } pub async fn plan(self) -> Result { match self { - #[cfg(target_os = "linux")] BuiltinPlanner::Linux(planner) => InstallPlan::plan(planner).await, - #[cfg(target_os = "linux")] BuiltinPlanner::SteamDeck(planner) => InstallPlan::plan(planner).await, - #[cfg(target_os = "linux")] BuiltinPlanner::Ostree(planner) => InstallPlan::plan(planner).await, - #[cfg(target_os = "macos")] BuiltinPlanner::Macos(planner) => InstallPlan::plan(planner).await, } } pub fn boxed(self) -> Box { match self { - #[cfg(target_os = "linux")] BuiltinPlanner::Linux(i) => i.boxed(), - #[cfg(target_os = "linux")] BuiltinPlanner::SteamDeck(i) => i.boxed(), - #[cfg(target_os = "linux")] BuiltinPlanner::Ostree(i) => i.boxed(), - #[cfg(target_os = "macos")] BuiltinPlanner::Macos(i) => i.boxed(), } } pub fn typetag_name(&self) -> &'static str { match self { - #[cfg(target_os = "linux")] BuiltinPlanner::Linux(i) => i.typetag_name(), - #[cfg(target_os = "linux")] BuiltinPlanner::SteamDeck(i) => i.typetag_name(), - #[cfg(target_os = "linux")] BuiltinPlanner::Ostree(i) => i.typetag_name(), - #[cfg(target_os = "macos")] BuiltinPlanner::Macos(i) => i.typetag_name(), } } pub fn settings(&self) -> Result, InstallSettingsError> { match self { - #[cfg(target_os = "linux")] BuiltinPlanner::Linux(i) => i.settings(), - #[cfg(target_os = "linux")] BuiltinPlanner::SteamDeck(i) => i.settings(), - #[cfg(target_os = "linux")] BuiltinPlanner::Ostree(i) => i.settings(), - #[cfg(target_os = "macos")] BuiltinPlanner::Macos(i) => i.settings(), } } @@ -314,13 +293,9 @@ impl BuiltinPlanner { &self, ) -> Result { match self { - #[cfg(target_os = "linux")] BuiltinPlanner::Linux(i) => i.diagnostic_data().await, - #[cfg(target_os = "linux")] BuiltinPlanner::SteamDeck(i) => i.diagnostic_data().await, - #[cfg(target_os = "linux")] BuiltinPlanner::Ostree(i) => i.diagnostic_data().await, - #[cfg(target_os = "macos")] BuiltinPlanner::Macos(i) => i.diagnostic_data().await, } } @@ -392,6 +367,11 @@ impl Default for FishShellProfileLocations { #[non_exhaustive] #[derive(thiserror::Error, Debug, strum::IntoStaticStr)] pub enum PlannerError { + #[error("The selected planner (`{planner}`) does not support the host's operating system (`{host_os}`)")] + IncompatibleOperatingSystem { + planner: &'static str, + host_os: target_lexicon::OperatingSystem, + }, /// `nix-installer` does not have a default planner for the target architecture right now #[error("`nix-installer` does not have a default planner for the `{0}` architecture right now, pass a specific archetype")] UnsupportedArchitecture(target_lexicon::Triple), @@ -448,6 +428,7 @@ impl HasExpectedErrors for PlannerError { PlannerError::InstallSettings(_) => None, PlannerError::Plist(_) => None, PlannerError::Sysctl(_) => None, + this @ PlannerError::IncompatibleOperatingSystem { .. } => Some(Box::new(this)), this @ PlannerError::RosettaDetected => Some(Box::new(this)), this @ PlannerError::EnterpriseEditionUnavailable => Some(Box::new(this)), PlannerError::OsRelease(_) => None, diff --git a/src/planner/ostree.rs b/src/planner/ostree.rs index fa246a443..9dbaeeeb2 100644 --- a/src/planner/ostree.rs +++ b/src/planner/ostree.rs @@ -279,6 +279,18 @@ impl Planner for Ostree { self.settings.ssl_cert_file.clone(), )?) } + + async fn platform_check(&self) -> Result<(), PlannerError> { + use target_lexicon::OperatingSystem; + match target_lexicon::OperatingSystem::host() { + OperatingSystem::Linux => Ok(()), + host_os => Err(PlannerError::IncompatibleOperatingSystem { + planner: self.typetag_name(), + host_os, + }), + } + } + async fn pre_uninstall_check(&self) -> Result<(), PlannerError> { check_not_wsl1()?; diff --git a/src/planner/steam_deck.rs b/src/planner/steam_deck.rs index 915da62ad..2ca59ca38 100644 --- a/src/planner/steam_deck.rs +++ b/src/planner/steam_deck.rs @@ -399,6 +399,17 @@ impl Planner for SteamDeck { )?) } + async fn platform_check(&self) -> Result<(), PlannerError> { + use target_lexicon::OperatingSystem; + match target_lexicon::OperatingSystem::host() { + OperatingSystem::Linux => Ok(()), + host_os => Err(PlannerError::IncompatibleOperatingSystem { + planner: self.typetag_name(), + host_os, + }), + } + } + async fn pre_uninstall_check(&self) -> Result<(), PlannerError> { super::linux::check_not_wsl1()?; diff --git a/src/settings.rs b/src/settings.rs index d62cb4166..390260941 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -24,22 +24,16 @@ pub const NIX_TARBALL: &[u8] = include_bytes!(env!("NIX_INSTALLER_TARBALL_PATH") #[derive(Debug, serde::Deserialize, serde::Serialize, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "cli", derive(clap::ValueEnum))] pub enum InitSystem { - #[cfg(not(target_os = "macos"))] None, - #[cfg(target_os = "linux")] Systemd, - #[cfg(target_os = "macos")] Launchd, } impl std::fmt::Display for InitSystem { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - #[cfg(not(target_os = "macos"))] InitSystem::None => write!(f, "none"), - #[cfg(target_os = "linux")] InitSystem::Systemd => write!(f, "systemd"), - #[cfg(target_os = "macos")] InitSystem::Launchd => write!(f, "launchd"), } } @@ -396,7 +390,6 @@ impl CommonSettings { } } -#[cfg(target_os = "linux")] async fn linux_detect_systemd_started() -> bool { use std::process::Stdio; @@ -454,22 +447,17 @@ impl InitSettings { pub async fn default() -> Result { use target_lexicon::{Architecture, OperatingSystem}; let (init, start_daemon) = match (Architecture::host(), OperatingSystem::host()) { - #[cfg(target_os = "linux")] (Architecture::X86_64, OperatingSystem::Linux) => { (InitSystem::Systemd, linux_detect_systemd_started().await) }, - #[cfg(target_os = "linux")] (Architecture::X86_32(_), OperatingSystem::Linux) => { (InitSystem::Systemd, linux_detect_systemd_started().await) }, - #[cfg(target_os = "linux")] (Architecture::Aarch64(_), OperatingSystem::Linux) => { (InitSystem::Systemd, linux_detect_systemd_started().await) }, - #[cfg(target_os = "macos")] (Architecture::X86_64, OperatingSystem::MacOSX { .. }) | (Architecture::X86_64, OperatingSystem::Darwin) => (InitSystem::Launchd, true), - #[cfg(target_os = "macos")] (Architecture::Aarch64(_), OperatingSystem::MacOSX { .. }) | (Architecture::Aarch64(_), OperatingSystem::Darwin) => (InitSystem::Launchd, true), _ => { diff --git a/tests/plan.rs b/tests/plan.rs index e34ad0f75..9f4ffa2c7 100644 --- a/tests/plan.rs +++ b/tests/plan.rs @@ -1,15 +1,11 @@ use nix_installer::InstallPlan; -#[cfg(target_os = "linux")] const LINUX: &str = include_str!("./fixtures/linux/linux.json"); -#[cfg(target_os = "linux")] const STEAM_DECK: &str = include_str!("./fixtures/linux/steam-deck.json"); -#[cfg(target_os = "macos")] const MACOS: &str = include_str!("./fixtures/macos/macos.json"); // Ensure existing plans still parse // If this breaks and you need to update the fixture, disable these tests, bump `nix_installer` to a new version, and update the plans. -#[cfg(target_os = "linux")] #[test] fn plan_compat_linux() -> eyre::Result<()> { let _: InstallPlan = serde_json::from_str(LINUX)?; @@ -18,7 +14,6 @@ fn plan_compat_linux() -> eyre::Result<()> { // Ensure existing plans still parse // If this breaks and you need to update the fixture, disable these tests, bump `nix_installer` to a new version, and update the plans. -#[cfg(target_os = "linux")] #[test] fn plan_compat_steam_deck() -> eyre::Result<()> { let _: InstallPlan = serde_json::from_str(STEAM_DECK)?; @@ -27,7 +22,6 @@ fn plan_compat_steam_deck() -> eyre::Result<()> { // Ensure existing plans still parse // If this breaks and you need to update the fixture, disable these tests, bump `nix_installer` to a new version, and update the plans. -#[cfg(target_os = "macos")] #[test] fn plan_compat_macos() -> eyre::Result<()> { let _: InstallPlan = serde_json::from_str(MACOS)?;