Skip to content

Commit

Permalink
Wait longer for /nix to exist on macOS (#1141)
Browse files Browse the repository at this point in the history
* macos: split wait_for_nix_store_dir into own function

* macos: give more retry tokens to wait_for_nix_store_dir

Now it will try for 15 seconds (150 * 100ms) before failing.
  • Loading branch information
cole-h committed Sep 4, 2024
1 parent 661fe1c commit 8a30565
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 46 deletions.
26 changes: 3 additions & 23 deletions src/action/macos/create_determinate_nix_volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,29 +237,9 @@ impl Action for CreateDeterminateNixVolume {
)));
}

let mut retry_tokens: usize = 50;
loop {
let mut command = Command::new("/usr/sbin/diskutil");
command.args(["info", "/nix"]);
command.stderr(std::process::Stdio::null());
command.stdout(std::process::Stdio::null());
tracing::trace!(%retry_tokens, command = ?command.as_std(), "Checking for Nix Store mount path existence");
let output = command
.output()
.await
.map_err(|e| ActionErrorKind::command(&command, e))
.map_err(Self::error)?;
if output.status.success() {
break;
} else if retry_tokens == 0 {
return Err(Self::error(ActionErrorKind::command_output(
&command, output,
)));
} else {
retry_tokens = retry_tokens.saturating_sub(1);
}
tokio::time::sleep(Duration::from_millis(100)).await;
}
crate::action::macos::wait_for_nix_store_dir()
.await
.map_err(Self::error)?;

self.setup_volume_daemon
.try_execute()
Expand Down
26 changes: 3 additions & 23 deletions src/action/macos/create_nix_volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,29 +225,9 @@ impl Action for CreateNixVolume {
.await
.map_err(Self::error)?;

let mut retry_tokens: usize = 50;
loop {
let mut command = Command::new("/usr/sbin/diskutil");
command.args(["info", "/nix"]);
command.stderr(std::process::Stdio::null());
command.stdout(std::process::Stdio::null());
tracing::trace!(%retry_tokens, command = ?command.as_std(), "Checking for Nix Store mount path existence");
let output = command
.output()
.await
.map_err(|e| ActionErrorKind::command(&command, e))
.map_err(Self::error)?;
if output.status.success() {
break;
} else if retry_tokens == 0 {
return Err(Self::error(ActionErrorKind::command_output(
&command, output,
)));
} else {
retry_tokens = retry_tokens.saturating_sub(1);
}
tokio::time::sleep(Duration::from_millis(100)).await;
}
crate::action::macos::wait_for_nix_store_dir()
.await
.map_err(Self::error)?;

self.enable_ownership
.try_execute()
Expand Down
29 changes: 29 additions & 0 deletions src/action/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub(crate) mod set_tmutil_exclusion;
pub(crate) mod set_tmutil_exclusions;
pub(crate) mod unmount_apfs_volume;

use std::time::Duration;

pub use bootstrap_launchctl_service::BootstrapLaunchctlService;
pub use configure_remote_building::ConfigureRemoteBuilding;
pub use create_apfs_volume::CreateApfsVolume;
Expand Down Expand Up @@ -105,3 +107,30 @@ pub(crate) async fn service_is_disabled(
tracing::trace!(is_disabled, "Service disabled status");
Ok(is_disabled)
}

/// Waits for the Nix Store mountpoint to exist, up to `retry_tokens * 100ms` amount of time.
#[tracing::instrument]
pub(crate) async fn wait_for_nix_store_dir() -> Result<(), ActionErrorKind> {
let mut retry_tokens: usize = 150;
loop {
let mut command = Command::new("/usr/sbin/diskutil");
command.args(["info", "/nix"]);
command.stderr(std::process::Stdio::null());
command.stdout(std::process::Stdio::null());
tracing::trace!(%retry_tokens, command = ?command.as_std(), "Checking for Nix Store mount path existence");
let output = command
.output()
.await
.map_err(|e| ActionErrorKind::command(&command, e))?;
if output.status.success() {
break;
} else if retry_tokens == 0 {
return Err(ActionErrorKind::command_output(&command, output))?;
} else {
retry_tokens = retry_tokens.saturating_sub(1);
}
tokio::time::sleep(Duration::from_millis(100)).await;
}

Ok(())
}

0 comments on commit 8a30565

Please sign in to comment.