-
-
Save betaboon/601795c1291b1657a65ae082a94149c6 to your computer and use it in GitHub Desktop.
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
diff --git a/nixos/lib/test-driver/test-driver.py b/nixos/lib/test-driver/test-driver.py | |
index fae7b9ab56a..a12613c3efb 100644 | |
--- a/nixos/lib/test-driver/test-driver.py | |
+++ b/nixos/lib/test-driver/test-driver.py | |
@@ -249,11 +249,11 @@ class Machine: | |
) | |
else: | |
start_command += ( | |
- "-drive file=" | |
+ "-drive id=hda,file=" | |
+ hda_path | |
- + ",if=" | |
- + args["hdaInterface"] | |
+ + ",if=none" | |
+ ",werror=report " | |
+ + "-device virtio-blk-pci,drive=hda,bootindex=0 " | |
) | |
if "cdrom" in args: | |
@@ -270,6 +270,20 @@ class Machine: | |
if "bios" in args: | |
start_command += "-bios " + args["bios"] + " " | |
+ # if "efiFirmware" in args: | |
+ # start_command += "-drive if=pflash,format=raw,readonly,file={} ".format( | |
+ # args["efiFirmware"] | |
+ # ) | |
+ # | |
+ # if "efiVars" in args: | |
+ # efi_vars_path = os.path.abspath("vm-state-machine/uefi_vars.bin") | |
+ # start_command = "cp {0} {1} && chmod +w {1} && ls -lah {1} && {2}".format( | |
+ # args["efiVars"], efi_vars_path, start_command | |
+ # ) | |
+ # start_command += "-drive if=pflash,format=raw,file={} ".format( | |
+ # efi_vars_path | |
+ # ) | |
+ # | |
start_command += args.get("qemuFlags", "") | |
return start_command | |
diff --git a/nixos/modules/system/boot/loader/refind/refind-builder.py b/nixos/modules/system/boot/loader/refind/refind-builder.py | |
index 0a9f65e067e..4c1807adeb4 100644 | |
--- a/nixos/modules/system/boot/loader/refind/refind-builder.py | |
+++ b/nixos/modules/system/boot/loader/refind/refind-builder.py | |
@@ -148,10 +148,14 @@ def write_refind_config(path, default_generation, generations): | |
**generation_details(*generation) | |
)) | |
- f.write(MENU_ENTRY.format( | |
- **generation_details(*default_generation), | |
- submenuentries="\n".join(submenuentries) | |
- )) | |
+ # FIXME - this fails when there are no generations | |
+ try: | |
+ f.write(MENU_ENTRY.format( | |
+ **generation_details(*default_generation), | |
+ submenuentries="\n".join(submenuentries) | |
+ )) | |
+ except: | |
+ pass | |
def main(): | |
@@ -184,6 +188,8 @@ def main(): | |
) | |
if os.getenv("NIXOS_INSTALL_BOOTLOADER") == "1": | |
+ # TODO is this required ? | |
+ subprocess.check_call(["modprobe", "efivars"]) | |
subprocess.check_call( | |
["@refind@/bin/refind-install", "--yes"], | |
env={"PATH": ":".join([ | |
diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix | |
index e313d2b411b..afcf7f9bf32 100644 | |
--- a/nixos/modules/virtualisation/qemu-vm.nix | |
+++ b/nixos/modules/virtualisation/qemu-vm.nix | |
@@ -101,8 +101,10 @@ let | |
${if cfg.useEFIBoot then '' | |
# VM needs a writable flash BIOS. | |
- cp ${bootDisk}/bios.bin $TMPDIR || exit 1 | |
- chmod 0644 $TMPDIR/bios.bin || exit 1 | |
+ cp ${bootDisk}/efi_firmware.bin $TMPDIR || exit 1 | |
+ cp ${bootDisk}/efi_vars.bin $TMPDIR || exit 1 | |
+ chmod 0444 $TMPDIR/efi_firmware.bin || exit 1 | |
+ chmod 0644 $TMPDIR/efi_vars.bin || exit 1 | |
'' else '' | |
''} | |
'' else '' | |
@@ -147,18 +149,26 @@ let | |
'' | |
mkdir $out | |
diskImage=$out/disk.img | |
- bootFlash=$out/bios.bin | |
+ efiFirmware=$out/efi_firmware.bin | |
+ efiVars=$out/efi_vars.bin | |
${qemu}/bin/qemu-img create -f qcow2 $diskImage "40M" | |
${if cfg.useEFIBoot then '' | |
- cp ${pkgs.OVMF-CSM.fd}/FV/OVMF.fd $bootFlash | |
- chmod 0644 $bootFlash | |
+ cp ${pkgs.OVMF.fd}/FV/OVMF_CODE.fd $efiFirmware | |
+ chmod 0444 $efiFirmware | |
+ cp ${pkgs.OVMF.fd}/FV/OVMF_VARS.fd $efiVars | |
+ chmod 0644 $efiVars | |
'' else '' | |
''} | |
''; | |
+ | |
buildInputs = [ pkgs.utillinux ]; | |
QEMU_OPTS = if cfg.useEFIBoot | |
- then "-pflash $out/bios.bin -nographic -serial pty" | |
- else "-nographic -serial pty"; | |
+ then builtins.concatStringsSep " " [ | |
+ "-nographic" | |
+ "-drive if=pflash,format=raw,readonly,file=$efiFirmware" | |
+ "-drive if=pflash,format=raw,file=$efiVars" | |
+ ] | |
+ else "-nographic"; | |
} | |
'' | |
# Create a /boot EFI partition with 40M and arbitrary but fixed GUIDs for reproducibility | |
@@ -192,6 +202,8 @@ let | |
# Install GRUB and generate the GRUB boot menu. | |
touch /etc/NIXOS | |
mkdir -p /nix/var/nix/profiles | |
+ # FIXME why is this required ? | |
+ export USER=root | |
${config.system.build.toplevel}/bin/switch-to-configuration boot | |
umount /boot | |
@@ -504,13 +516,14 @@ in | |
(mkIf (pkgs.stdenv.isAarch32 || pkgs.stdenv.isAarch64) [ | |
"-device virtio-gpu-pci" "-device usb-ehci,id=usb0" "-device usb-kbd" "-device usb-tablet" | |
]) | |
- (mkIf (!cfg.useBootLoader) [ | |
+ (mkIf (!cfg.useBootLoader || (cfg.useBootLoader && cfg.useEFIBoot)) [ | |
"-kernel ${config.system.build.toplevel}/kernel" | |
"-initrd ${config.system.build.toplevel}/initrd" | |
''-append "$(cat ${config.system.build.toplevel}/kernel-params) init=${config.system.build.toplevel}/init regInfo=${regInfo}/registration ${consoles} $QEMU_KERNEL_PARAMS"'' | |
]) | |
(mkIf cfg.useEFIBoot [ | |
- "-pflash $TMPDIR/bios.bin" | |
+ "-drive if=pflash,format=raw,readonly,file=$TMP/efi_firmware.bin" | |
+ "-drive if=pflash,format=raw,file=$TMP/efi_vars.bin" | |
]) | |
(mkIf (!cfg.graphics) [ | |
"-nographic" | |
@@ -520,11 +533,13 @@ in | |
virtualisation.qemu.drives = mkMerge [ | |
(mkIf cfg.useBootLoader [ | |
{ | |
+ # should be the 8G device | |
file = "$NIX_DISK_IMAGE"; | |
driveExtraOpts.cache = "writeback"; | |
driveExtraOpts.werror = "report"; | |
} | |
{ | |
+ # should be the disk containing efi firmware | |
file = "$TMPDIR/disk.img"; | |
driveExtraOpts.media = "disk"; | |
deviceExtraOpts.bootindex = "1"; | |
diff --git a/nixos/tests/installer.nix b/nixos/tests/installer.nix | |
index 50a980aab02..01efe28ed45 100644 | |
--- a/nixos/tests/installer.nix | |
+++ b/nixos/tests/installer.nix | |
@@ -47,7 +47,6 @@ let | |
${optionalString (bootLoader == "refind") '' | |
boot.loader.refind.enable = true; | |
- boot.loader.refind.installAsRemovable = true; # required as initial nixos-install is run in bios-mode | |
''} | |
users.users.alice = { | |
@@ -84,15 +83,15 @@ let | |
qemuFlags = | |
(if system == "x86_64-linux" then "-m 768 " else "-m 512 ") + | |
(optionalString (system == "x86_64-linux") "-cpu kvm64 ") + | |
- (optionalString (system == "aarch64-linux") "-enable-kvm -machine virt,gic-version=host -cpu host "); | |
+ (optionalString (system == "aarch64-linux") "-enable-kvm -machine virt,gic-version=host -cpu host ") + | |
+ (optionalString isEfi | |
+ "-drive if=pflash,format=raw,readonly,file=/build/efi_firmware.bin " + | |
+ "-drive if=pflash,format=raw,file=/build/efi_vars.bin " | |
+ ); | |
hda = "vm-state-machine/machine.qcow2"; | |
hdaInterface = iface; | |
- } // (optionalAttrs isEfi { | |
- bios = if pkgs.stdenv.isAarch64 | |
- then "${pkgs.OVMF.fd}/FV/QEMU_EFI.fd" | |
- else "${pkgs.OVMF.fd}/FV/OVMF.fd"; | |
- }))); | |
+ })); | |
in if !isEfi && !(pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) then | |
throw "Non-EFI boot methods are only supported on i686 / x86_64" | |
@@ -152,7 +151,7 @@ let | |
${if bootLoader == "grub" then | |
''machine.succeed("test -e /boot/grub")'' | |
else if bootLoader == "refind" then | |
- ''machine.succeed("test -e /boot/EFI/BOOT/refind.conf")'' | |
+ ''machine.succeed("test -e /boot/EFI/refind/refind.conf")'' | |
else | |
''machine.succeed("test -e /boot/loader/loader.conf")'' | |
} | |
@@ -288,12 +287,18 @@ let | |
# the same during and after installation. | |
virtualisation.emptyDiskImages = [ 512 ]; | |
virtualisation.bootDevice = | |
- if grubVersion == 1 then "/dev/sdb" else "/dev/vdb"; | |
+ if grubVersion == 1 then "/dev/sdb" else "/dev/vdc"; | |
virtualisation.qemu.diskInterface = | |
if grubVersion == 1 then "scsi" else "virtio"; | |
+ virtualisation.useBootLoader = true; | |
+ virtualisation.useEFIBoot = true; | |
+ | |
boot.loader.systemd-boot.enable = mkIf (bootLoader == "systemd-boot") true; | |
- boot.loader.refind.enable = mkIf (bootLoader == "refind") true; | |
+ boot.loader.refind = mkIf (bootLoader == "refind") { | |
+ enable = true; | |
+ installAsRemovable = true; | |
+ }; | |
hardware.enableAllFirmware = mkForce false; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment