diff options
| author | Alejandro Soto <alejandro@34project.org> | 2024-07-14 17:53:13 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2024-07-15 09:34:00 -0600 |
| commit | 02abf4ed0131237c25e0a10db50fa4c41a902a50 (patch) | |
| tree | 20904894fc0952806e341cdaff5941e81b3ce51c /sys/virt/libvirt.nix | |
| parent | 08e746700341dda3e3bdf704332fc3c07053d3e7 (diff) | |
sys: final merge of dmz, hv into sys
Diffstat (limited to '')
| -rw-r--r-- | sys/virt/libvirt.nix | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/sys/virt/libvirt.nix b/sys/virt/libvirt.nix new file mode 100644 index 0000000..29679ae --- /dev/null +++ b/sys/virt/libvirt.nix @@ -0,0 +1,53 @@ +{ config, flakes, lib, pkgs, ... }: +with lib; let + cfg = config.local.virt; + + inherit (import ../../util lib) 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; + 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; + }; + }; + }; + }; +} |
