From 1798db8aee4aaeff0f45d97948a0d8a46b339cd5 Mon Sep 17 00:00:00 2001 From: workflow <4farlion@gmail.com> Date: Sun, 20 Oct 2024 01:21:25 +0100 Subject: [PATCH] feat(nvidia-gpu): tweak setup --- home.nix | 5 +++++ machines/flexbox/system.nix | 16 +++++----------- system/nvidia/default.nix | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/home.nix b/home.nix index d1fe9bc..cde980c 100644 --- a/home.nix +++ b/home.nix @@ -1,5 +1,6 @@ { lib, + isNvidia, pkgs, secrets, ... @@ -161,6 +162,10 @@ in { BROWSER = "brave"; DEFAULT_BROWSER = "brave"; DIRENV_LOG_FORMAT = ""; # Disable verbose direnv output showing env variables changed + LIBVA_DRIVER_NAME = + if isNvidia + then "nvidia" + else null; }; }; diff --git a/machines/flexbox/system.nix b/machines/flexbox/system.nix index d4894ae..01e0830 100644 --- a/machines/flexbox/system.nix +++ b/machines/flexbox/system.nix @@ -1,15 +1,7 @@ # Edit this configuration file to define what should be installed on # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). -{pkgs, ...}: let - nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" '' - export __NV_PRIME_RENDER_OFFLOAD=1 - export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0 - export __GLX_VENDOR_LIBRARY_NAME=nvidia - export __VK_LAYER_NV_optimus=NVIDIA_only - exec -a "$0" "$@" - ''; -in { +{...}: { # Use the systemd-boot EFI boot loader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = false; # Disable this after first installation to not wear out EFI storage @@ -19,9 +11,11 @@ in { boot.kernelParams = ["nvme_core.default_ps_max_latency_us=0" "acpiphp.disable=1"]; # GPU - environment.systemPackages = [nvidia-offload]; hardware.nvidia.prime = { - offload.enable = true; + offload = { + enable = true; + enableOffloadCmd = true; + }; intelBusId = "PCI:0:2:0"; nvidiaBusId = "PCI:1:0:0"; }; diff --git a/system/nvidia/default.nix b/system/nvidia/default.nix index 1db143e..c78f62d 100644 --- a/system/nvidia/default.nix +++ b/system/nvidia/default.nix @@ -1,7 +1,42 @@ +# See: https://nixos.wiki/wiki/Nvidia {pkgs, ...}: { boot.blacklistedKernelModules = ["nouveau"]; environment.systemPackages = [ pkgs.nvtopPackages.full # nvtop + pkgs.mesa-demos + pkgs.vulkan-tools + pkgs.libva-utils ]; services.xserver.videoDrivers = ["nvidia"]; + hardware.opengl = { + enable = true; + }; + + 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 = false; + + # 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 = false; + + # Enable the Nvidia settings menu, + # accessible via `nvidia-settings`. + nvidiaSettings = true; + }; }