From 2078204168c8e776b03079167bbdcf5001677984 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Tue, 15 Sep 2026 14:49:13 -0400 Subject: [PATCH] Fix bootstrap image: missing virtio drivers stranded it in initrd The bootstrap image (built from common.nix alone - nixos-generators supplies its own partitioning/bootloader, which is why hardware.nix is excluded from it) never got hardware.nix's qemu-guest.nix profile or virtio initrd modules. Both disks are virtio-blk, including the one the image itself boots from, so the initrd couldn't find its own root device: "Timed out waiting for device /dev/disk/by-label/nixos", dropping to emergency mode with root locked - confirmed live on hl-fwdesk. The label itself was correct (verified via a read-only losetup + blkid against the built image); the initrd genuinely had no virtio_blk/virtio_pci module and no qemu-guest.nix profile at all. Moved the qemu-guest.nix import and virtio_pci/virtio_blk/virtio_scsi initrd modules from hardware.nix into common.nix, which both the bootstrap build and the guest's own post-first-boot flake (via guest/flake.nix importing both files) pull in. hardware.nix keeps only the partition-specific fileSystems/bootloader config, which genuinely does need to stay out of the bootstrap build. Co-Authored-By: Claude Sonnet 5 --- guest/common.nix | 12 +++++++++++- guest/hardware.nix | 17 +++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/guest/common.nix b/guest/common.nix index 86e9c36..39152ff 100644 --- a/guest/common.nix +++ b/guest/common.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, modulesPath, ... }: let # These must match services.hermenix.* on the host. If you changed the @@ -21,6 +21,16 @@ let useHostCache = cachePublicKey != ""; in { + # Both disks are virtio-blk, including the one this very image boots from + # (see modules/host.nix's qemu invocation) - so this has to be here, not + # only in hardware.nix. hardware.nix is excluded from this image's build + # (nixos-generators supplies its own partitioning/bootloader instead), but + # driver support for the VM environment itself is needed either way. + imports = [ (modulesPath + "/profiles/qemu-guest.nix") ]; + boot.initrd.availableKernelModules = [ + "virtio_pci" "virtio_blk" "virtio_scsi" "ahci" "sd_mod" "xhci_pci" + ]; + networking.hostName = "hermes"; # ===================================================================== diff --git a/guest/hardware.nix b/guest/hardware.nix index 8c61b21..e2b1c73 100644 --- a/guest/hardware.nix +++ b/guest/hardware.nix @@ -1,8 +1,11 @@ -{ lib, modulesPath, ... }: +{ lib, ... }: -# Only used by the guest's own /etc/nixos flake. The bootstrap image gets its -# partitioning and bootloader from nixos-generators instead, which is why -# this is kept out of common.nix. +# Only used by the guest's own /etc/nixos flake (see guest/flake.nix). The +# bootstrap image gets its partitioning and bootloader from nixos-generators +# instead, which is why fileSystems/bootloader are kept out of common.nix - +# but driver support for the VM environment (qemu-guest.nix profile, virtio +# initrd modules) lives in common.nix instead, since the bootstrap image +# needs that too. See common.nix if you're looking for that. # # VERIFY THE LABELS on first boot with `lsblk -f`. nixos-generators names the # root partition "nixos" and the ESP "ESP", but check rather than trust, and @@ -10,8 +13,6 @@ # produces a system that will not boot. { - imports = [ (modulesPath + "/profiles/qemu-guest.nix") ]; - fileSystems."/" = { device = "/dev/disk/by-label/nixos"; fsType = "ext4"; @@ -26,9 +27,5 @@ boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = false; - boot.initrd.availableKernelModules = [ - "virtio_pci" "virtio_blk" "virtio_scsi" "ahci" "sd_mod" "xhci_pci" - ]; - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; }