diff --git a/base/absolution/configuration.nix b/base/absolution/configuration.nix index 3cb50b9..43e442f 100644 --- a/base/absolution/configuration.nix +++ b/base/absolution/configuration.nix @@ -85,6 +85,18 @@ hardware.display.outputs."DP-4".mode = "2560x1080@75"; + services.monado = { + enable = true; + defaultRuntime = true; + }; + + systemd.user.services.monado.environment = { + STEAMVR_LH_ENABLE = "1"; + XRT_COMPOSITOR_COMPUTE = "1"; + WMR_HANDTRACKING = "0"; + AMD_VULKAN_ICD="RADV"; + }; + programs.virt-manager.enable = true; systemd.packages = with pkgs; [lact]; systemd.services.lactd.wantedBy = ["multi-user.target"]; diff --git a/base/absolution/default.nix b/base/absolution/default.nix index 8701225..82029e9 100644 --- a/base/absolution/default.nix +++ b/base/absolution/default.nix @@ -6,7 +6,6 @@ ../substituters.nix ../fonts.nix ../greetd.nix -# ../virtualisation/virtualisation.nix -# ../monado.nix + ../virtualisation/virtualisation.nix ]; } diff --git a/base/absolution/hardware-configuration.nix b/base/absolution/hardware-configuration.nix index 913f721..982059d 100644 --- a/base/absolution/hardware-configuration.nix +++ b/base/absolution/hardware-configuration.nix @@ -8,47 +8,47 @@ [ (modulesPath + "/installer/scan/not-detected.nix") ]; - boot.initrd.availableKernelModules = [ "uhci_hcd" "ehci_pci" "ahci" "firewire_ohci" "usb_storage" "usbhid" "sd_mod" "sr_mod" ]; + boot.initrd.availableKernelModules = [ "ahci" "xhci_pci" "ehci_pci" "nvme" "usb_storage" "sd_mod" "sr_mod" ]; boot.initrd.kernelModules = [ ]; boot.kernelModules = [ "kvm-intel" ]; boot.extraModulePackages = [ ]; fileSystems."/" = - { device = "/dev/disk/by-uuid/193dbe3e-ca2b-4347-85aa-216d197b507f"; + { device = "/dev/disk/by-uuid/9d711676-b74f-4b8e-a5bb-d8e4864966e1"; fsType = "xfs"; }; fileSystems."/boot" = - { device = "/dev/disk/by-uuid/3FF5-99B9"; + { device = "/dev/disk/by-uuid/A4B4-1762"; fsType = "vfat"; options = [ "fmask=0022" "dmask=0022" ]; }; - fileSystems."/miscssd" = + fileSystems."/2TB" = + { device = "/dev/disk/by-uuid/CE2C90F22C90D6B5"; + fsType = "ntfs"; + }; + + fileSystems."/500G" = + { device = "/dev/disk/by-uuid/88c7ab87-3bec-4f52-ab4f-c1a081df191f"; + fsType = "xfs"; + }; + + fileSystems."/250G" = { device = "/dev/disk/by-uuid/1375e97d-e67b-43b7-827c-c1b984e0f42f"; fsType = "xfs"; }; - fileSystems."/mainstorage" = - { device = "/dev/disk/by-uuid/CE2C90F22C90D6B5"; - fsType = "ntfs"; - }; - - fileSystems."/secondarystorage" = - { device = "/dev/disk/by-uuid/0e2b7fc5-a593-41d7-93e5-2271f572502b"; - fsType = "xfs"; - }; - - swapDevices = [ ]; + swapDevices = + [ { device = "/dev/disk/by-uuid/ce3ea6ad-54bb-44e7-b817-2d69e41ee041"; } + ]; # Enables DHCP on each ethernet and wireless interface. In case of scripted networking # (the default) this is the recommended approach. When using systemd-networkd it's # still possible to use this option, but it's recommended to use it in conjunction # with explicit per-interface declarations with `networking.interfaces..useDHCP`. networking.useDHCP = lib.mkDefault true; - # networking.interfaces.enp11s0.useDHCP = lib.mkDefault true; - # networking.interfaces.enp12s0.useDHCP = lib.mkDefault true; - # networking.interfaces.wls5.useDHCP = lib.mkDefault true; + # networking.interfaces.enp0s25.useDHCP = lib.mkDefault true; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; diff --git a/base/apollo/configuration.nix b/base/apollo/configuration.nix index 437992c..73c4eb1 100644 --- a/base/apollo/configuration.nix +++ b/base/apollo/configuration.nix @@ -22,6 +22,8 @@ services.wivrn.openFirewall = true; services.wivrn.defaultRuntime = true; programs.steam.extraCompatPackages = with pkgs; [ proton-ge-rtsp-bin ]; + environment.pathsToLink = [ "/share/xdg-desktop-portal" ]; + powerManagement.cpuFreqGovernor = "performance"; # Bootloader. @@ -107,18 +109,6 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="05c6", ATTRS{idProduct}=="9008", MODE="0666 layout = "us"; variant = ""; }; - xdg.portal.config.common.default = "*"; - xdg.portal.wlr = { - enable = true; - settings = { - screencast = { - chooser_type = "simple"; - chooser_cmd = "${pkgs.slurp}/bin/slurp -f %o -or"; - exec_before = "${lib.getExe' pkgs.swaynotificationcenter "swaync-client"} --dnd-on --skip-wait"; - exec_after = "${lib.getExe' pkgs.swaynotificationcenter "swaync-client"} --dnd-off --skip-wait"; - }; - }; - }; # Enable CUPS to print documents. services.printing.enable = true; nixpkgs.overlays = [ diff --git a/base/substituters.nix b/base/substituters.nix index f120590..de35b67 100644 --- a/base/substituters.nix +++ b/base/substituters.nix @@ -8,7 +8,7 @@ nix.settings.substituters = [ "https://nix-community.cachix.org" - "https://hyprland.cachix.org" + "https://niri.cachix.org" "https://nixpkgs-wayland.cachix.org" "https://cache.garnix.io" ]; @@ -16,14 +16,14 @@ nix.settings.trusted-substituters = [ "https://nix-community.cachix.org" - "https://hyprland.cachix.org" + "https://niri.cachix.org" "https://nixpkgs-wayland.cachix.org" "https://cache.garnix.io" ]; nix.settings.trusted-public-keys = [ "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" - "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=" + "niri.cachix.org-1:Wv0OmO7PsuocRKzfDoJ3mulSl7Z6oezYhGhR+3W2964=" "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=" "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ]; diff --git a/base/udev.nix b/base/udev.nix index 7d1b702..09ff78a 100644 --- a/base/udev.nix +++ b/base/udev.nix @@ -163,6 +163,54 @@ ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x1002", ATTR{device}=="0x7362", ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x1002", ATTR{device}=="0x738c", RUN+="/bin/sh -c '/sbin/modprobe vendor-reset; echo device_specific > /sys$env{DEVPATH}/reset_method'" +SUBSYSTEM=="usb", ATTRS{idVendor}=="07ca", ATTRS{idProduct}=="0551", MODE="0666" + +SUBSYSTEM=="usb", ATTRS{idVendor}=="07ca", ATTRS{idProduct}=="4710", MODE="0666" + +ACTION!="unbind", ACTION!="remove", SUBSYSTEM=="hid", ATTRS{idVendor}=="044f" GOTO="thrustmaster-rules" + +GOTO="end" + +LABEL="thrustmaster-rules" + +DRIVER=="tmff2" GOTO="tmff-new" + +DRIVER=="hid-tmff-new" GOTO="tmff-new" + +DRIVER=="hid-t150" GOTO="t150" + +DRIVER!="t500rs" GOTO="end" + +ATTRS{idProduct}=="b65e", DRIVER=="t500rs", RUN+="/bin/sh -c 'cd %S%p; chmod 666 range gain spring_level damper_l> + +GOTO="end" + +LABEL="tmff-new" + +ATTRS{idProduct}=="b66e", RUN+="/bin/sh -c 'cd %S%p; chmod 666 range gain spring_level damper_level friction_leve> + +ATTRS{idProduct}=="b66f", RUN+="/bin/sh -c 'cd %S%p; chmod 666 range gain spring_level damper_level friction_leve> + +ATTRS{idProduct}=="b66d", RUN+="/bin/sh -c 'cd %S%p; chmod 666 range gain spring_level damper_level friction_leve> + +ATTRS{idProduct}=="b696", RUN+="/bin/sh -c 'cd %S%p; chmod 666 range gain spring_level damper_level friction_leve> + +ATTRS{idProduct}=="b692", RUN+="/bin/sh -c 'cd %S%p; chmod 666 range gain spring_level damper_level friction_leve> + +ATTRS{idProduct}=="b689", RUN+="/bin/sh -c 'cd %S%p; chmod 666 range gain spring_level damper_level friction_leve> + +GOTO="end" + +LABEL="t150" + +ATTRS{idProduct}=="b677", RUN+="/bin/sh -c 'cd %S%p; chmod 666 range gain autocenter'" + +SUBSYSTEM=="hid", ATTRS{driver}=="hid-t150", ATTR{gain}="100" + +ATTRS{idProduct}=="b67f", RUN+="/bin/sh -c 'cd %S%p; chmod 666 range gain autocenter'" + +LABEL="end" + ''; services.udev.extraHwdb = '' id-input:modalias:input:b0003v054Cp0268* diff --git a/base/virtualisation/kvmfr-git-package.nix b/base/virtualisation/kvmfr-git-package.nix new file mode 100644 index 0000000..4d1b548 --- /dev/null +++ b/base/virtualisation/kvmfr-git-package.nix @@ -0,0 +1,40 @@ +# https://gist.github.com/j-brn/716a03822d256bc5bf5d77b951c7915c +{ stdenv, lib, fetchFromGitHub, kernel, kmod, looking-glass-client, ... }: + +stdenv.mkDerivation rec { + pname = "kvmfr-${version}-${kernel.version}"; + version = "e25492a"; + + # src = looking-glass-client.src; + src = fetchFromGitHub { + owner = "gnif"; + repo = "LookingGlass"; + rev = version; + sha256 = "sha256-efAO7KLdm7G4myUv6cS1gUSI85LtTwmIm+HGZ52arj8="; + }; + sourceRoot = "source/module"; + hardeningDisable = [ "pic" "format" ]; + nativeBuildInputs = kernel.moduleBuildDependencies; + + patchPhase = '' + substituteInPlace kvmfr.c \ + --replace 'MODULE_IMPORT_NS(DMA_BUF);' 'MODULE_IMPORT_NS("DMA_BUF");' + ''; + + makeFlags = [ + "KVER=${kernel.modDirVersion}" + "KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" + ]; + + installPhase = '' + install -D kvmfr.ko -t "$out/lib/modules/${kernel.modDirVersion}/kernel/drivers/misc/" + ''; + + meta = with lib; { + description = "This kernel module implements a basic interface to the IVSHMEM device for LookingGlass"; + homepage = "https://github.com/gnif/LookingGlass"; + license = licenses.gpl2Only; + maintainers = with maintainers; [ j-brn ]; + platforms = [ "x86_64-linux" ]; + }; +} diff --git a/base/virtualisation/kvmfr-options.nix b/base/virtualisation/kvmfr-options.nix new file mode 100644 index 0000000..e93704e --- /dev/null +++ b/base/virtualisation/kvmfr-options.nix @@ -0,0 +1,52 @@ +# https://gist.github.com/j-brn/716a03822d256bc5bf5d77b951c7915c +{ lib, pkgs, config, ... }: + +with lib; +let + cfg = config.virtualisation.kvmfr; +in +{ + options.virtualisation.kvmfr = { + enable = mkEnableOption "Kvmfr"; + + shm = { + enable = mkEnableOption "shm"; + + size = mkOption { + type = types.int; + default = "128"; + description = "Size of the shared memory device in megabytes."; + }; + user = mkOption { + type = types.str; + default = "root"; + description = "Owner of the shared memory device."; + }; + group = mkOption { + type = types.str; + default = "root"; + description = "Group of the shared memory device."; + }; + mode = mkOption { + type = types.str; + default = "0600"; + description = "Mode of the shared memory device."; + }; + }; + }; + + config = mkIf cfg.enable { + boot.extraModulePackages = with config.boot.kernelPackages; [ + (pkgs.callPackage ./kvmfr-git-package.nix { inherit kernel;}) + ]; + boot.initrd.kernelModules = [ "kvmfr" ]; + + boot.kernelParams = optionals cfg.shm.enable [ + "kvmfr.static_size_mb=${toString cfg.shm.size}" + ]; + + services.udev.extraRules = optionals cfg.shm.enable '' + SUBSYSTEM=="kvmfr", OWNER="${cfg.shm.user}", GROUP="${cfg.shm.group}", MODE="${cfg.shm.mode}" + ''; + }; +} \ No newline at end of file diff --git a/base/virtualisation/libvirt.nix b/base/virtualisation/libvirt.nix new file mode 100644 index 0000000..690b667 --- /dev/null +++ b/base/virtualisation/libvirt.nix @@ -0,0 +1,39 @@ +# https://gist.github.com/CRTified/43b7ce84cd238673f7f24652c85980b3?permalink_comment_id=3793931 +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.virtualisation.libvirtd; + + boolToZeroOne = x: if x then "1" else "0"; + + aclString = with lib.strings; + concatMapStringsSep '' + , + '' escapeNixString cfg.deviceACL; +in { + options.virtualisation.libvirtd = { + deviceACL = mkOption { + type = types.listOf types.str; + default = [ ]; + }; + clearEmulationCapabilities = mkOption { + type = types.bool; + default = true; + }; + }; + + # Add qemu-libvirtd to the input group if required + config.users.users."qemu-libvirtd" = { + extraGroups = optionals (!cfg.qemu.runAsRoot) [ "kvm" "input" ]; + isSystemUser = true; + }; + + config.virtualisation.libvirtd.qemu.verbatimConfig = '' + clear_emulation_capabilities = ${ + boolToZeroOne cfg.clearEmulationCapabilities + } + cgroup_device_acl = [ + ${aclString} + ] + ''; +} \ No newline at end of file diff --git a/base/virtualisation/vfio.nix b/base/virtualisation/vfio.nix new file mode 100644 index 0000000..84f6864 --- /dev/null +++ b/base/virtualisation/vfio.nix @@ -0,0 +1,73 @@ +# https://gist.github.com/CRTified/43b7ce84cd238673f7f24652c85980b3?permalink_comment_id=3793931 +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.virtualisation.vfio; +in { + options.virtualisation.vfio = { + enable = mkEnableOption "VFIO Configuration"; + IOMMUType = mkOption { + type = types.enum [ "intel" "amd" ]; + example = "intel"; + description = "Type of the IOMMU used"; + }; + devices = mkOption { + type = types.listOf (types.strMatching "[0-9a-f]{4}:[0-9a-f]{4}"); + default = [ ]; + example = [ "10de:1b80" "10de:10f0" ]; + description = "PCI IDs of devices to bind to vfio-pci"; + }; + disableEFIfb = mkOption { + type = types.bool; + default = false; + example = true; + description = "Disables the usage of the EFI framebuffer on boot."; + }; + blacklistNvidia = mkOption { + type = types.bool; + default = false; + description = "Add Nvidia GPU modules to blacklist"; + }; + ignoreMSRs = mkOption { + type = types.bool; + default = false; + example = true; + description = + "When true, disable kvm guest access to model-specific registers"; + }; + disablePCIeASPM = mkOption { + type = types.bool; + default = false; + example = true; + description = + "When true, disable PCIe Active-State Power Management"; + }; + }; + + config = lib.mkIf cfg.enable { + services.udev.extraRules = '' + SUBSYSTEM=="vfio", OWNER="root", GROUP="kvm" + ''; + + boot.kernelParams = (if cfg.IOMMUType == "intel" then [ + "intel_iommu=on" + "intel_iommu=igfx_off" + ] else + [ "amd_iommu=on" ]) ++ (optional (builtins.length cfg.devices > 0) + ("vfio-pci.ids=" + builtins.concatStringsSep "," cfg.devices)) + ++ (optional cfg.disableEFIfb "video=efifb:off") + ++ (optionals cfg.ignoreMSRs [ + "kvm.ignore_msrs=1" + "kvm.report_ignored_msrs=0" ]) + ++ (optionals cfg.disablePCIeASPM [ + "pcie_aspm=off" + ]); + + boot.kernelModules = [ "vfio_pci" "vfio_iommu_type1" "vfio" ]; + + boot.initrd.kernelModules = + [ "vfio_pci" "vfio_iommu_type1" "vfio" ]; + boot.blacklistedKernelModules = + optionals cfg.blacklistNvidia [ "nvidia" "nouveau" ]; + }; +} \ No newline at end of file diff --git a/base/virtualisation/virtualisation.nix b/base/virtualisation/virtualisation.nix new file mode 100644 index 0000000..ca220a3 --- /dev/null +++ b/base/virtualisation/virtualisation.nix @@ -0,0 +1,63 @@ +{ pkgs, config, ... }: { + + imports = [ + ./kvmfr-options.nix + ./libvirt.nix + ./virtualisationmod.nix + ./vfio.nix + ]; + + virtualisation = { + libvirtd = { + enable = true; + onBoot = "ignore"; + onShutdown = "shutdown"; + qemu = { + package = pkgs.qemu_kvm; + ovmf = { + enable = true; + packages = [ pkgs.OVMFFull.fd ]; + }; + vhostUserPackages = [ pkgs.virtiofsd ]; + swtpm.enable = true; + runAsRoot = true; + }; + clearEmulationCapabilities = false; + deviceACL = [ + "/dev/ptmx" + "/dev/kvm" + "/dev/kvmfr0" + "/dev/vfio/vfio" + "/dev/vfio/30" + ]; + }; + + kvmfr = { + enable = true; + shm = { + enable = true; + size = 512; + user = "alyx"; + group = "qemu-libvirtd"; + mode = "0666"; + }; + }; + spiceUSBRedirection.enable = true; + }; + + virtualisation.vfio = { + enable = true; + IOMMUType = "intel"; + devices = [ + "1002:67df" + "1002:aaf0" + "1b21:2142" + ]; + ignoreMSRs = true; + disablePCIeASPM = true; + disableEFIfb = false; + }; + + boot.kernelModules = [ "kvm-intel" "vhost_vsock" "vfio_virqfd" "vhost-net" ]; + +} diff --git a/base/virtualisation/virtualisationmod.nix b/base/virtualisation/virtualisationmod.nix new file mode 100644 index 0000000..9bb2d41 --- /dev/null +++ b/base/virtualisation/virtualisationmod.nix @@ -0,0 +1,67 @@ +# https://gist.github.com/CRTified/43b7ce84cd238673f7f24652c85980b3?permalink_comment_id=3793931 +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.virtualisation; + tmpfileEntry = name: f: "f /dev/shm/${name} ${f.mode} ${f.user} ${f.group} -"; +in { + options.virtualisation = { + sharedMemoryFiles = mkOption { + type = types.attrsOf (types.submodule ({ name, ... }: { + options = { + name = mkOption { + visible = false; + default = name; + type = types.str; + }; + user = mkOption { + type = types.str; + default = "root"; + description = "Owner of the memory file"; + }; + group = mkOption { + type = types.str; + default = "root"; + description = "Group of the memory file"; + }; + mode = mkOption { + type = types.str; + default = "0600"; + description = "Group of the memory file"; + }; + }; + })); + default = { }; + }; + hugepages = { + enable = mkEnableOption "Hugepages"; + + defaultPageSize = mkOption { + type = types.strMatching "[0-9]*[kKmMgG]"; + default = "1M"; + description = + "Default size of huge pages. You can use suffixes K, M, and G to specify KB, MB, and GB."; + }; + pageSize = mkOption { + type = types.strMatching "[0-9]*[kKmMgG]"; + default = "1M"; + description = + "Size of huge pages that are allocated at boot. You can use suffixes K, M, and G to specify KB, MB, and GB."; + }; + numPages = mkOption { + type = types.ints.positive; + default = 1; + description = "Number of huge pages to allocate at boot."; + }; + }; + }; + + config.systemd.tmpfiles.rules = + mapAttrsToList (tmpfileEntry) cfg.sharedMemoryFiles; + + config.boot.kernelParams = optionals cfg.hugepages.enable [ + "default_hugepagesz=${cfg.hugepages.defaultPageSize}" + "hugepagesz=${cfg.hugepages.pageSize}" + "hugepages=${toString cfg.hugepages.numPages}" + ]; +} \ No newline at end of file