Files
nix-config/hosts/12kingdoms-shoryu/libvirtd.nix
T
Ryan Yin 5c9bb6f95f chore(shoryu): drop the libvirt default-network oneshot
NixOS's libvirtd-config copies default.xml but never creates its
autostart link, and shoryu has no networks/autostart directory at all,
so virbr0 never starts and the oneshot had nothing to disable.

Assisted-by: Claude Code (claude-opus-5-5)
2026-11-01 11:42:57 -06:00

67 lines
2.0 KiB
Nix

{
pkgs,
lib,
mylib,
...
}:
let
genXml = import (mylib.relativeToRoot "lib/genLibvirtDomainXml.nix") { inherit lib; };
# Declarative libvirt domains. The disk image is a one-time copy (reflink) of
# the VM's former KubeVirt disk, e.g.:
# cp --reflink=auto /var/lib/rancher/k3s/storage/vms/<vm>-disk/disk.img \
# /var/lib/libvirt/images/<vm>.img
domains = {
idols-kana = {
uuid = "e744f563-7c7d-45e6-bc71-61980790208d";
vcpu = 4;
memoryGiB = 8;
disk = "/var/lib/libvirt/images/idols-kana.img";
mac = "52:54:00:5a:51:02";
vncPort = 5902;
};
idols-ruby = {
uuid = "3a959d02-11de-498d-bce7-85f78713ca63";
vcpu = 4;
memoryGiB = 8;
disk = "/var/lib/libvirt/images/idols-ruby.img";
mac = "52:54:00:5a:51:03";
vncPort = 5903;
};
};
in
{
# libvirt/QEMU -- runs the VMs directly instead of on KubeVirt. Used for the
# VMs that need to feel like a real machine (the agent desktops kana/ruby) and
# for Windows.
virtualisation.libvirtd.enable = true;
# The VMs attach to our existing bridge (br0), so allow it explicitly.
virtualisation.libvirtd.allowedBridges = [ "br0" ];
# Define (and autostart) the declarative domains on every activation.
systemd.services.libvirt-define-domains = {
description = "Define the declarative libvirt domains";
after = [ "libvirtd.service" ];
requires = [ "libvirtd.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = lib.concatStringsSep "\n" (
lib.mapAttrsToList (name: args: ''
${pkgs.libvirt}/bin/virsh define ${
pkgs.writeText "libvirt-domain-${name}.xml" (genXml (args // { inherit name; }))
}
${pkgs.libvirt}/bin/virsh autostart ${name} || true
'') domains
);
};
# VM disk images (the declarative domains reference files here).
systemd.tmpfiles.rules = [
"d /var/lib/libvirt/images 0755 root root -"
];
}