dotfiles

My PC Dotfiles & Website

modules/virt/libvirt.nix (1136B)


 1## Libvirt Settings ##
 2_: {
 3  flake.modules = {
 4    nixos.libvirt = {
 5      config,
 6      pkgs,
 7      ...
 8    }: let
 9      inherit (config.hardware.cpu) model;
10    in {
11      # Environment Setup
12      environment.persist.directories = ["/var/lib/libvirt"];
13      security.virtualisation.flushL1DataCache = "cond";
14      boot = {
15        kernelModules = ["kvm-${model}"];
16        extraModprobeConfig = "options kvm_${model} nested=1";
17      };
18
19      virtualisation = {
20        kvmgt.enable = true;
21        spiceUSBRedirection.enable = true;
22        libvirtd = {
23          enable = true;
24          onBoot = "ignore";
25          onShutdown = "shutdown";
26          qemu = {
27            package = pkgs.qemu_kvm;
28            runAsRoot = false;
29            swtpm.enable = true;
30            vhostUserPackages = [pkgs.unstable.virtiofsd];
31          };
32        };
33      };
34
35      # VM Utilities
36      programs.virt-manager.enable = true;
37      environment.systemPackages = [pkgs.libguestfs];
38    };
39
40    homeManager.libvirt = _: {
41      home.persist.directories = [
42        ".config/libvirt"
43        ".local/share/libvirt"
44      ];
45    };
46  };
47}