diff --git a/src/action/common/configure_init_service.rs b/src/action/common/configure_init_service.rs index f7ad31b0d..2208be9e0 100644 --- a/src/action/common/configure_init_service.rs +++ b/src/action/common/configure_init_service.rs @@ -242,7 +242,7 @@ impl Action for ConfigureInitService { let service_dest = service_dest .as_ref() .expect("service_dest should be set for Launchd"); - let service = service_name + let service_name = service_name .as_ref() .expect("service_name should be set for Launchd"); let domain = DARWIN_LAUNCHD_DOMAIN; @@ -259,11 +259,11 @@ impl Action for ConfigureInitService { })?; } - crate::action::macos::retry_bootstrap(domain, service, service_dest) + crate::action::macos::retry_bootstrap(domain, service_name, service_dest) .await .map_err(Self::error)?; - let is_disabled = crate::action::macos::service_is_disabled(domain, service) + let is_disabled = crate::action::macos::service_is_disabled(domain, service_name) .await .map_err(Self::error)?; if is_disabled { @@ -271,7 +271,7 @@ impl Action for ConfigureInitService { Command::new("launchctl") .process_group(0) .arg("enable") - .arg(format!("{domain}/{service}")) + .arg(format!("{domain}/{service_name}")) .stdin(std::process::Stdio::null()), ) .await @@ -279,7 +279,7 @@ impl Action for ConfigureInitService { } if *start_daemon { - crate::action::macos::retry_kickstart(domain, service) + crate::action::macos::retry_kickstart(domain, service_name) .await .map_err(Self::error)?; } diff --git a/src/action/macos/bootstrap_launchctl_service.rs b/src/action/macos/bootstrap_launchctl_service.rs index ca3a9c9b2..67f3d7559 100644 --- a/src/action/macos/bootstrap_launchctl_service.rs +++ b/src/action/macos/bootstrap_launchctl_service.rs @@ -16,7 +16,7 @@ Bootstrap and kickstart an APFS volume #[derive(Debug, serde::Deserialize, serde::Serialize, Clone)] #[serde(tag = "action_name", rename = "bootstrap_launchctl_service")] pub struct BootstrapLaunchctlService { - service: String, + service_name: String, path: PathBuf, is_present: bool, is_disabled: bool, @@ -24,15 +24,15 @@ pub struct BootstrapLaunchctlService { impl BootstrapLaunchctlService { #[tracing::instrument(level = "debug", skip_all)] - pub async fn plan(service: &str, path: &str) -> Result, ActionError> { - let service = service.to_owned(); + pub async fn plan(service_name: &str, path: &str) -> Result, ActionError> { + let service_name = service_name.to_owned(); let path = PathBuf::from(path); let is_present = { let mut command = Command::new("launchctl"); command.process_group(0); command.arg("print"); - command.arg(format!("{DARWIN_LAUNCHD_DOMAIN}/{service}")); + command.arg(format!("{DARWIN_LAUNCHD_DOMAIN}/{service_name}")); command.stdin(std::process::Stdio::null()); command.stdout(std::process::Stdio::piped()); command.stderr(std::process::Stdio::piped()); @@ -41,15 +41,15 @@ impl BootstrapLaunchctlService { .await .map_err(|e| Self::error(ActionErrorKind::command(&command, e)))?; // We presume that success means it's found - command_output.status.success() || command_output.status.code() == Some(37) + command_output.status.success() }; - let is_disabled = service_is_disabled(DARWIN_LAUNCHD_DOMAIN, &service) + let is_disabled = service_is_disabled(DARWIN_LAUNCHD_DOMAIN, &service_name) .await .map_err(Self::error)?; Ok(StatefulAction::uncompleted(Self { - service, + service_name, path, is_present, is_disabled, @@ -66,7 +66,7 @@ impl Action for BootstrapLaunchctlService { fn tracing_synopsis(&self) -> String { format!( "Bootstrap the `{}` service via `launchctl bootstrap {} {}`", - self.service, + self.service_name, DARWIN_LAUNCHD_DOMAIN, self.path.display() ) @@ -89,7 +89,7 @@ impl Action for BootstrapLaunchctlService { #[tracing::instrument(level = "debug", skip_all)] async fn execute(&mut self) -> Result<(), ActionError> { let Self { - service, + service_name, path, is_present, is_disabled, @@ -100,7 +100,7 @@ impl Action for BootstrapLaunchctlService { Command::new("launchctl") .process_group(0) .arg("enable") - .arg(format!("{DARWIN_LAUNCHD_DOMAIN}/{service}")) + .arg(format!("{DARWIN_LAUNCHD_DOMAIN}/{service_name}")) .stdin(std::process::Stdio::null()), ) .await @@ -108,12 +108,12 @@ impl Action for BootstrapLaunchctlService { } if *is_present { - crate::action::macos::retry_bootout(DARWIN_LAUNCHD_DOMAIN, service) + crate::action::macos::retry_bootout(DARWIN_LAUNCHD_DOMAIN, service_name) .await .map_err(Self::error)?; } - crate::action::macos::retry_bootstrap(DARWIN_LAUNCHD_DOMAIN, service, path) + crate::action::macos::retry_bootstrap(DARWIN_LAUNCHD_DOMAIN, service_name, path) .await .map_err(Self::error)?; @@ -133,7 +133,7 @@ impl Action for BootstrapLaunchctlService { #[tracing::instrument(level = "debug", skip_all)] async fn revert(&mut self) -> Result<(), ActionError> { - crate::action::macos::retry_bootout(DARWIN_LAUNCHD_DOMAIN, &self.service) + crate::action::macos::retry_bootout(DARWIN_LAUNCHD_DOMAIN, &self.service_name) .await .map_err(Self::error)?; diff --git a/src/action/macos/create_nix_volume.rs b/src/action/macos/create_nix_volume.rs index 480dfe622..ec64815a1 100644 --- a/src/action/macos/create_nix_volume.rs +++ b/src/action/macos/create_nix_volume.rs @@ -19,13 +19,14 @@ use super::{ }; pub const NIX_VOLUME_MOUNTD_DEST: &str = "/Library/LaunchDaemons/org.nixos.darwin-store.plist"; +pub const NIX_VOLUME_MOUNTD_NAME: &str = "org.nixos.darwin-store"; /// Create an APFS volume #[derive(Debug, serde::Deserialize, serde::Serialize, Clone)] #[serde(tag = "action_name", rename = "create_nix_volume")] pub struct CreateNixVolume { disk: PathBuf, - name: String, + volume_label: String, case_sensitive: bool, encrypt: bool, create_or_append_synthetic_conf: StatefulAction, @@ -44,7 +45,7 @@ impl CreateNixVolume { #[tracing::instrument(level = "debug", skip_all)] pub async fn plan( disk: impl AsRef, - name: String, + volume_label: String, case_sensitive: bool, encrypt: bool, ) -> Result, ActionError> { @@ -62,34 +63,34 @@ impl CreateNixVolume { let create_synthetic_objects = CreateSyntheticObjects::plan().await.map_err(Self::error)?; - let create_volume = CreateApfsVolume::plan(disk, name.clone(), case_sensitive) + let create_volume = CreateApfsVolume::plan(disk, volume_label.clone(), case_sensitive) .await .map_err(Self::error)?; let unmount_volume = if create_volume.state == crate::action::ActionState::Completed { - UnmountApfsVolume::plan_skip_if_already_mounted_to_nix(disk, name.clone()) + UnmountApfsVolume::plan_skip_if_already_mounted_to_nix(disk, volume_label.clone()) .await .map_err(Self::error)? } else { - UnmountApfsVolume::plan(disk, name.clone()) + UnmountApfsVolume::plan(disk, volume_label.clone()) .await .map_err(Self::error)? }; - let create_fstab_entry = CreateFstabEntry::plan(name.clone()) + let create_fstab_entry = CreateFstabEntry::plan(volume_label.clone()) .await .map_err(Self::error)?; let encrypt_volume = if encrypt { - Some(EncryptApfsVolume::plan(false, disk, &name, &create_volume).await?) + Some(EncryptApfsVolume::plan(false, disk, &volume_label, &create_volume).await?) } else { None }; let setup_volume_daemon = CreateVolumeService::plan( NIX_VOLUME_MOUNTD_DEST, - "org.nixos.darwin-store", - name.clone(), + NIX_VOLUME_MOUNTD_NAME, + volume_label.clone(), "/nix", encrypt, ) @@ -97,18 +98,18 @@ impl CreateNixVolume { .map_err(Self::error)?; let bootstrap_volume = - BootstrapLaunchctlService::plan("org.nixos.darwin-store", NIX_VOLUME_MOUNTD_DEST) + BootstrapLaunchctlService::plan(NIX_VOLUME_MOUNTD_NAME, NIX_VOLUME_MOUNTD_DEST) .await .map_err(Self::error)?; let kickstart_launchctl_service = - KickstartLaunchctlService::plan(DARWIN_LAUNCHD_DOMAIN, "org.nixos.darwin-store") + KickstartLaunchctlService::plan(DARWIN_LAUNCHD_DOMAIN, NIX_VOLUME_MOUNTD_NAME) .await .map_err(Self::error)?; let enable_ownership = EnableOwnership::plan("/nix").await.map_err(Self::error)?; Ok(Self { disk: disk.to_path_buf(), - name, + volume_label, case_sensitive, encrypt, create_or_append_synthetic_conf, @@ -134,9 +135,9 @@ impl Action for CreateNixVolume { } fn tracing_synopsis(&self) -> String { format!( - "Create an{maybe_encrypted} APFS volume `{name}` for Nix on `{disk}` and add it to `/etc/fstab` mounting on `/nix`", + "Create an{maybe_encrypted} APFS volume `{volume_label}` for Nix on `{disk}` and add it to `/etc/fstab` mounting on `/nix`", maybe_encrypted = if self.encrypt { " encrypted" } else { "" }, - name = self.name, + volume_label = self.volume_label, disk = self.disk.display(), ) } @@ -146,7 +147,7 @@ impl Action for CreateNixVolume { tracing::Level::DEBUG, "create_nix_volume", disk = tracing::field::display(self.disk.display()), - name = self.name + volume_label = self.volume_label ) } @@ -188,7 +189,7 @@ impl Action for CreateNixVolume { loop { let mut command = Command::new("/usr/sbin/diskutil"); command.args(["info", "-plist"]); - command.arg(&self.name); + command.arg(&self.volume_label); command.stderr(std::process::Stdio::null()); command.stdout(std::process::Stdio::null()); tracing::debug!(%retry_tokens, command = ?command.as_std(), "Checking for Nix Store volume existence"); @@ -261,7 +262,7 @@ impl Action for CreateNixVolume { vec![ActionDescription::new( format!( "Remove the APFS volume `{}` on `{}`", - self.name, + self.volume_label, self.disk.display() ), explanation,