{ config, flakes, lib, pkgs, ... }: with lib; let cfg = config.local.virt; inherit (config.lib.local) importAll; doms = mapAttrs (_: dom: dom { inherit config lib pkgs; }) (importAll { root = ./dom; }); in { options.local.virt = { enable = mkEnableOption "hypervisor support"; dom = mapAttrs (name: _: { enable = mkEnableOption "domain ${name}"; }) doms; }; config = mkIf cfg.enable { local.boot.impermanence.directories = [ { directory = "/var/dom"; user = "root"; group = "qemu-libvirtd"; mode = "u=rwx,g=rx,o="; } ]; virtualisation = { libvirt = { enable = true; connections."qemu:///system".domains = let makeDomain = def: { active = true; restart = false; definition = flakes.nixvirt.lib.domain.writeXML def; }; in map makeDomain (attrValues (filterAttrs (name: _: cfg.dom.${name}.enable) doms)); swtpm.enable = true; }; libvirtd = { enable = true; qemu = { runAsRoot = false; ovmf.enable = true; swtpm.enable = true; }; }; }; }; }