From 4a848be9bb71b7c0a72dec8fd058cb2f6f508d24 Mon Sep 17 00:00:00 2001 From: marcoleder Date: Tue, 3 Dec 2024 18:06:42 +0100 Subject: [PATCH] fix(dev): Check for Rosetta2 and install if necessary (MacOS) --- flake.nix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/flake.nix b/flake.nix index 4ef325dbde..a1e7261106 100644 --- a/flake.nix +++ b/flake.nix @@ -148,6 +148,31 @@ # Fix clang for XCode builds export PATH=$(echo $PATH | tr ':' '\n' | grep -v clang | paste -sd ':' -) + + # Check and install Rosetta 2 on macOS to enable emulator support + if [[ $(uname) == "Darwin" ]]; then + processor_brand=$(/usr/sbin/sysctl -n machdep.cpu.brand_string) + if [[ "$processor_brand" == *"Apple"* ]]; then + echo "Apple Processor is present..." + check_rosetta_status=$(/usr/bin/pgrep oahd) + rosetta_folder="/Library/Apple/usr/share/rosetta" + + if [[ -n $check_rosetta_status ]] && [[ -e $rosetta_folder ]]; then + echo "Rosetta is installed... no action needed" + else + echo "Rosetta is not installed... installing now - It is needed for running the application in a virtual emulator on your MacOS with Apple Silicon, read more here: https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment" + sudo /usr/sbin/softwareupdate --install-rosetta --agree-to-license + if /usr/bin/pgrep oahd >/dev/null 2>&1 ; then + echo "Rosetta is now installed" + else + echo "Rosetta installation failed" + exit 1 + fi + fi + else + echo "Apple Processor is not present... Rosetta is not needed" + fi + fi ''; }; }