From eccaa631df563c4fc7c9d23b7af3bf00bc78dda9 Mon Sep 17 00:00:00 2001 From: Alain Lehmann Date: Sun, 15 Oct 2023 18:00:17 +0200 Subject: [PATCH] create VM completly with setupVM.osa --- config.plist | 80 --------------------------------------------------- efi_vars.fd | Bin 131072 -> 0 bytes flake.nix | 56 ++++++++++++++++++++++-------------- setupVM.osa | 10 +++---- 4 files changed, 39 insertions(+), 107 deletions(-) delete mode 100644 config.plist delete mode 100644 efi_vars.fd diff --git a/config.plist b/config.plist deleted file mode 100644 index 9f50f0e..0000000 --- a/config.plist +++ /dev/null @@ -1,80 +0,0 @@ - - - - - Backend - Apple - ConfigurationVersion - 4 - Display - - - HeightPixels - 1200 - PixelsPerInch - 226 - WidthPixels - 1920 - - - Drive - - - Information - - IconCustom - - Name - XXX_NAME - UUID - XXX_VM_ID - - Network - - - Serial - - - Mode - Ptty - - - System - - Architecture - aarch64 - Boot - - EfiVariableStoragePath - efi_vars.fd - OperatingSystem - Linux - UEFIBoot - - - CPUCount - 2 - MemorySize - 4096 - - Virtualization - - Audio - - Balloon - - ClipboardSharing - - Entropy - - Keyboard - - Pointer - - Rosetta - - Trackpad - - - - diff --git a/efi_vars.fd b/efi_vars.fd deleted file mode 100644 index 0622fddd25d5e0c3ef881cbb57eb06e26898f0bc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 131072 zcmeI%&yQVG902h1W=5ygR*fG;i_A`>C0MXPXiHVnQK8fLk&tSu8l#$_L_*4<3n?~= zE=0RzA|xbY;}2kg5DN>bhzPN=v5=VYJ@>li&FkyDdpk{LqMtXpGw;58&OPUR&i8)r zxo=XM`FeHDA5(8Wb7=E>2d}te@WCy2r_@&zczENsP1m23(x&vwZ}CCjaQ^h%{HuJe zy#A{n_FuPi-H}fw5AHiK`NF5iQ+i;sJT@_UQyPr7i(?yzZRpm0zxQ46?a*t_remM) z8NYEPZA}~E^HyvVqqh`g^Qm*o+mHWz=!@6C8Jbw0emv5@=9R5!PkJKl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oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk g1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+z^MuR12Y;J)Bpeg diff --git a/flake.nix b/flake.nix index e10a94c..a726271 100644 --- a/flake.nix +++ b/flake.nix @@ -85,6 +85,21 @@ ssh "root@$(nixosIP)" "$@" ''; }; + packages.killUTM = pkgs.writeShellApplication { + name = "killUTM"; + runtimeInputs = [self'.packages.utm]; + text = '' + # shellcheck disable=SC2009 + if ps aux | grep '/[U]TM'; then + UTM_PID=$(ps ax -o pid,command | grep '/[U]TM'|cut -d' ' -f1) + read -r -e -p "Running at $UTM_PID. Kill? (y/N)" -i "n" answer + case "$answer" in + y | Y | yes ) kill "$UTM_PID" ;; + *) echo "don't stop UTM. abort."; exit ;; + esac + fi + ''; + }; packages.nixosCreate = pkgs.writeShellApplication { name = "nixosCreate"; runtimeInputs = [ @@ -96,45 +111,44 @@ self'.packages.utm self'.packages.nixosCmd self'.packages.nixosIP + self'.packages.killUTM inputs'.nixos-anywhere.packages.default ]; text = '' UTM_DATA_DIR="$HOME/Library/Containers/com.utmapp.UTM/Data/Documents"; NAME=$NIXOS_NAME - VM_ID=$(uuidgen) #MAC_ADDR=$(tr -dc A-F0-9 < /dev/urandom | head -c 10 | sed -r 's/(..)/\1:/g;s/:$//;s/^/02:/') MAC_ADDR=$(md5sum <<< "$NAME" | head -c 10 | sed -r 's/(..)/\1:/g;s/:$//;s/^/02:/') - FOLDER="$UTM_DATA_DIR/$NAME.utm" - if [ -e "$FOLDER" ]; then - read -r -e -p "The VM [$NAME] exists: should the folder $FOLDER be deleted (y/N)" -i "n" answer + if utmctl list | grep "$NAME" ; then + read -r -e -p "The VM [$NAME] exists: should the VM be deleted (y/N)" -i "n" answer case "$answer" in - y | Y | yes ) rm -rf "$FOLDER" ;; + y | Y | yes ) utmctl stop "$NAME"; utmctl delete "$NAME" ;; *) echo "keep existing VM. abort."; exit ;; esac fi - # shellcheck disable=SC2009 - if ps aux | grep '[U]TM'; then - UTM_PID=$(ps ax -o pid,command | grep '[U]TM'|cut -d' ' -f1) - read -r -e -p "Running at $UTM_PID. Kill? (y/N)" -i "n" answer - case "$answer" in - y | Y | yes ) kill "$UTM_PID" ;; - *) echo "don't stop UTM. abort."; exit ;; - esac - fi - mkdir -p "$FOLDER/Data" - set -x - install -m 600 ${./efi_vars.fd} "$FOLDER/Data/efi_vars.fd" - sed -e "s/XXX_NAME/$NAME/g;s/XXX_VM_ID/$VM_ID/g" ${./config.plist} > "$FOLDER/config.plist" - utmctl start "$NAME" - utmctl stop "$NAME" - sleep 1 + echo "create the VM [$NAME] with applescript" osascript ${./setupVM.osa} "$NAME" "$MAC_ADDR" ${self'.packages.nixosImg} sleep 2 # sometimes iso is not recognised.. maybe sleep helps + echo "configure the VM with plutil" + FOLDER="$UTM_DATA_DIR/$NAME.utm" + CFG="$FOLDER"/config.plist + plutil -insert "Display.0" -json '{ "HeightPixels": 1200, "PixelsPerInch": 226, "WidthPixels": 1920 }' "$CFG" + plutil -replace "Virtualization.Rosetta" -bool true "$CFG" + plutil -replace "Virtualization.Keyboard" -bool true "$CFG" + plutil -replace "Virtualization.Trackpad" -bool true "$CFG" + plutil -replace "Virtualization.Pointer" -bool true "$CFG" + plutil -replace "Virtualization.Keybaord" -bool true "$CFG" + plutil -replace "Virtualization.ClipboardSharing" -bool true "$CFG" + plutil -replace "Virtualization.Audio" -bool false "$CFG" + plutil -replace "Virtualization.Balloon" -bool true "$CFG" + echo "refresh UTMs view of the configuration" + killUTM + utmctl start "$NAME" while ! nixosCmd ls | grep nixos ; do echo "VM $NAME not yet running" diff --git a/setupVM.osa b/setupVM.osa index 2d315db..4e28873 100644 --- a/setupVM.osa +++ b/setupVM.osa @@ -4,11 +4,9 @@ on run argv set iso_path to item 3 of argv set iso to "file://" & iso_path as POSIX file tell application "UTM" - set vm to virtual machine named vm_name - set config to configuration of vm - set end of drives of config to {guest size:65536} - set end of drives of config to {source:iso, removable:true} - set end of network interfaces of config to {address:vm_mac, mode:shared} - update configuration of vm with config + set theDrive to {{guest size:65536}, {removable:true, source:iso}} + set theNetwork to {{address:vm_mac, mode:shared}} + set theConfiguration to {name:vm_name, architecture:"aarch64", drives:theDrive, network interfaces:theNetwork} + set vm to make new virtual machine with properties {backend:apple, configuration:theConfiguration} end tell end run