From 1d5b1cf5e09935f448e73057ef73f1969b01d5ab Mon Sep 17 00:00:00 2001 From: mjallen18 Date: Fri, 2 Jan 2026 11:05:48 -0600 Subject: [PATCH] check --- modules/nixos/boot/common/default.nix | 2 + .../nixos/hardware/raspberry-pi/default.nix | 5 ++ .../hardware/raspberry-pi/uefi-builder.sh | 3 +- qemu.nix | 74 +++++++++++++++---- systems/aarch64-linux/pi4/boot.nix | 2 +- 5 files changed, 67 insertions(+), 19 deletions(-) diff --git a/modules/nixos/boot/common/default.nix b/modules/nixos/boot/common/default.nix index 10d4eda..6ca38c4 100644 --- a/modules/nixos/boot/common/default.nix +++ b/modules/nixos/boot/common/default.nix @@ -24,6 +24,8 @@ in config = mkIf cfg.enable { boot = { + kernelModules = [ "kvm" ]; + binfmt = lib.mkIf isArm { registrations."x86_64-linux" = { magicOrExtension = ''\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00''; diff --git a/modules/nixos/hardware/raspberry-pi/default.nix b/modules/nixos/hardware/raspberry-pi/default.nix index 49dfd88..79ac1a8 100644 --- a/modules/nixos/hardware/raspberry-pi/default.nix +++ b/modules/nixos/hardware/raspberry-pi/default.nix @@ -186,6 +186,11 @@ in useGenerationDeviceTree = lib.mkOverride 60 (if cfg.bootType == "uefi" then false else true); }; systemd-boot.enable = (if cfg.bootType == "uefi" then true else false); + systemd-boot.extraInstallCommands = let + bootloaderInstaller = (if cfg.bootType == "uefi" then (builder."uefi") else (builder."uboot")); # todo + in '' + ${bootloaderInstaller} -f /boot/firmware -b /boot -c + ''; grub.enable = lib.mkForce false; }; }; diff --git a/modules/nixos/hardware/raspberry-pi/uefi-builder.sh b/modules/nixos/hardware/raspberry-pi/uefi-builder.sh index f0b69e3..79fab2f 100644 --- a/modules/nixos/hardware/raspberry-pi/uefi-builder.sh +++ b/modules/nixos/hardware/raspberry-pi/uefi-builder.sh @@ -42,9 +42,8 @@ if [ -n "$fwtarget" ]; then @firmwareBuilder@ -c $default -d $fwtarget echo "copying uefi firmware..." - #for file in "@uefi@/*"; do + rm -rf $fwtarget/* copyForced @uefi@ $fwtarget/ - #done fi echo "uefi bootloader installed" diff --git a/qemu.nix b/qemu.nix index 65012ae..a5d48a3 100644 --- a/qemu.nix +++ b/qemu.nix @@ -1,25 +1,67 @@ -with import { }; +{ pkgs ? import {} }: -writeShellApplication { +pkgs.writeShellApplication { name = "test-image"; - runtimeInputs = [ qemu ]; + runtimeInputs = [ + pkgs.qemu + pkgs.OVMF + ]; text = '' - if [ -z "$1" ]; then - echo "Usage: $0 " + set -euo pipefail + + if [ $# -lt 1 ]; then + echo "Usage: $0 [x86_64|aarch64]" >&2 exit 1 fi - tmpFile=$(mktemp /home/matt/tmp/test-image.XXXXXX) - trap 'rm -f $tmpFile' EXIT - cp "$1" "$tmpFile" - qemu-system-x86_64 \ - -enable-kvm \ - -m 4G \ - -cpu max \ - -smp 4 \ + + img="$1" + arch="''\${2:-$(uname -m)}" + + accel=( -accel kvm ) + [ -e /dev/kvm ] || accel=( -accel "tcg,thread=multi" ) + + case "$arch" in + x86_64|amd64) + qemu_bin="qemu-system-x86_64" + machine=( -machine q35 ) + cpu=( -cpu max ) + smp=( -smp 4 ) + ram=( -m 4G ) + pflash_code=( -drive "if=pflash,format=raw,readonly=on,file=${pkgs.OVMF.firmware}" ) + pflash_vars=( -drive "if=pflash,format=raw,readonly=on,file=${pkgs.OVMF.variables}" ) + ;; + aarch64|arm64) + qemu_bin="qemu-system-aarch64" + machine=( -machine virt ) + cpu=( -cpu host ) + smp=( -smp 4 ) + ram=( -m 4G ) + # Copy VARS to a writable temp file; QEMU opens it read/write + varsTmp=$(mktemp /tmp/AAVMF_VARS.fd.XXXXXX) + cp ${pkgs.OVMF.fd}/FV/AAVMF_VARS.fd "$varsTmp" + pflash_code=( -drive "if=pflash,format=raw,readonly=on,file=${pkgs.OVMF.fd}/FV/AAVMF_CODE.fd" ) + pflash_vars=( -drive "if=pflash,format=raw,file=$varsTmp" ) + ;; + *) + echo "Unsupported arch: $arch" >&2 + exit 1 + ;; + esac + + tmpFile=$(mktemp /tmp/test-image.XXXXXX) + trap 'rm -f "$tmpFile"' EXIT + cp "$img" "$tmpFile" + + "$qemu_bin" \ + "''\${accel[@]}" \ + "''\${machine[@]}" \ + "''\${cpu[@]}" \ + "''\${ram[@]}" \ + "''\${smp[@]}" \ -netdev user,id=net0,hostfwd=tcp::2222-:22 \ -device virtio-net-pci,netdev=net0 \ - -drive if=pflash,format=raw,readonly=on,file=${OVMF.firmware} \ - -drive if=pflash,format=raw,readonly=on,file=${OVMF.variables} \ + "''\${pflash_code[@]}" \ + "''\${pflash_vars[@]}" \ -drive "if=virtio,format=raw,file=$tmpFile" ''; -} +} \ No newline at end of file diff --git a/systems/aarch64-linux/pi4/boot.nix b/systems/aarch64-linux/pi4/boot.nix index 21c4689..e7f6970 100755 --- a/systems/aarch64-linux/pi4/boot.nix +++ b/systems/aarch64-linux/pi4/boot.nix @@ -14,7 +14,7 @@ in # variant = "4"; # }; # kernelPackages = kernelBundle.linuxPackages_rpi4; - kernelPackages = pkgs.${namespace}.linuxPackages_rpi4; + kernelPackages = pkgs.linuxPackages_latest; supportedFilesystems = lib.mkForce [ ]; };