Last active
October 1, 2022 01:52
-
-
Save mweinelt/b7399e31a05e2e9659acf52b842a417c to your computer and use it in GitHub Desktop.
NixOS Installer Testing via QEMU aarch64 emulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env nix-shell | |
#!nix-shell -i bash -p qemu_full virt-viewer | |
# shellcheck shell=bash | |
set -euo pipefail | |
BASEDIR=$(dirname "$0") | |
VMNAME=nixos-aarch64 | |
ISO="${BASEDIR}/$1" | |
NVRAM="${BASEDIR}/vars-pflash.raw" | |
CORES=6 | |
MEMORY=4096 | |
KEYBOARD="de" | |
cleanup() { | |
kill "$QEMU_PID" || true | |
} | |
trap cleanup EXIT | |
run_vm() { | |
OVMF_FD=$(nix-build '<nixpkgs>' --no-out-link -A OVMF.fd --system aarch64-linux) | |
test -f "${NVRAM}" || { | |
cp "${OVMF_FD}/AAVMF/vars-template-pflash.raw" "${NVRAM}" | |
chmod u+w "${NVRAM}" | |
} | |
qemu-system-aarch64 \ | |
-name $VMNAME,process=$VMNAME \ | |
-machine virt,gic-version=max \ | |
--accel tcg,thread=multi \ | |
-cpu max \ | |
-smp $CORES \ | |
-m $MEMORY \ | |
-k $KEYBOARD \ | |
-serial stdio \ | |
-drive if=pflash,format=raw,file="${OVMF_FD}/AAVMF//QEMU_EFI-pflash.raw",readonly=on \ | |
-drive if=pflash,format=raw,file="${NVRAM}" \ | |
-device virtio-scsi-pci \ | |
-device virtio-gpu-pci \ | |
-device virtio-net-pci,netdev=wan \ | |
-netdev user,id=wan \ | |
-device virtio-rng-pci,rng=rng0 \ | |
-object rng-random,filename=/dev/urandom,id=rng0 \ | |
-device virtio-serial-pci \ | |
-drive file="${ISO}",media=cdrom \ | |
-boot d | |
QEMU_PID=$! | |
} | |
run_vm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment