88 lines
1.7 KiB
Nix
88 lines
1.7 KiB
Nix
{
|
|
lib,
|
|
config,
|
|
pkgs,
|
|
username,
|
|
vars,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.virtualization;
|
|
in
|
|
{
|
|
options = {
|
|
virtualization = {
|
|
enable = lib.mkEnableOption "Enable virtualization in NixOS & home-manager";
|
|
};
|
|
};
|
|
config = lib.mkIf cfg.enable {
|
|
environment = {
|
|
systemPackages = with pkgs; [
|
|
docker-compose
|
|
podlet
|
|
quickemu
|
|
spice
|
|
spice-protocol
|
|
virt-manager
|
|
virtiofsd
|
|
virtio-win
|
|
win-spice
|
|
];
|
|
};
|
|
services = {
|
|
spice-vdagentd.enable = true;
|
|
};
|
|
virtualisation = {
|
|
docker = {
|
|
enable = true;
|
|
enableOnBoot = true;
|
|
autoPrune = {
|
|
enable = true;
|
|
dates = "weekly";
|
|
};
|
|
liveRestore = false;
|
|
enableNvidia = if vars.nvidia then true else false;
|
|
};
|
|
libvirtd = {
|
|
# Make sure you run this once: "sudo virsh net-autostart default"
|
|
enable = true;
|
|
qemu = {
|
|
swtpm.enable = true;
|
|
ovmf.enable = true;
|
|
ovmf.packages = [ pkgs.OVMFFull.fd ];
|
|
};
|
|
};
|
|
spiceUSBRedirection.enable = true;
|
|
vmVariant = {
|
|
virtualisation = {
|
|
memorySize = 4096;
|
|
cores = 3;
|
|
};
|
|
};
|
|
};
|
|
|
|
users = {
|
|
users = {
|
|
${username} = {
|
|
extraGroups = [
|
|
"docker"
|
|
"libvirtd"
|
|
"podman"
|
|
];
|
|
# quadlets
|
|
autoSubUidGidRange = true;
|
|
linger = true;
|
|
};
|
|
};
|
|
};
|
|
|
|
home-manager.users.${username} = {
|
|
dconf.settings = {
|
|
"org/virt-manager/virt-manager/connections" = {
|
|
autoconnect = [ "qemu:///system" ];
|
|
uris = [ "qemu:///system" ];
|
|
};
|
|
};
|
|
};
|
|
};
|
|
} |