2024-03-03 16:13:56 -05:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
2024-06-24 12:30:49 -04:00
|
|
|
inherit (lib) mkIf mkEnableOption mkOption optionals types;
|
2024-03-03 16:13:56 -05:00
|
|
|
|
|
|
|
cfg = config.nvidia;
|
|
|
|
in {
|
|
|
|
options.nvidia = {
|
2024-06-24 12:30:49 -04:00
|
|
|
enable = mkEnableOption "nvidia";
|
2024-03-03 16:13:56 -05:00
|
|
|
|
|
|
|
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 = {
|
2024-03-03 16:13:56 -05:00
|
|
|
enable = true;
|
2024-06-21 18:15:19 -04:00
|
|
|
enable32Bit = true;
|
2024-03-03 16:13:56 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2024-06-15 01:40:26 -04:00
|
|
|
open = false;
|
2024-03-03 16:13:56 -05:00
|
|
|
|
2024-07-30 22:21:08 -04:00
|
|
|
package = let
|
2024-08-13 00:07:59 -04:00
|
|
|
inherit (config.boot.kernelPackages.nvidiaPackages) stable latest;
|
2024-07-30 22:21:08 -04:00
|
|
|
in
|
2024-03-13 19:25:48 -04:00
|
|
|
if !cfg.enableWayland
|
2024-07-30 22:21:08 -04:00
|
|
|
then stable
|
2024-05-22 10:24:21 -04:00
|
|
|
else
|
2024-08-13 00:07:59 -04:00
|
|
|
# Stick to 555 driver version for better Wayland support
|
|
|
|
latest;
|
2024-03-03 16:13:56 -05:00
|
|
|
};
|
|
|
|
|
2024-05-05 23:07:06 -04:00
|
|
|
environment.systemPackages =
|
|
|
|
optionals cfg.enableCUDA [pkgs.cudaPackages.cudatoolkit]
|
|
|
|
++ (with pkgs; [
|
2024-03-03 16:13:56 -05:00
|
|
|
libva-utils
|
|
|
|
nvidia-vaapi-driver
|
2024-03-22 21:10:11 -04:00
|
|
|
nvtopPackages.nvidia
|
2024-03-03 16:13:56 -05:00
|
|
|
pciutils
|
|
|
|
vdpauinfo
|
2024-05-05 23:07:06 -04:00
|
|
|
]);
|
2024-03-03 16:13:56 -05:00
|
|
|
|
2024-06-15 01:40:26 -04:00
|
|
|
boot.kernelModules =
|
|
|
|
optionals cfg.enableCUDA ["nvidia-uvm"]
|
|
|
|
++ ["nvidia" "nvidia-drm"];
|
2024-03-03 16:13:56 -05:00
|
|
|
};
|
2024-08-02 22:32:29 -04:00
|
|
|
|
|
|
|
# For accurate stack trace
|
|
|
|
_file = ./default.nix;
|
2024-03-03 16:13:56 -05:00
|
|
|
}
|