NixOS in a VM won't boot, problem with btrfs?

I already run NixOS on my desktop (with btrfs), and I’ve created NixOS VMs before, but this is the first time trying to create a VM using btrfs. At least, that’s my only guess at what is different for it to not be working…

I use virt-manager (libvirtd) to create the VM, and boot it off of the 22.11 nixos minimal ISO. The VM boots fine, but after installing NixOS and rebooting, it just hangs at “Booting from Hard Disk”. Almost like it doesn’t even load the kernel?

Below is the installation script I’m using. Everything looks right as far as I can tell, and is similar to what I did for my desktop (though I didn’t write down the commands for that one). Any ideas?

#!/usr/bin/env bash


parted ${DISK} -- mklabel gpt
parted ${DISK} -- mkpart ESP fat32 1MB 512MB
parted ${DISK} -- set 1 esp on
parted ${DISK} -- mkpart primary 512MB 100%

mkfs.fat -F 32 -n boot ${DISK}1
mkfs.btrfs -f ${DISK}2

mount -t btrfs ${DISK}2 /mnt

btrfs subvolume create /mnt/root
btrfs subvolume create /mnt/home
btrfs subvolume create /mnt/nix
btrfs subvolume create /mnt/persist
btrfs subvolume create /mnt/log
btrfs subvolume create /mnt/swap

btrfs subvolume snapshot -r /mnt/root /mnt/root-blank
umount /mnt

mount -o subvol=root,compress=zstd,noatime ${DISK}2 /mnt
mkdir /mnt/home
mount -o subvol=home,compress=zstd,noatime ${DISK}2 /mnt/home
mkdir /mnt/nix
mount -o subvol=nix,compress=zstd,noatime ${DISK}2 /mnt/nix
mkdir /mnt/persist
mount -o subvol=persist,compress=zstd,noatime ${DISK}2 /mnt/persist
mkdir -p /mnt/var/log
mount -o subvol=log,compress=zstd,noatime ${DISK}2 /mnt/var/log
mkdir /mnt/swap
mount -o subvol=swap,noatime ${DISK}2 /mnt/swap
mkdir /mnt/boot
mount ${DISK}1 /mnt/boot

nixos-generate-config --root /mnt

cat > /mnt/etc/nixos/configuration.nix <<EOL
{ config, pkgs, ... }: {
  imports = [

  boot.kernelPackages = pkgs.linuxPackages_latest;
  boot.supportedFilesystems = [ "btrfs" ];
  hardware.enableAllFirmware = true;
  nixpkgs.config.allowUnfree = true;

  # Use the systemd-boot EFI boot loader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  networking.hostName = "zen"; # Define your hostname.

  system.stateVersion = "22.11";

# nixos-install --flake /mnt/etc/nixos#zen

Nevermind… I’m so used to doing UEFI installations on real hardware, I forgot to modify the VM to support UEFI. It works now. :slight_smile: