Nixos-rebuild build-vm # option `virtualisation.cores' does not exist

nixos-rebuild build-vm

building Nix...
error: The option `virtualisation.cores' does not exist. Definition values:
       - In `/etc/nixos/configuration.nix': 6

  • system: "x86_64-linux"
  • host os: Linux 5.19.9, NixOS, 22.05 (Quokka), 22.05.3242.72783a2d0db
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.8.1
  • channels(root): "home-manager-22.05.tar.gz, nixos, nixpkgs"
  • channels(usera): ""
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

You probably missed

  imports = [ <nixpkgs/nixos/modules/virtualisation/qemu-vm.nix> ];

@igel , see Incomplete documentation for "build-vm" options (can be used only inside "virtualisation.vmVariant") · Issue #196755 · NixOS/nixpkgs · GitHub .

You must specify virtualisation.cores inside of virtualisation.vmVariant.

For example:

  virtualisation.vmVariant = {
    # following configuration is added only when building VM with build-vm
    virtualisation.cores = 1;
 - system: `"x86_64-linux"` 
 - host os: `Linux 5.15.104, NixOS, 22.11 (Raccoon), 22.11.3333.83607dae4e0` 
 - multi-user?: `yes` 
 - sandbox: `yes` 
 - version: `nix-env (Nix) 2.11.1` 
 - channels(root): `"nixgl, nixos-22.11, nixos-hardware"` 
 - channels(usera): `""` 
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

when trying to nixos-switch

imports = [ <nixpkgs/nixos/modules/virtualisation/qemu-vm.nix> ];

the result is

Found Windows Boot Manager on /dev/nvme0n1p1@/EFI/Microsoft/Boot/bootmgfw.efi
installing the GRUB 2 boot loader on /dev/vda...
Installing for i386-pc platform.
/nix/store/imdz3ipf50dh2wc7brbmdq0sk55x85g2-grub-2.06/sbin/grub-install: error: cannot find a GRUB drive for /dev/vda.  Check your
/nix/store/ installation of GRUB on /dev/vda failed: Inappropriate ioctl for device
warning: error(s) occurred while switching to the new configuration

You do not want to import qemu-vm.nix in your actual configuration; it does a lot of things to reconfigure the system for running in a VM. If you want to add settings for the build-vm command without changing your actual configuration, see the comment above and use virtualisation.vmVariant.

1 Like