diff --git a/nixos/lib/make-disk-image.nix b/nixos/lib/make-disk-image.nix index d418a4146294..b63c64f0188b 100644 --- a/nixos/lib/make-disk-image.nix +++ b/nixos/lib/make-disk-image.nix @@ -731,19 +731,28 @@ let ''} ${lib.optionalString installBootLoader '' - # In this throwaway resource, we only have /dev/vda, but the actual VM may refer to another disk for bootloader, e.g. /dev/vdb - # Use this option to create a symlink from vda to any arbitrary device you want. - ${lib.optionalString (config.boot.loader.grub.enable) ( - lib.concatMapStringsSep " " ( - device: - lib.optionalString (device != "/dev/vda") '' - mkdir -p "$(dirname ${device})" - ln -s /dev/vda ${device} - '' - ) config.boot.loader.grub.devices - )} + # In this throwaway resource, we only have /dev/vda, but the actual VM may refer to another disk for bootloader, e.g. /dev/vdb + # Use this option to create a symlink from vda to any arbitrary device you want. + ${lib.optionalString (config.boot.loader.grub.enable) ( + lib.concatMapStringsSep " " ( + device: + lib.optionalString (device != "/dev/vda") '' + mkdir -p "$(dirname ${device})" + ln -s /dev/vda ${device} + '' + ) config.boot.loader.grub.devices + )} + ${ + let + limine = config.boot.loader.limine; + in + lib.optionalString (limine.enable && limine.biosSupport && limine.biosDevice != "/dev/vda") '' + mkdir -p "$(dirname ${limine.biosDevice})" + ln -s /dev/vda ${limine.biosDevice} + '' + } - # Set up core system link, bootloader (sd-boot, GRUB, uboot, etc.), etc. + # Set up core system link, bootloader (sd-boot, GRUB, uboot, etc.), etc. # NOTE: systemd-boot-builder.py calls nix-env --list-generations which # clobbers $HOME/.nix-defexpr/channels/nixos This would cause a folder diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix index 068aa7efa0b1..ce1773a2f86c 100644 --- a/nixos/modules/virtualisation/qemu-vm.nix +++ b/nixos/modules/virtualisation/qemu-vm.nix @@ -1159,6 +1159,9 @@ in `useBootLoader` useless. You might want to disable one of those options. ''; + # Install Limine on the bootloader device + boot.loader.limine.biosDevice = cfg.bootLoaderDevice; + # In UEFI boot, we use a EFI-only partition table layout, thus GRUB will fail when trying to install # legacy and UEFI. In order to avoid this, we have to put "nodev" to force UEFI-only installs. # Otherwise, we set the proper bootloader device for this. diff --git a/nixos/tests/limine/bios.nix b/nixos/tests/limine/bios.nix new file mode 100644 index 000000000000..bc22af764c66 --- /dev/null +++ b/nixos/tests/limine/bios.nix @@ -0,0 +1,28 @@ +{ lib, ... }: +{ + name = "bios"; + meta.maintainers = with lib.maintainers; [ + lzcunt + phip1611 + programmerlexi + ]; + meta.platforms = [ + "i686-linux" + "x86_64-linux" + ]; + nodes.machine = + { ... }: + { + virtualisation.useBootLoader = true; + virtualisation.useBootPartition = true; + boot.loader.limine.enable = true; + boot.loader.limine.efiSupport = false; + boot.loader.timeout = 0; + }; + + testScript = '' + machine.start() + with subtest('Machine boots correctly'): + machine.wait_for_unit('multi-user.target') + ''; +} diff --git a/nixos/tests/limine/default.nix b/nixos/tests/limine/default.nix index dad761b1f882..6923fb4de62b 100644 --- a/nixos/tests/limine/default.nix +++ b/nixos/tests/limine/default.nix @@ -3,6 +3,7 @@ ... }: { + bios = runTest ./bios.nix; checksum = runTest ./checksum.nix; secureBoot = runTest ./secure-boot.nix; specialisations = runTest ./specialisations.nix;