summaryrefslogtreecommitdiff
path: root/modules/virt.nix
blob: ff63155fb25095313f0cf0237d693e9bcb8c6d76 (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
{
  pkgs,
  config,
  lib,
  ...
}:
let
  cfg = config.addons.virtualisation;
in
{
  options.addons.virtualisation = {
    host = lib.mkEnableOption "Allow to host vm's and containers";
    guest = lib.mkEnableOption "Enable guest agents";
    isTestVM = lib.mkEnableOption "Enabled if the system is a test VM";
  };

  config = lib.mkMerge ([
    (lib.mkIf cfg.host {
      environment.systemPackages = with pkgs; [
        qemu
      ];
      programs.virt-manager.enable = true;
      virtualisation = {
        spiceUSBRedirection.enable = true;
        docker.enable = true;
        libvirtd = {
          enable = true;
          qemu = {
            swtpm.enable = true;
            vhostUserPackages = with pkgs; [ virtiofsd ];
          };
        };
      };

    })
    (lib.mkIf cfg.guest {
      services.spice-vdagentd.enable = true;
      services.qemuGuest.enable = true;
    })
    ({
      virtualisation.vmVariant = {
        addons.virtualization.isTestVM = true;
      };
    })
  ]);

}