From 88b1681dcbcb191ae19062a8742b6abeb9103b1d Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 15 Dec 2023 18:31:08 +0100 Subject: [PATCH] added config for nvidia/intel gpus and settings file --- hardware/amdgpu.nix | 13 ++++++++++++- hardware/default.nix | 12 +++++++++--- hardware/intelgpu.nix | 16 ++++++++++++++++ hardware/nvidia.nix | 8 ++++++++ settings.nix | 7 +++++++ 5 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 hardware/intelgpu.nix create mode 100644 hardware/nvidia.nix create mode 100644 settings.nix diff --git a/hardware/amdgpu.nix b/hardware/amdgpu.nix index cce5773..cfe9d4f 100644 --- a/hardware/amdgpu.nix +++ b/hardware/amdgpu.nix @@ -1,8 +1,14 @@ -{ pkgs, config, ... }: { +{ pkgs, lib, ... }: +{ + # Adapted from: https://github.com/NixOS/nixos-hardware/blob/master/common/gpu/amd/default.nix # Make the kernel use the correct driver early boot.initrd.kernelModules = [ "amdgpu" ]; + # Make sure Xserver uses the `amdgpu` driver + services.xserver.enable = true; + services.xserver.videoDrivers = [ "amdgpu" ]; + # For 32 bit applications hardware.opengl.driSupport32Bit = true; @@ -12,6 +18,11 @@ rocmPackages.clr.icd ]; + # For 32 bit applications + hardware.opengl.extraPackages32 = with pkgs; [ + driversi686Linux.amdvlk + ]; + environment.systemPackages = with pkgs; [ nvtop-amd clinfo diff --git a/hardware/default.nix b/hardware/default.nix index 3c7f6bd..9a266ec 100644 --- a/hardware/default.nix +++ b/hardware/default.nix @@ -1,5 +1,11 @@ +{ lib, ... }: +let + settings = import ./../settings.nix; +in { - imports = [ - ./amdgpu.nix - ]; + # Optionally import modules for specific hardware + imports = + lib.optionals settings.hardware.amdgpu [ ./amdgpu.nix ] + ++ lib.optionals settings.hardware.intelgpu [ ./intelgpu.nix ] + ++ lib.optionals settings.hardware.nvidiagpu [ ./nvidiagpu.nix ]; } diff --git a/hardware/intelgpu.nix b/hardware/intelgpu.nix new file mode 100644 index 0000000..7677c3d --- /dev/null +++ b/hardware/intelgpu.nix @@ -0,0 +1,16 @@ +{ pkgs, lib, ... }: +{ + # Excerpt: https://github.com/NixOS/nixos-hardware/blob/master/common/gpu/intel/default.nix + + boot.initrd.kernelModules = [ "i915" ]; + + environment.variables = { + VDPAU_DRIVER = lib.mkIf config.hardware.opengl.enable (lib.mkDefault "va_gl"); + }; + + hardware.opengl.extraPackages = with pkgs; [ + (if (lib.versionOlder (lib.versions.majorMinor lib.version) "23.11") then vaapiIntel else intel-vaapi-driver) + libvdpau-va-gl + intel-media-driver + ]; +} diff --git a/hardware/nvidia.nix b/hardware/nvidia.nix new file mode 100644 index 0000000..abaa388 --- /dev/null +++ b/hardware/nvidia.nix @@ -0,0 +1,8 @@ +{ pkgs, lib, ... }: +{ + # Excerpt from: https://github.com/NixOS/nixos-hardware/blob/master/common/gpu/nvidia/default.nix + services.xserver.videoDrivers = lib.mkDefault [ "nvidia" ]; + hardware.opengl.extraPackages = with pkgs; [ + vaapiVdpau + ]; +} diff --git a/settings.nix b/settings.nix new file mode 100644 index 0000000..af53d02 --- /dev/null +++ b/settings.nix @@ -0,0 +1,7 @@ +{ + hardware = { + amdgpu = true; + intelgpu = false; + nvidiagpu = false; + }; +}