mirror of
https://github.com/ciderale/nixos-utm.git
synced 2024-12-14 11:37:37 +00:00
create VM completly with setupVM.osa
This commit is contained in:
parent
41c9a0cb5a
commit
eccaa631df
4 changed files with 39 additions and 107 deletions
80
config.plist
80
config.plist
|
@ -1,80 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>Backend</key>
|
|
||||||
<string>Apple</string>
|
|
||||||
<key>ConfigurationVersion</key>
|
|
||||||
<integer>4</integer>
|
|
||||||
<key>Display</key>
|
|
||||||
<array>
|
|
||||||
<dict>
|
|
||||||
<key>HeightPixels</key>
|
|
||||||
<integer>1200</integer>
|
|
||||||
<key>PixelsPerInch</key>
|
|
||||||
<integer>226</integer>
|
|
||||||
<key>WidthPixels</key>
|
|
||||||
<integer>1920</integer>
|
|
||||||
</dict>
|
|
||||||
</array>
|
|
||||||
<key>Drive</key>
|
|
||||||
<array>
|
|
||||||
</array>
|
|
||||||
<key>Information</key>
|
|
||||||
<dict>
|
|
||||||
<key>IconCustom</key>
|
|
||||||
<false/>
|
|
||||||
<key>Name</key>
|
|
||||||
<string>XXX_NAME</string>
|
|
||||||
<key>UUID</key>
|
|
||||||
<string>XXX_VM_ID</string>
|
|
||||||
</dict>
|
|
||||||
<key>Network</key>
|
|
||||||
<array>
|
|
||||||
</array>
|
|
||||||
<key>Serial</key>
|
|
||||||
<array>
|
|
||||||
<dict>
|
|
||||||
<key>Mode</key>
|
|
||||||
<string>Ptty</string>
|
|
||||||
</dict>
|
|
||||||
</array>
|
|
||||||
<key>System</key>
|
|
||||||
<dict>
|
|
||||||
<key>Architecture</key>
|
|
||||||
<string>aarch64</string>
|
|
||||||
<key>Boot</key>
|
|
||||||
<dict>
|
|
||||||
<key>EfiVariableStoragePath</key>
|
|
||||||
<string>efi_vars.fd</string>
|
|
||||||
<key>OperatingSystem</key>
|
|
||||||
<string>Linux</string>
|
|
||||||
<key>UEFIBoot</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
<key>CPUCount</key>
|
|
||||||
<integer>2</integer>
|
|
||||||
<key>MemorySize</key>
|
|
||||||
<integer>4096</integer>
|
|
||||||
</dict>
|
|
||||||
<key>Virtualization</key>
|
|
||||||
<dict>
|
|
||||||
<key>Audio</key>
|
|
||||||
<false/>
|
|
||||||
<key>Balloon</key>
|
|
||||||
<true/>
|
|
||||||
<key>ClipboardSharing</key>
|
|
||||||
<true/>
|
|
||||||
<key>Entropy</key>
|
|
||||||
<true/>
|
|
||||||
<key>Keyboard</key>
|
|
||||||
<true/>
|
|
||||||
<key>Pointer</key>
|
|
||||||
<true/>
|
|
||||||
<key>Rosetta</key>
|
|
||||||
<true/>
|
|
||||||
<key>Trackpad</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
BIN
efi_vars.fd
BIN
efi_vars.fd
Binary file not shown.
56
flake.nix
56
flake.nix
|
@ -85,6 +85,21 @@
|
||||||
ssh "root@$(nixosIP)" "$@"
|
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 {
|
packages.nixosCreate = pkgs.writeShellApplication {
|
||||||
name = "nixosCreate";
|
name = "nixosCreate";
|
||||||
runtimeInputs = [
|
runtimeInputs = [
|
||||||
|
@ -96,45 +111,44 @@
|
||||||
self'.packages.utm
|
self'.packages.utm
|
||||||
self'.packages.nixosCmd
|
self'.packages.nixosCmd
|
||||||
self'.packages.nixosIP
|
self'.packages.nixosIP
|
||||||
|
self'.packages.killUTM
|
||||||
inputs'.nixos-anywhere.packages.default
|
inputs'.nixos-anywhere.packages.default
|
||||||
];
|
];
|
||||||
text = ''
|
text = ''
|
||||||
UTM_DATA_DIR="$HOME/Library/Containers/com.utmapp.UTM/Data/Documents";
|
UTM_DATA_DIR="$HOME/Library/Containers/com.utmapp.UTM/Data/Documents";
|
||||||
|
|
||||||
NAME=$NIXOS_NAME
|
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=$(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:/')
|
MAC_ADDR=$(md5sum <<< "$NAME" | head -c 10 | sed -r 's/(..)/\1:/g;s/:$//;s/^/02:/')
|
||||||
|
|
||||||
|
|
||||||
FOLDER="$UTM_DATA_DIR/$NAME.utm"
|
if utmctl list | grep "$NAME" ; then
|
||||||
if [ -e "$FOLDER" ]; then
|
read -r -e -p "The VM [$NAME] exists: should the VM be deleted (y/N)" -i "n" answer
|
||||||
read -r -e -p "The VM [$NAME] exists: should the folder $FOLDER be deleted (y/N)" -i "n" answer
|
|
||||||
case "$answer" in
|
case "$answer" in
|
||||||
y | Y | yes ) rm -rf "$FOLDER" ;;
|
y | Y | yes ) utmctl stop "$NAME"; utmctl delete "$NAME" ;;
|
||||||
*) echo "keep existing VM. abort."; exit ;;
|
*) echo "keep existing VM. abort."; exit ;;
|
||||||
esac
|
esac
|
||||||
fi
|
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"
|
echo "create the VM [$NAME] with applescript"
|
||||||
utmctl stop "$NAME"
|
|
||||||
sleep 1
|
|
||||||
osascript ${./setupVM.osa} "$NAME" "$MAC_ADDR" ${self'.packages.nixosImg}
|
osascript ${./setupVM.osa} "$NAME" "$MAC_ADDR" ${self'.packages.nixosImg}
|
||||||
sleep 2 # sometimes iso is not recognised.. maybe sleep helps
|
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"
|
utmctl start "$NAME"
|
||||||
while ! nixosCmd ls | grep nixos ; do
|
while ! nixosCmd ls | grep nixos ; do
|
||||||
echo "VM $NAME not yet running"
|
echo "VM $NAME not yet running"
|
||||||
|
|
10
setupVM.osa
10
setupVM.osa
|
@ -4,11 +4,9 @@ on run argv
|
||||||
set iso_path to item 3 of argv
|
set iso_path to item 3 of argv
|
||||||
set iso to "file://" & iso_path as POSIX file
|
set iso to "file://" & iso_path as POSIX file
|
||||||
tell application "UTM"
|
tell application "UTM"
|
||||||
set vm to virtual machine named vm_name
|
set theDrive to {{guest size:65536}, {removable:true, source:iso}}
|
||||||
set config to configuration of vm
|
set theNetwork to {{address:vm_mac, mode:shared}}
|
||||||
set end of drives of config to {guest size:65536}
|
set theConfiguration to {name:vm_name, architecture:"aarch64", drives:theDrive, network interfaces:theNetwork}
|
||||||
set end of drives of config to {source:iso, removable:true}
|
set vm to make new virtual machine with properties {backend:apple, configuration:theConfiguration}
|
||||||
set end of network interfaces of config to {address:vm_mac, mode:shared}
|
|
||||||
update configuration of vm with config
|
|
||||||
end tell
|
end tell
|
||||||
end run
|
end run
|
||||||
|
|
Loading…
Reference in a new issue