Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait longer for /nix to exist on macOS #1141

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}
Loading