diff --git a/modules/default.nix b/modules/default.nix index ed581f3..5c8f47f 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -3,7 +3,7 @@ ./fonts ./yazi ./sound - ./vm +# ./vm ./retro ./packages ./misc diff --git a/modules/gpu/default.nix b/modules/gpu/default.nix new file mode 100644 index 0000000..c089217 --- /dev/null +++ b/modules/gpu/default.nix @@ -0,0 +1,54 @@ +{ pkgs, config, ... }: +let + # Change this to your username. + user = "joy"; + # Change this to match your system's CPU. + platform = "amd"; + # Change this to specify the IOMMU ids you wrote down earlier. + vfioIds = [ "10de:249c" "10de:228b" ]; +in { + # Configure kernel options to make sure IOMMU & KVM support is on. + boot = { + kernelModules = [ "kvm-${platform}" "vfio_virqfd" "vfio_pci" "vfio_iommu_type1" "vfio" ]; + kernelParams = [ "${platform}_iommu=on" "${platform}_iommu=pt" "kvm.ignore_msrs=1" ]; + extraModprobeConfig = "options vfio-pci ids=${builtins.concatStringsSep "," vfioIds}"; + }; + + # Add a file for looking-glass to use later. This will allow for viewing the guest VM's screen in a + # performant way. + systemd.tmpfiles.rules = [ + "f /dev/shm/looking-glass 0660 ${user} qemu-libvirtd -" + ]; + + # Add virt-manager and looking-glass to use later. + environment.systemPackages = with pkgs; [ + virt-manager + looking-glass-client + ]; + + # Enable virtualisation programs. These will be used by virt-manager to run your VM. + virtualisation = { + libvirtd = { + enable = true; + extraConfig = '' + user="${user}" + ''; + + # Don't start any VMs automatically on boot. + onBoot = "ignore"; + # Stop all running VMs on shutdown. + onShutdown = "shutdown"; + + qemu = { + package = pkgs.qemu_kvm; + ovmf = enabled; + verbatimConfig = '' + namespaces = [] + user = "+${builtins.toString config.users.users.${user}.uid}" + ''; + }; + }; + }; + + users.users.${user}.extraGroups = [ "qemu-libvirtd" "libvirtd" "disk" ]; +} diff --git a/modules/packages/default.nix b/modules/packages/default.nix index 1c22b3c..423151b 100644 --- a/modules/packages/default.nix +++ b/modules/packages/default.nix @@ -57,6 +57,7 @@ gnome.gnome-calculator gnome.gnome-disk-utility #random utils + pciutils cliphist wl-clipboard git