diff --git a/src/action/common/configure_nix.rs b/src/action/common/configure_nix.rs index cbd0f1c..5502270 100644 --- a/src/action/common/configure_nix.rs +++ b/src/action/common/configure_nix.rs @@ -3,10 +3,9 @@ use reqwest::Url; use crate::{ action::{ common::{ - ConfigureShellProfile, PlaceChannelConfiguration, PlaceNixConfiguration, - SetupDefaultProfile, + ConfigureNixDaemonService, ConfigureShellProfile, PlaceChannelConfiguration, + PlaceNixConfiguration, SetupDefaultProfile, }, - linux::ConfigureNixDaemonService, Action, ActionDescription, ActionState, }, cli::arg::ChannelValue, diff --git a/src/action/linux/configure_nix_daemon_service.rs b/src/action/common/configure_nix_daemon_service.rs similarity index 79% rename from src/action/linux/configure_nix_daemon_service.rs rename to src/action/common/configure_nix_daemon_service.rs index 0b4b8a4..974d798 100644 --- a/src/action/linux/configure_nix_daemon_service.rs +++ b/src/action/common/configure_nix_daemon_service.rs @@ -100,7 +100,7 @@ impl Action for ConfigureNixDaemonService { .arg(DARWIN_NIX_DAEMON_DEST), ) .await - .map_err(|e| ConfigureNixDaemonServiceError::CommandFailed(e).boxed())?; + .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; }, _ => { tracing::trace!(src = TMPFILES_SRC, dest = TMPFILES_DEST, "Symlinking"); @@ -121,19 +121,19 @@ impl Action for ConfigureNixDaemonService { .arg("--prefix=/nix/var/nix"), ) .await - .map_err(|e| ConfigureNixDaemonServiceError::CommandFailed(e).boxed())?; + .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; execute_command(Command::new("systemctl").arg("link").arg(SERVICE_SRC)) .await - .map_err(|e| ConfigureNixDaemonServiceError::CommandFailed(e).boxed())?; + .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; execute_command(Command::new("systemctl").arg("link").arg(SOCKET_SRC)) .await - .map_err(|e| ConfigureNixDaemonServiceError::CommandFailed(e).boxed())?; + .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; execute_command(Command::new("systemctl").arg("daemon-reload")) .await - .map_err(|e| ConfigureNixDaemonServiceError::CommandFailed(e).boxed())?; + .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; }, }; @@ -167,30 +167,48 @@ impl Action for ConfigureNixDaemonService { } tracing::debug!("Unconfiguring nix daemon service"); - // We don't need to do this! Systemd does it for us! (In fact, it's an error if we try to do this...) - execute_command(Command::new("systemctl").args(["disable", SOCKET_SRC])) - .await - .map_err(|e| ConfigureNixDaemonServiceError::CommandFailed(e).boxed())?; + match OperatingSystem::host() { + OperatingSystem::MacOSX { + major: _, + minor: _, + patch: _, + } + | OperatingSystem::Darwin => { + execute_command( + Command::new("launchctl") + .arg("unload") + .arg("system/org.nixos.nix-daemon"), + ) + .await + .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; + }, + _ => { + execute_command(Command::new("systemctl").args(["disable", SOCKET_SRC])) + .await + .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; - execute_command(Command::new("systemctl").args(["disable", SERVICE_SRC])) - .await - .map_err(|e| ConfigureNixDaemonServiceError::CommandFailed(e).boxed())?; + execute_command(Command::new("systemctl").args(["disable", SERVICE_SRC])) + .await + .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; - execute_command( - Command::new("systemd-tmpfiles") - .arg("--remove") - .arg("--prefix=/nix/var/nix"), - ) - .await - .map_err(|e| ConfigureNixDaemonServiceError::CommandFailed(e).boxed())?; + execute_command( + Command::new("systemd-tmpfiles") + .arg("--remove") + .arg("--prefix=/nix/var/nix"), + ) + .await + .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; - remove_file(TMPFILES_DEST).await.map_err(|e| { - ConfigureNixDaemonServiceError::RemoveFile(PathBuf::from(TMPFILES_DEST), e).boxed() - })?; + remove_file(TMPFILES_DEST).await.map_err(|e| { + ConfigureNixDaemonServiceError::RemoveFile(PathBuf::from(TMPFILES_DEST), e) + .boxed() + })?; - execute_command(Command::new("systemctl").arg("daemon-reload")) - .await - .map_err(|e| ConfigureNixDaemonServiceError::CommandFailed(e).boxed())?; + execute_command(Command::new("systemctl").arg("daemon-reload")) + .await + .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; + }, + }; tracing::trace!("Unconfigured nix daemon service"); *action_state = ActionState::Uncompleted; @@ -207,7 +225,7 @@ pub enum ConfigureNixDaemonServiceError { #[source] std::io::Error, ), #[error("Command failed to execute")] - CommandFailed(#[source] std::io::Error), + Command(#[source] std::io::Error), #[error("Remove file `{0}`")] RemoveFile(std::path::PathBuf, #[source] std::io::Error), #[error("Copying file `{0}` to `{1}`")] diff --git a/src/action/common/create_group.rs b/src/action/common/create_group.rs index 1747352..21042cf 100644 --- a/src/action/common/create_group.rs +++ b/src/action/common/create_group.rs @@ -141,9 +141,13 @@ impl Action for CreateGroup { patch: _, } | OperatingSystem::Darwin => { - execute_command(Command::new("groupdel").arg(&name)) - .await - .map_err(|e| CreateGroupError::Command(e).boxed())?; + execute_command(Command::new("/usr/bin/dscl").args([ + ".", + "-delete", + &format!("/Groups/{name}"), + ])) + .await + .map_err(|e| CreateGroupError::Command(e).boxed())?; }, _ => { execute_command(Command::new("groupdel").arg(&name)) diff --git a/src/action/common/mod.rs b/src/action/common/mod.rs index 50c2445..ce9520a 100644 --- a/src/action/common/mod.rs +++ b/src/action/common/mod.rs @@ -1,6 +1,7 @@ /*! Actions which only call other base plugins. */ mod configure_nix; +mod configure_nix_daemon_service; mod configure_shell_profile; mod create_directory; mod create_file; @@ -17,6 +18,7 @@ mod provision_nix; mod setup_default_profile; pub use configure_nix::ConfigureNix; +pub use configure_nix_daemon_service::{ConfigureNixDaemonService, ConfigureNixDaemonServiceError}; pub use configure_shell_profile::ConfigureShellProfile; pub use create_directory::{CreateDirectory, CreateDirectoryError}; pub use create_file::{CreateFile, CreateFileError}; diff --git a/src/action/darwin/kickstart_launchctl_service.rs b/src/action/darwin/kickstart_launchctl_service.rs index 6f0f476..6127584 100644 --- a/src/action/darwin/kickstart_launchctl_service.rs +++ b/src/action/darwin/kickstart_launchctl_service.rs @@ -84,16 +84,12 @@ impl Action for KickstartLaunchctlService { async fn revert(&mut self) -> Result<(), Box> { let Self { unit, action_state } = self; if *action_state == ActionState::Uncompleted { - tracing::trace!("Already reverted: Stopping launchctl unit"); + tracing::trace!("Already reverted: Unkickstart launchctl unit (noop)"); return Ok(()); } - tracing::debug!("Stopping launchctl unit"); + tracing::debug!("Unkickstart launchctl unit (noop)"); - execute_command(Command::new("launchctl").arg("stop").arg(unit)) - .await - .map_err(|e| KickstartLaunchctlServiceError::Command(e).boxed())?; - - tracing::trace!("Stopped launchctl unit"); + tracing::trace!("Unkickstart launchctl unit (noop)"); *action_state = ActionState::Completed; Ok(()) } diff --git a/src/action/linux/mod.rs b/src/action/linux/mod.rs index c066910..58f683f 100644 --- a/src/action/linux/mod.rs +++ b/src/action/linux/mod.rs @@ -1,9 +1,7 @@ -mod configure_nix_daemon_service; mod create_systemd_sysext; mod start_systemd_unit; mod systemd_sysext_merge; -pub use configure_nix_daemon_service::{ConfigureNixDaemonService, ConfigureNixDaemonServiceError}; pub use create_systemd_sysext::{CreateSystemdSysext, CreateSystemdSysextError}; pub use start_systemd_unit::{StartSystemdUnit, StartSystemdUnitError}; pub use systemd_sysext_merge::{SystemdSysextMerge, SystemdSysextMergeError};