2024-05-22 20:47:55 +00:00
|
|
|
# Enables virtualization via QEMU/KVM
|
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2024-06-24 15:38:28 +00:00
|
|
|
cfg = config.aux.system.services.virtualization;
|
2024-05-22 20:47:55 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2024-06-24 15:38:28 +00:00
|
|
|
aux.system.services.virtualization = {
|
2024-06-24 18:31:13 +00:00
|
|
|
enable = lib.mkEnableOption (lib.mdDoc "Enables virtualization hosting tools on this host.");
|
2024-05-22 20:47:55 +00:00
|
|
|
user = lib.mkOption {
|
|
|
|
default = "";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The default user to add as a KVM admin.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
virtualisation = {
|
|
|
|
libvirtd = {
|
|
|
|
enable = true;
|
|
|
|
qemu = {
|
|
|
|
package = pkgs.qemu_kvm;
|
|
|
|
swtpm.enable = true;
|
|
|
|
ovmf.enable = true;
|
|
|
|
ovmf.packages = [ pkgs.OVMFFull.fd ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
spiceUSBRedirection.enable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.${cfg.user}.extraGroups = [ "libvirtd" ];
|
|
|
|
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
spice
|
|
|
|
spice-gtk
|
|
|
|
spice-protocol
|
|
|
|
virt-viewer
|
|
|
|
];
|
|
|
|
programs.virt-manager.enable = true;
|
2024-05-22 23:31:30 +00:00
|
|
|
|
|
|
|
# Allow the default bridge interface to access the network
|
2024-05-23 15:00:25 +00:00
|
|
|
networking.firewall.trustedInterfaces = [ "virbr0" ];
|
2024-05-22 20:47:55 +00:00
|
|
|
};
|
|
|
|
}
|