From 5331fac6eb4086c6a1289c794a54bbe889b076b6 Mon Sep 17 00:00:00 2001 From: Icy-Thought Date: Mon, 16 Dec 2024 22:57:14 +0100 Subject: [PATCH] [VIRT] rename dir + looking-glass + scream --- hosts/probook-445g6/hardware.nix | 3 - hosts/thinkpad-e595/default.nix | 1 - hosts/thinkpad-e595/hardware.nix | 2 +- modules/desktop/distractions/lutris.nix | 2 +- modules/virtualize/containers/archlinux.nix | 4 +- .../virtualize/containers/transmission.nix | 4 +- modules/virtualize/default.nix | 42 ------------- modules/virtualize/kvm.nix | 60 +++++++++++++++++++ modules/virtualize/looking-glass.nix | 38 ++++++++++++ modules/virtualize/podman.nix | 7 ++- modules/virtualize/wine.nix | 7 ++- 11 files changed, 112 insertions(+), 58 deletions(-) delete mode 100644 modules/virtualize/default.nix create mode 100644 modules/virtualize/kvm.nix create mode 100644 modules/virtualize/looking-glass.nix diff --git a/hosts/probook-445g6/hardware.nix b/hosts/probook-445g6/hardware.nix index 272f4aab..79698158 100644 --- a/hosts/probook-445g6/hardware.nix +++ b/hosts/probook-445g6/hardware.nix @@ -26,9 +26,6 @@ in { [ "xhci_pci" "ahci" "usb_storage" "sd_mod" "rtsx_pci_sdmmc" ]; kernelModules = [ ]; }; - extraModulePackages = [ ]; - kernelModules = [ "kvm-amd" ]; - kernelParams = [ ]; kernel.sysctl = { "net.ipv4.icmp_echo_ignore_broadcasts" = 1; # Refuse ICMP echo requests }; diff --git a/hosts/thinkpad-e595/default.nix b/hosts/thinkpad-e595/default.nix index 6752937b..7ed4be44 100644 --- a/hosts/thinkpad-e595/default.nix +++ b/hosts/thinkpad-e595/default.nix @@ -66,7 +66,6 @@ }; distractions.steam.enable = true; }; - virtualize.enable = true; }; # KDE-Connect + Start-up indicator diff --git a/hosts/thinkpad-e595/hardware.nix b/hosts/thinkpad-e595/hardware.nix index 6058d890..260b53e0 100644 --- a/hosts/thinkpad-e595/hardware.nix +++ b/hosts/thinkpad-e595/hardware.nix @@ -39,7 +39,7 @@ in { kernelModules = [ ]; }; extraModulePackages = [ config.boot.kernelPackages.acpi_call ]; - kernelModules = [ "thinkpad_acpi" "acpi_call" "kvm_amd" ]; + kernelModules = [ "thinkpad_acpi" "acpi_call" ]; kernelParams = [ "pcie_aspm.policy=performance" ]; kernel.sysctl = { "net.ipv4.icmp_echo_ignore_broadcasts" = 1; # Refuse ICMP echo requests diff --git a/modules/desktop/distractions/lutris.nix b/modules/desktop/distractions/lutris.nix index 54d968ec..ad3641df 100644 --- a/modules/desktop/distractions/lutris.nix +++ b/modules/desktop/distractions/lutris.nix @@ -18,7 +18,7 @@ in { user.packages = attrValues ({ lutris = pkgs.lutris.override { extraLibraries = pkgs: [ pkgs.jansson ]; }; - } // optionalAttrs (config.modules.virtualize.wine.enable == false) { + } // optionalAttrs (config.modules.virtualisation.wine.enable == false) { inherit (pkgs) winetricks; inherit (pkgs.wineWowPackages) fonts stagingFull; }); diff --git a/modules/virtualize/containers/archlinux.nix b/modules/virtualize/containers/archlinux.nix index ccb3b707..10d8af6e 100644 --- a/modules/virtualize/containers/archlinux.nix +++ b/modules/virtualize/containers/archlinux.nix @@ -2,11 +2,11 @@ let inherit (lib.modules) mkIf; in { - options.modules.virtualize.containers.archlinux = + options.modules.virtualisation.containers.archlinux = let inherit (lib.options) mkEnableOption; in { enable = mkEnableOption "arch-linux container"; }; - config = mkIf config.modules.virtualize.containers.archlinux.enable { + config = mkIf config.modules.virtualisation.containers.archlinux.enable { virtualisation.libvirtd = { enable = true; qemuVerbatimConfig = '' diff --git a/modules/virtualize/containers/transmission.nix b/modules/virtualize/containers/transmission.nix index 4c10c57b..9b198b66 100644 --- a/modules/virtualize/containers/transmission.nix +++ b/modules/virtualize/containers/transmission.nix @@ -2,9 +2,9 @@ let inherit (lib.modules) mkIf; - cfg = config.modules.virtualize.containers.transmission; + cfg = config.modules.virtualisation.containers.transmission; in { - options.modules.virtualize.containers.transmission = let + options.modules.virtualisation.containers.transmission = let inherit (lib.options) mkOption mkEnableOption; inherit (lib.types) path str; in { diff --git a/modules/virtualize/default.nix b/modules/virtualize/default.nix deleted file mode 100644 index 773b6a6b..00000000 --- a/modules/virtualize/default.nix +++ /dev/null @@ -1,42 +0,0 @@ -{ options, config, lib, pkgs, ... }: - -let - inherit (lib.attrsets) attrValues; - inherit (lib.modules) mkIf; - - cfg = config.modules.virtualize; -in { - options.modules.virtualize = let inherit (lib.options) mkEnableOption; - in { enable = mkEnableOption "Spawn virtual envionrments where required."; }; - - config = mkIf cfg.enable { - user.packages = attrValues { - inherit (pkgs) - virt-manager virt-viewer win-virtio spice spice-gtk spice-protocol - win-spice; - }; - - virtualisation = { - libvirtd = { - enable = true; - # extraOptions = ["--verbose"]; - qemu.ovmf = { - enable = true; - packages = [ pkgs.OVMFFull.fd ]; - }; - }; - spiceUSBRedirection.enable = true; - }; - user.extraGroups = [ "libvirtd" ]; - - services.spice-vdagentd.enable = true; - - # Fix: Could not detect a default hypervisor. Make sure the appropriate QEMU/KVM virtualization... - hm.dconf.settings = { - "org/virt-manager/virt-manager/connections" = { - autoconnect = [ "qemu:///system" ]; - uris = [ "qemu:///system" ]; - }; - }; - }; -} diff --git a/modules/virtualize/kvm.nix b/modules/virtualize/kvm.nix new file mode 100644 index 00000000..66958b5d --- /dev/null +++ b/modules/virtualize/kvm.nix @@ -0,0 +1,60 @@ +{ options, config, lib, pkgs, ... }: + +let + inherit (lib.attrsets) attrValues; + inherit (lib.modules) mkIf; + virtCfg = config.modules.virtualisation; +in { + options.modules.virtualisation.kvm = let inherit (lib.options) mkEnableOption; + in { + enable = mkEnableOption "Kernel-based Virutal Machine."; + vendor = lib.types.enum [ "amd" "intel" ] "amd"; + }; + + config = mkIf virtCfg.kvm.enable { + virtCfg.looking-glass.enable = true; + + user.packages = attrValues { inherit (pkgs) virt-manager; }; + + boot = { + kernelModules = + # https://wiki.archlinux.org/title/PCI_passthrough_via_OVMF#modprobe.d + [ "kvm-${virtCfg.vendor}" "vfio" "vfio_iommu_type1" "vfio_pci" ]; + kernelParams = [ + "${virtCfg.vendor}_iommu=on" + "${virtCfg.vendor}_iommu=pt" + "kvm.ignore_msrs=1" # https://pve.proxmox.com/wiki/PCI_Passthrough#Tips + ]; + extraModprobeConfig = '' + softdep drm pre: vfio vfio-pci + ''; + }; + + virtualisation = { + libvirtd = { + enable = true; + onBoot = "ignore"; + onShutdown = "shutdown"; + qemu = { + ovmf = true; + swtpm = true; + runAsRoot = false; + }; + }; + }; + + user.extraGroups = [ "libvirtd" ]; + + systemd.user.services.scream-ivshmem = { + after = + [ "libvirtd.service" "pipewire.service" "pipewire-pulse.service" ]; + wantedBy = [ "graphical-session.target" ]; + partOf = [ "graphical-session.target" ]; + serviceConfig = { + Type = "simple"; + Restart = "on-failure"; + ExecStart = "${lib.getExe pkgs.scream} -m /dev/shm/scream -o pulse"; + }; + }; + }; +} diff --git a/modules/virtualize/looking-glass.nix b/modules/virtualize/looking-glass.nix new file mode 100644 index 00000000..1ad8170d --- /dev/null +++ b/modules/virtualize/looking-glass.nix @@ -0,0 +1,38 @@ +{ options, config, lib, pkgs, ... }: + +let inherit (lib.modules) mkIf; +in { + options.modules.virtualisation.looking-glass = + let inherit (lib.options) mkEnableOption; + in { + enable = + mkEnableOption "KVM(s) VGA PCI Pass-through without peripherals."; + }; + + config = mkIf config.modules.virtualisation.looking-glass.enable { + + hm.programs.looking-glass-client = { + enable = true; + package = pkgs.unstable.looking-glass-client; + settings = { + app = { + allowDMA = true; + shmFile = "/dev/shm/looking-glass"; + }; + input = { + rawMouse = true; + escapeKey = "56"; # linux/input-event-codes.h + }; + spice = { + enable = true; + audio = true; + }; + win = { + autoResize = true; + borderless = true; + quickSplash = true; + }; + }; + }; + }; +} diff --git a/modules/virtualize/podman.nix b/modules/virtualize/podman.nix index 1a94924c..1d8c716b 100644 --- a/modules/virtualize/podman.nix +++ b/modules/virtualize/podman.nix @@ -4,10 +4,11 @@ let inherit (lib.attrsets) attrValues; inherit (lib.modules) mkIf; in { - options.modules.virtualize.podman = let inherit (lib.options) mkEnableOption; - in { enable = mkEnableOption "Enable the Podman container engine"; }; + options.modules.virtualisation.podman = + let inherit (lib.options) mkEnableOption; + in { enable = mkEnableOption "Enable the Podman container engine"; }; - config = mkIf config.modules.virtualize.podman.enable { + config = mkIf config.modules.virtualisation.podman.enable { virtualisation.podman = { enable = true; dockerCompat = true; # docker = podman (alias) diff --git a/modules/virtualize/wine.nix b/modules/virtualize/wine.nix index 61457c86..2366f5a2 100644 --- a/modules/virtualize/wine.nix +++ b/modules/virtualize/wine.nix @@ -4,10 +4,11 @@ let inherit (lib.attrsets) attrValues; inherit (lib.modules) mkIf; in { - options.modules.virtualize.wine = let inherit (lib.options) mkEnableOption; - in { enable = mkEnableOption "compatibility layer -> windows.exe"; }; + options.modules.virtualisation.wine = + let inherit (lib.options) mkEnableOption; + in { enable = mkEnableOption "compatibility layer -> windows.exe"; }; - config = mkIf config.modules.virtualize.wine.enable { + config = mkIf config.modules.virtualisation.wine.enable { user.packages = attrValues { inherit (pkgs) bottles winetricks; inherit (pkgs.wineWowPackages) fonts stagingFull;