Fixup a mistaken move of actions and make configure_nix_daemon_service cross platform

This commit is contained in:
Ana Hobden 2022-10-28 10:54:33 -07:00
parent a61045f5a8
commit 615b8b502c
6 changed files with 58 additions and 41 deletions

View file

@ -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,

View file

@ -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}`")]

View file

@ -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))

View file

@ -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};

View file

@ -84,16 +84,12 @@ impl Action for KickstartLaunchctlService {
async fn revert(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
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(())
}

View file

@ -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};