From 0d8d418a912fcfa1a3a25fcdd738021e3b2b7c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=E2=80=9CNiols=E2=80=9D=20Jeannerod?= Date: Wed, 12 Feb 2025 11:03:25 +0100 Subject: [PATCH] Allow disabling QEMU VM-specific options --- infra/common/nixos/hardware.nix | 120 +++++++++++++++++++------------- infra/common/options.nix | 8 +++ 2 files changed, 79 insertions(+), 49 deletions(-) diff --git a/infra/common/nixos/hardware.nix b/infra/common/nixos/hardware.nix index c01ced2f..580f9526 100644 --- a/infra/common/nixos/hardware.nix +++ b/infra/common/nixos/hardware.nix @@ -1,62 +1,84 @@ -{ modulesPath, ... }: +{ config, lib, ... }: +let + inherit (lib) mkIf mkMerge; + +in { - imports = [ (modulesPath + "/profiles/qemu-guest.nix") ]; + config = mkMerge [ + { + boot.loader = { + systemd-boot.enable = true; + efi.canTouchEfiVariables = true; + }; + } - boot = { - loader = { - systemd-boot.enable = true; - efi.canTouchEfiVariables = true; - }; + (mkIf config.procolixVm.isQemuVm { - initrd = { - availableKernelModules = [ - "ata_piix" - "uhci_hcd" - "virtio_pci" - "virtio_scsi" - "sd_mod" - "sr_mod" - ]; - kernelModules = [ "dm-snapshot" ]; - }; - }; + boot.initrd = { + availableKernelModules = [ + "ata_piix" + "uhci_hcd" + "sd_mod" + "sr_mod" - disko.devices.disk.main = { - device = "/dev/sda"; - type = "disk"; + # from `/profiles/qemu-guest.nix` + "virtio_net" + "virtio_pci" + "virtio_mmio" + "virtio_blk" + "virtio_scsi" + "9p" + "9pnet_virtio" + ]; + kernelModules = [ + "dm-snapshot" - content = { - type = "gpt"; + # from `/profiles/qemu-guest.nix` + "virtio_balloon" + "virtio_console" + "virtio_rng" + "virtio_gpu" + ]; + }; - partitions = { - MBR = { - priority = 0; - size = "1M"; - type = "EF02"; - }; + disko.devices.disk.main = { + device = "/dev/sda"; + type = "disk"; - ESP = { - priority = 1; - size = "500M"; - type = "EF00"; - content = { - type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; - }; - }; + content = { + type = "gpt"; - root = { - priority = 2; - size = "100%"; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; + partitions = { + MBR = { + priority = 0; + size = "1M"; + type = "EF02"; + }; + + ESP = { + priority = 1; + size = "500M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + + root = { + priority = 2; + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; }; }; }; - }; - }; + }) + ]; } diff --git a/infra/common/options.nix b/infra/common/options.nix index 1236c01a..963d6d76 100644 --- a/infra/common/options.nix +++ b/infra/common/options.nix @@ -175,5 +175,13 @@ in this for testing machines, as it is a security hole for so many reasons. ''; }; + + isQemuVm = mkOption { + description = '' + Whether the machine is a QEMU VM. This will import all the necessary + things. + ''; + default = true; + }; }; }