nixos-configs/modules/nvidia.nix

93 lines
2.4 KiB
Nix
Raw Normal View History

{
config,
lib,
pkgs,
...
}: let
inherit (lib) mdDoc mkIf mkEnableOption mkOption optionals types;
cfg = config.nvidia;
in {
options.nvidia = {
enable = mkEnableOption (mdDoc "nvidia");
enableNvidiaSettings = mkOption {
type = types.bool;
default = false;
};
enableWayland = mkOption {
type = types.bool;
default = false;
};
enableCUDA = mkOption {
type = types.bool;
default = false;
};
};
config = mkIf cfg.enable {
# Enable OpenGL
hardware.opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;
extraPackages = with pkgs; [
vaapiVdpau
libvdpau-va-gl
nvidia-vaapi-driver
];
extraPackages32 = with pkgs; [vaapiVdpau];
};
services.xserver.videoDrivers = ["nvidia"];
hardware.nvidia = {
modesetting.enable = true;
# Enable the Nvidia settings menu,
# accessible via `nvidia-settings`.
nvidiaSettings = cfg.enableNvidiaSettings;
# Nvidia power management. Experimental, and can cause sleep/suspend to fail.
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).
finegrained = false;
};
open = cfg.enableWayland;
2024-05-05 23:07:06 -04:00
package =
if !cfg.enableWayland
2024-05-05 23:07:06 -04:00
then config.boot.kernelPackages.nvidiaPackages.stable
2024-05-22 10:24:21 -04:00
else
# Get newest beta driver version for better Wayland support
config.boot.kernelPackages.nvidiaPackages.mkDriver {
2024-06-06 08:39:51 -04:00
version = "555.52.04";
sha256_64bit = "sha256-nVOubb7zKulXhux9AruUTVBQwccFFuYGWrU1ZiakRAI=";
sha256_aarch64 = "sha256-Kt60kTTO3mli66De2d1CAoE3wr0yUbBe7eqCIrYHcWk=";
openSha256 = "sha256-wDimW8/rJlmwr1zQz8+b1uvxxxbOf3Bpk060lfLKuy0=";
settingsSha256 = "sha256-PMh5efbSEq7iqEMBr2+VGQYkBG73TGUh6FuDHZhmwHk=";
persistencedSha256 = "sha256-KAYIvPjUVilQQcD04h163MHmKcQrn2a8oaXujL2Bxro=";
};
};
2024-05-05 23:07:06 -04:00
environment.systemPackages =
optionals cfg.enableCUDA [pkgs.cudaPackages.cudatoolkit]
++ (with pkgs; [
libva-utils
nvidia-vaapi-driver
2024-03-22 21:10:11 -04:00
nvtopPackages.nvidia
pciutils
vdpauinfo
2024-05-05 23:07:06 -04:00
]);
boot.kernelModules = optionals cfg.enableCUDA ["nvidia-uvm"];
};
}