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

feat: Add check to verify if rosetta is installed on macOS #29

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ pub mod flake_enabled;
pub mod max_jobs;
pub mod min_nix_version;
pub mod rosetta;
pub mod rosetta_installed;
pub mod system;
pub mod trusted_users;
62 changes: 62 additions & 0 deletions src/check/rosetta_installed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use nix_rs::{
env::{MacOSArch, OS},
info,
};
use serde::{Deserialize, Serialize};
use std::process::Command;

use crate::traits::{Check, CheckResult, Checkable};

/// Check if rosetta 2 is installed
///
/// Applies to ARM macs.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
#[serde(default)]
pub struct RosettaInstalled {
enable: bool,
required: bool,
}

impl Checkable for RosettaInstalled {
fn check(
&self,
nix_info: &info::NixInfo,
_: Option<&nix_rs::flake::url::FlakeUrl>,
) -> Vec<Check> {
let mut checks = vec![];
if let (
true,
OS::MacOS {
nix_darwin: _,
arch: MacOSArch::Arm64(_),
},
) = (self.enable, &nix_info.nix_env.os)
{
let check = Check {
title: "Rosetta Installed".to_string(),
info: "".to_string(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be something rather than empty string, so that we don't see an empty line (somewhat confusing) here:

image

result: if is_rosetta_installed() {
CheckResult::Green
} else {
CheckResult::Red {
msg: "Rosetta 2 is not installed".to_string(),
suggestion: "Install Rosetta 2 by running: `softwareupdate --install-rosetta --agree-to-license`".to_string(),
}
},
required: self.required,
};
checks.push(check);
};
checks
}
}

fn is_rosetta_installed() -> bool {
let output = Command::new("pkgutil")
.arg("--pkg-info")
.arg("com.apple.pkg.RosettaUpdateAuto")
.output()
.expect("Failed to execute command");

output.status.success()
}
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tracing::instrument;

use self::check::{
caches::Caches, flake_enabled::FlakeEnabled, max_jobs::MaxJobs, min_nix_version::MinNixVersion,
rosetta::Rosetta, trusted_users::TrustedUsers,
rosetta::Rosetta, rosetta_installed::RosettaInstalled, trusted_users::TrustedUsers,
};

/// Nix Health check information for user's install
Expand All @@ -32,6 +32,7 @@ pub struct NixHealth {
pub system: check::system::System,
pub trusted_users: TrustedUsers,
pub rosetta: Rosetta,
pub rosetta_installed: RosettaInstalled,
pub direnv: Direnv,
}

Expand All @@ -43,6 +44,7 @@ impl<'a> IntoIterator for &'a NixHealth {
fn into_iter(self) -> Self::IntoIter {
let items: Vec<Self::Item> = vec![
&self.rosetta,
&self.rosetta_installed,
&self.nix_version,
&self.flake_enabled,
&self.system,
Expand Down