blob: 0f98563078dac8aa78b4ba7d0674a758cf172043 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
{ 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;
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;
};
};
};
};
}
|