nixos-configs/modules/nvidia.nix

93 lines
2.3 KiB
Nix
Raw Normal View History

{
config,
lib,
pkgs,
...
}: let
2024-06-24 12:30:49 -04:00
inherit (lib) mkIf mkEnableOption mkOption optionals types;
cfg = config.nvidia;
in {
options.nvidia = {
2024-06-24 12:30:49 -04:00
enable = mkEnableOption "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 {
2024-06-21 18:15:19 -04:00
hardware.graphics = {
enable = true;
2024-06-21 18:15:19 -04:00
enable32Bit = 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 = false;
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-07-04 19:33:33 -04:00
version = "555.58.02";
sha256_64bit = "sha256-xctt4TPRlOJ6r5S54h5W6PT6/3Zy2R4ASNFPu8TSHKM=";
sha256_aarch64 = "sha256-wb20isMrRg8PeQBU96lWJzBMkjfySAUaqt4EgZnhyF8=";
openSha256 = "sha256-8hyRiGB+m2hL3c9MDA/Pon+Xl6E788MZ50WrrAGUVuY=";
settingsSha256 = "sha256-ZpuVZybW6CFN/gz9rx+UJvQ715FZnAOYfHn5jt5Z2C8=";
persistencedSha256 = "sha256-a1D7ZZmcKFWfPjjH1REqPM5j/YLWKnbkP9qfRyIyxAw=";
};
};
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"]
++ ["nvidia" "nvidia-drm"];
};
}