summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaito Bezarius <masterancpp@gmail.com>2023-04-28 17:01:22 +0200
committerRaito Bezarius <masterancpp@gmail.com>2024-02-11 17:50:37 +0100
commitfd110f5fea05d13f14621b41d361ce3d7346fd32 (patch)
treeb51d5edbd4a45d0b7855e81e12bd2ff257c437bb
parentnixos/virtualisation/qemu-vm: deep merge fileSystems (diff)
downloadnixpkgs-fd110f5fea05d13f14621b41d361ce3d7346fd32.tar.gz
nixos/tests/netboot: add directBoot test
This verifies that we can direct boot a netboot image as expected.
-rw-r--r--nixos/modules/installer/netboot/netboot.nix30
-rw-r--r--nixos/tests/boot.nix9
2 files changed, 38 insertions, 1 deletions
diff --git a/nixos/modules/installer/netboot/netboot.nix b/nixos/modules/installer/netboot/netboot.nix
index a50f22cbe471..fb9b6541853c 100644
--- a/nixos/modules/installer/netboot/netboot.nix
+++ b/nixos/modules/installer/netboot/netboot.nix
@@ -1,7 +1,7 @@
# This module creates netboot media containing the given NixOS
# configuration.
-{ config, lib, pkgs, ... }:
+{ options, config, lib, pkgs, ... }:
with lib;
@@ -41,6 +41,34 @@ with lib;
environment.systemPackages = [ pkgs.grub2_efi ]
++ (lib.optionals (pkgs.stdenv.hostPlatform.system != "aarch64-linux") [pkgs.grub2 pkgs.syslinux]);
+ # We only want to set those options in the context of
+ # the QEMU infrastructure.
+ virtualisation = lib.optionalAttrs (options ? virtualisation.directBoot) {
+ # By default, using netboot images in virtualized contexts
+ # should not create any disk image ideally, except if
+ # asked explicitly.
+ diskImage = mkDefault null;
+ # We do not want to mount the host Nix store in those situations.
+ mountHostNixStore = mkDefault false;
+ # We do not need the nix store image because:
+ # - either we boot through network and we have the squashfs image
+ # - either we direct boot, we have the squashfs image
+ useNixStoreImage = mkDefault false;
+ # Though, we still want a writable store through .rw-store
+ writableStore = mkDefault true;
+ # Ideally, we might not want to test the network / firmware.
+ directBoot = {
+ enable = mkDefault true;
+ # We need to use our netboot initrd which contains a copy of the Nix store.
+ initrd = "${config.system.build.netbootRamdisk}/${config.system.boot.loader.initrdFile}";
+ };
+ # We do not want to use the default filesystems.
+ useDefaultFilesystems = mkDefault false;
+ # Bump the default memory size as we are loading the whole initrd in RAM.
+ memorySize = mkDefault 1536;
+ };
+
+
fileSystems."/" = mkImageMediaOverride
{ fsType = "tmpfs";
options = [ "mode=0755" ];
diff --git a/nixos/tests/boot.nix b/nixos/tests/boot.nix
index ec2a9f6527c9..11fb817c77a7 100644
--- a/nixos/tests/boot.nix
+++ b/nixos/tests/boot.nix
@@ -104,6 +104,15 @@ in {
bios = uefiBinary;
};
+ directNetboot = makeTest {
+ name = "directboot-netboot";
+ nodes.machine = {
+ imports = [ ../modules/installer/netboot/netboot-minimal.nix ];
+ virtualisation.memorySize = 4096;
+ };
+ testScript = "machine.fail('stat /dev/vda')";
+ };
+
uefiNetboot = makeNetbootTest "uefi" {
bios = uefiBinary;
# Custom ROM is needed for EFI PXE boot. I failed to understand exactly why, because QEMU should still use iPXE for EFI.