kvm.nix/nixos-options.md

13 KiB
Raw Permalink Blame History

kvm.instances

KVM instances.

Type: attribute set of (submodule)

Default: { }

Example:

{
  my-vm = {
    cores = 2;
    memory = 4096; # MB

    networking.enable = true;
    networking.ipv4 = {
      address = "10.0.0.1"; # /31
      gateway = "10.0.0.0";
    };

    nixos.enable = true;
    nixos.config = {
      # NixOS VM config
      services.openssh.enable = true;
    };
  };
}

Declared by:

kvm.instances.<name>.boot

How to boot the VM.

Type: attribute-tagged union

Declared by:

kvm.instances.<name>.boot.efi

Boot via UEFI.

Type: submodule

Declared by:

kvm.instances.<name>.boot.efi.firmwarePackage

KVM firmware package.

Type: package

Default:

{
  cloud-hypervisor = pkgs.OVMF-cloud-hypervisor;
  qemu = pkgs.OVMF;
}
.${config.hypervisor}

kvm.instances.<name>.boot.linux

Boot directly into a Linux system.

Type: submodule

Declared by:

kvm.instances.<name>.boot.linux.cmdline

Kernel command line.

Type: string

kvm.instances.<name>.boot.linux.initrd

Initrd path.

Type: absolute path

kvm.instances.<name>.boot.linux.kernel

Kernel path.

Type: absolute path

kvm.instances.<name>.cdrom

Path of an ISO file to add to the VM as a cdrom.

Type: null or absolute path

Default: null

Declared by:

kvm.instances.<name>.cores

Number of CPU cores to assign to the VM.

Type: positive integer, meaning >0

Declared by:

kvm.instances.<name>.disks

Disks that should be provided to the VM.

Type: attribute set of (submodule)

Default: { }

Declared by:

kvm.instances.<name>.disks.<name>.path

Path of the raw disk image. This file can be created using qemu-img create -f raw -o nocow=on <path> <size>

Type: absolute path

Declared by:

kvm.instances.<name>.disks.<name>.readOnly

Whether to make this disk read-only.

Type: boolean

Default: false

Declared by:

kvm.instances.<name>.hypervisor

Which hypervisor to use for this instance.

Type: one of “cloud-hypervisor”, “qemu”

Default: "cloud-hypervisor"

Declared by:

kvm.instances.<name>.hypervisorArgs

List of arguments passed directly to the hypervisor.

Type: list of string

Declared by:

kvm.instances.<name>.hypervisorPackage

The hypervisor package to use for this instance.

Type: package

Default:

{
  cloud-hypervisor = pkgs.cloud-hypervisor;
  qemu = pkgs.qemu_kvm;
}
.${config.hypervisor};

Declared by:

kvm.instances.<name>.interactive

Whether to add a kvm-<name>-console binary to the system path to connect to the VM console.

Type: boolean

Default: false

Declared by:

kvm.instances.<name>.memory

How much memory to assign to the VM (in MB).

Type: positive integer, meaning >0

Declared by:

kvm.instances.<name>.networking.enable

Whether to enable networking for this instance.

Type: boolean

Default: false

Example: true

Declared by:

kvm.instances.<name>.networking.dev

Name of the tap device on the host.

Type: string

Default: "kvm-${hash name}"

Declared by:

kvm.instances.<name>.networking.ipv4

IPv4 networking configuration.

Type: null or (submodule)

Default: null

Declared by:

kvm.instances.<name>.networking.ipv4.address

IPv4 address of the VM.

Type: null or string

Default: null

Declared by:

kvm.instances.<name>.networking.ipv4.gateway

IPv4 address of the host.

Type: string

Declared by:

kvm.instances.<name>.networking.ipv4.prefixLength

Length of the subnet prefix.

Type: integer between 0 and 32 (both inclusive)

Default: 31

Declared by:

kvm.instances.<name>.networking.ipv6

IPv6 networking configuration.

Type: null or (submodule)

Default: null

Declared by:

kvm.instances.<name>.networking.ipv6.address

IPv6 address of the VM.

Type: null or string

Default: null

Declared by:

kvm.instances.<name>.networking.ipv6.gateway

IPv6 address of the host.

Type: string

Declared by:

kvm.instances.<name>.networking.ipv6.prefixLength

Length of the subnet prefix.

Type: integer between 0 and 128 (both inclusive)

Default: 64

Declared by:

kvm.instances.<name>.networking.mac

MAC address of the VM.

Type: string matching the pattern ([0-9a-f]{2}:){5}[0-9a-f]{2}

Default: "52:54:${macHash name}"

Declared by:

kvm.instances.<name>.nixos.enable

Whether to boot directly into a pre-configured NixOS system.

Type: boolean

Default: false

Declared by:

kvm.instances.<name>.nixos.config

NixOS configuration of this instance.

Type: Toplevel NixOS config

Declared by:

kvm.instances.<name>.nixos.nixpkgs

Path to the nixpkgs that provide the modules, pkgs and lib for evaluating this instance.

Type: absolute path

Default: pkgs.path

Declared by:

kvm.instances.<name>.nixos.specialArgs

Set of special arguments to be passed to NixOS modules.

Type: attribute set of unspecified value

Default: { }

Declared by:

kvm.instances.<name>.nixos.system

System to run in the VM.

Type: string

Default: pkgs.system

Declared by:

kvm.instances.<name>.nixos.writableStore

Whether to make the guest Nix store writable by layering an overlay filesystem on top of the hosts Nix store.

Type: boolean

Default: false

Declared by:

kvm.instances.<name>.sharedDirectories

Shared directories.

Type: attribute set of (submodule)

Default: { }

Declared by:

kvm.instances.<name>.sharedDirectories.<name>.cache

The caching policy which virtiofsd should use.

Type: one of “auto”, “always”, “never”, “metadata”

Default: "always"

Declared by:

kvm.instances.<name>.sharedDirectories.<name>.readOnly

Whether to make this shared directory read-only.

Type: boolean

Default: true

Declared by:

kvm.instances.<name>.sharedDirectories.<name>.source

Path of the source directory on the host. Defaults to the attribute name.

Type: absolute path

Declared by:

kvm.instances.<name>.sharedDirectories.<name>.tag

The virtiofs tag.

Type: string

Default: hash "${name} ${config.source}"

Declared by:

kvm.instances.<name>.sharedDirectories.<name>.target

Path of the target directory in the VM. Defaults to the attribute name.

Type: null or absolute path

Declared by:

kvm.instances.<name>.sharedDirectories.<name>.threadPoolSize

The maximum thread pool size for virtiofsd. Defaults to the number of host CPU cores.

Type: null or (unsigned integer, meaning >=0)

Default: null

Declared by:

kvm.instances.<name>.sharedDirectories.<name>.virtiofsdArgs

List of arguments passed to virtiofsd.

Type: list of string

Declared by:

kvm.instances.<name>.sharedDirectories.<name>.virtiofsdPackage

The virtiofsd package to use.

Type: package

Default: pkgs.virtiofsd

Declared by:

kvm.instances.<name>.vnc.enable

Whether to enable VNC for this instance.

Type: boolean

Default: false

Example: true

Declared by:

kvm.instances.<name>.vnc.display

The display to use for the VNC server. By convention the corresponding TCP port is 5900 + display.

Type: unsigned integer, meaning >=0

Declared by:

kvm.instances.<name>.vnc.powerControl

Whether to permit the remote client to issue shutdown, reboot or reset power control requests.

Type: boolean

Default: false

Declared by: