From 0b050561851d261ba08ad84cc1b7f367a6e2bd1e Mon Sep 17 00:00:00 2001 From: Melvillian Date: Thu, 13 Nov 2025 14:06:53 -0500 Subject: [PATCH] fix: fix setup_lima when run on a mac Prior to this commit, env_wrapper's 'setup_lima' command would only work for Linux because it uses the 'nproc' and 'free' shell commands, which do not exist on Mac. Now, the script detects the platform and uses the appropriate shell commands --- scripts/env_wrapper.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/env_wrapper.sh b/scripts/env_wrapper.sh index e50ec45..a892220 100755 --- a/scripts/env_wrapper.sh +++ b/scripts/env_wrapper.sh @@ -22,8 +22,25 @@ setup_lima() { exit 1 fi - LIMA_CPUS="${LIMA_CPUS:-$( nproc )}" - LIMA_MEMORY="${LIMA_MEMORY:-$( free -g | awk '/^Mem:/ {print $2-2 }' )}" + # Detect CPU count (cross-platform) + if command -v nproc &>/dev/null; then + LIMA_CPUS="${LIMA_CPUS:-$( nproc )}" + elif [[ "$OSTYPE" == "darwin"* ]]; then + LIMA_CPUS="${LIMA_CPUS:-$( sysctl -n hw.ncpu )}" + else + LIMA_CPUS="${LIMA_CPUS:-2}" # Fallback + fi + + # Detect memory (cross-platform) + if command -v free &>/dev/null; then + LIMA_MEMORY="${LIMA_MEMORY:-$( free -g | awk '/^Mem:/ {print $2-2 }' )}" + elif [[ "$OSTYPE" == "darwin"* ]]; then + # sysctl returns bytes, convert to GB and subtract 2GB + mem_gb=$(($(sysctl -n hw.memsize) / 1024 / 1024 / 1024 - 2)) + LIMA_MEMORY="${LIMA_MEMORY:-$mem_gb}" + else + LIMA_MEMORY="${LIMA_MEMORY:-4}" # Fallback + fi # Create VM if it doesn't exist if ! limactl list "$LIMA_VM" > /dev/null 2>&1; then