From 1451a6c90e9eb13d3e1a43341acdbb810bddb81c Mon Sep 17 00:00:00 2001 From: xnm Date: Sun, 21 Apr 2024 21:58:07 +0300 Subject: [PATCH] added `opengl` and `nvidia` configs --- nixos/disable-nvidia.nix | 21 +++++++++++ nixos/flake.nix | 3 ++ nixos/nvidia.nix | 76 ++++++++++++++++++++++++++++++++++++++++ nixos/opengl.nix | 32 +++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 nixos/disable-nvidia.nix create mode 100644 nixos/nvidia.nix create mode 100644 nixos/opengl.nix diff --git a/nixos/disable-nvidia.nix b/nixos/disable-nvidia.nix new file mode 100644 index 0000000..2967008 --- /dev/null +++ b/nixos/disable-nvidia.nix @@ -0,0 +1,21 @@ +{ ... }: + +{ + boot.extraModprobeConfig = '' + blacklist nouveau + options nouveau modeset=0 + ''; + + services.udev.extraRules = '' + # Remove NVIDIA USB xHCI Host Controller devices, if present + ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c0330", ATTR{power/control}="auto", ATTR{remove}="1" + # Remove NVIDIA USB Type-C UCSI devices, if present + ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c8000", ATTR{power/control}="auto", ATTR{remove}="1" + # Remove NVIDIA Audio devices, if present + ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x040300", ATTR{power/control}="auto", ATTR{remove}="1" + # Remove NVIDIA VGA/3D controller devices + ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", ATTR{power/control}="auto", ATTR{remove}="1" + ''; + + boot.blacklistedKernelModules = [ "nouveau" "nvidia" "nvidia_drm" "nvidia_modeset" ]; +} diff --git a/nixos/flake.nix b/nixos/flake.nix index b9cbd4c..73970a4 100644 --- a/nixos/flake.nix +++ b/nixos/flake.nix @@ -13,6 +13,9 @@ modules = [ ./configuration.nix ./hardware-configuration.nix + # ./nvidia.nix + # ./disable-nvidia.nix + ./opengl.nix # ./fingerprint-scanner.nix ./yubikey.nix ./sound.nix diff --git a/nixos/nvidia.nix b/nixos/nvidia.nix new file mode 100644 index 0000000..e43db5d --- /dev/null +++ b/nixos/nvidia.nix @@ -0,0 +1,76 @@ +{ config, lib, ... }: + +{ + # Load nvidia driver for Xorg and Wayland + services.xserver.videoDrivers = ["nvidia"]; + + hardware.nvidia = { + + # Modesetting is required. + modesetting.enable = true; + + # Nvidia power management. Experimental, and can cause sleep/suspend to fail. + # Enable this if you have graphical corruption issues or application crashes after waking + # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead + # of just the bare essentials. + powerManagement.enable = true; + + # Fine-grained power management. Turns off GPU when not in use. + # Experimental and only works on modern Nvidia GPUs (Turing or newer). + powerManagement.finegrained = true; + + # Use the NVidia open source kernel module (not to be confused with the + # independent third-party "nouveau" open source driver). + # Support is limited to the Turing and later architectures. Full list of + # supported GPUs is at: + # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus + # Only available from driver 515.43.04+ + # Currently alpha-quality/buggy, so false is currently the recommended setting. + open = true; + + # Enable the Nvidia settings menu, + # accessible via `nvidia-settings`. + nvidiaSettings = true; + + # Optionally, you may need to select the appropriate driver version for your specific GPU. + package = config.boot.kernelPackages.nvidiaPackages.production; + + # Nvidia Optimus PRIME. It is a technology developed by Nvidia to optimize + # the power consumption and performance of laptops equipped with their GPUs. + # It seamlessly switches between the integrated graphics, + # usually from Intel, for lightweight tasks to save power, + # and the discrete Nvidia GPU for performance-intensive tasks. + prime = { + offload = { + enable = true; + enableOffloadCmd = true; + }; + + # FIXME: Change the following values to the correct Bus ID values for your system! + # More on "https://wiki.nixos.org/wiki/Nvidia#Configuring_Optimus_PRIME:_Bus_ID_Values_(Mandatory)" + nvidiaBusId = "PCI:0:0:0"; + intelBusId = "PCI:0:0:0"; + }; + }; + + # NixOS specialization named 'nvidia-sync'. Provides the ability + # to switch the Nvidia Optimus Prime profile + # to sync mode during the boot process, enhancing performance. + specialisation = { + nvidia-sync.configuration = { + system.nixos.tags = [ "nvidia-sync" ]; + hardware.nvidia = { + powerManagement.finegrained = lib.mkForce false; + + prime.offload.enable = lib.mkForce false; + prime.offload.enableOffloadCmd = lib.mkForce false; + + prime.sync.enable = lib.mkForce true; + # Dynamic Boost. It is a technology found in NVIDIA Max-Q design laptops with RTX GPUs. + # It intelligently and automatically shifts power between + # the CPU and GPU in real-time based on the workload of your game or application. + dynamicBoost.enable = lib.mkForce true; + }; + }; + }; +} diff --git a/nixos/opengl.nix b/nixos/opengl.nix new file mode 100644 index 0000000..69130a3 --- /dev/null +++ b/nixos/opengl.nix @@ -0,0 +1,32 @@ +{ pkgs, ... }: + +{ + + nixpkgs.config.packageOverrides = pkgs: { + intel-vaapi-driver = pkgs.intel-vaapi-driver.override { enableHybridCodec = true; }; + }; + + # Enable OpenGL + hardware.opengl = { + enable = true; + driSupport = true; + driSupport32Bit = true; + extraPackages = with pkgs; [ + intel-compute-runtime + intel-media-driver # LIBVA_DRIVER_NAME=iHD + intel-vaapi-driver # LIBVA_DRIVER_NAME=i965 (older but works better for Firefox/Chromium) + vaapiVdpau + libvdpau-va-gl + mesa + nvidia-vaapi-driver + nv-codec-headers-12 + ]; + extraPackages32 = with pkgs.pkgsi686Linux; [ + intel-media-driver + intel-vaapi-driver + vaapiVdpau + mesa + libvdpau-va-gl + ]; + }; +}