vm.nix
1# What every host shares as a KVM virtual machine: disk layout (disko),
2# bootloader and hostname. Networking and resolvers depend on the provider
3# (modules/hetzner.nix, modules/netcup.nix). No provider offers a NixOS
4# image, so `just new-host` installs over the stock Debian image with
5# nixos-anywhere.
6#
7# `host` is this machine's entry from hosts.json (a specialArg).
8{ host, lib, modulesPath, ... }:
9
10{
11 imports = [ (modulesPath + "/profiles/qemu-guest.nix") ];
12
13 # One disk: BIOS boot partition + ESP + ext4 root. Some VMs boot legacy
14 # BIOS (Hetzner x86, netcup by default) and others UEFI (Hetzner arm64,
15 # netcup when switched), so GRUB is installed for both and the same layout
16 # serves either. The disk is whatever `just new-host` found on the box:
17 # /dev/sda on SCSI (Hetzner, netcup's SCSI option), /dev/vda on virtio.
18 disko.devices.disk.main = {
19 type = "disk";
20 device = host.disk or "/dev/sda";
21 content = {
22 type = "gpt";
23 partitions = {
24 bios = {
25 size = "1M";
26 type = "EF02";
27 priority = 1;
28 };
29 ESP = {
30 size = "512M";
31 type = "EF00";
32 content = {
33 type = "filesystem";
34 format = "vfat";
35 mountpoint = "/boot";
36 mountOptions = [ "umask=0077" ];
37 };
38 };
39 root = {
40 size = "100%";
41 content = {
42 type = "filesystem";
43 format = "ext4";
44 mountpoint = "/";
45 };
46 };
47 };
48 };
49 };
50
51 boot.loader.grub = {
52 enable = true;
53 efiSupport = true;
54 efiInstallAsRemovable = true;
55 };
56 boot.initrd.availableKernelModules = [
57 "ahci"
58 "xhci_pci"
59 "virtio_pci"
60 "virtio_scsi"
61 "virtio_blk"
62 "sd_mod"
63 "sr_mod"
64 ];
65
66 networking.hostName = builtins.head (lib.splitString "." host.name);
67 networking.domain = lib.concatStringsSep "." (builtins.tail (lib.splitString "." host.name));
68
69 # The provider module configures the uplink, "10-uplink".
70 networking.useDHCP = false;
71 networking.useNetworkd = true;
72 systemd.network.enable = true;
73}