2024-03-03 16:13:56 -05:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
2024-08-18 11:00:55 -04:00
|
|
|
inherit (builtins) toJSON;
|
|
|
|
inherit (lib) mkIf mkEnableOption mkOption optionals optionalString 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
|
|
|
|
2024-08-31 19:16:06 -04:00
|
|
|
extraPackages = builtins.attrValues {
|
|
|
|
inherit
|
|
|
|
(pkgs)
|
|
|
|
vaapiVdpau
|
|
|
|
libvdpau-va-gl
|
|
|
|
nvidia-vaapi-driver
|
|
|
|
;
|
|
|
|
};
|
|
|
|
extraPackages32 = [pkgs.vaapiVdpau];
|
2024-03-03 16:13:56 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
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-12-08 00:51:16 -05:00
|
|
|
inherit (config.boot.kernelPackages.nvidiaPackages) beta stable;
|
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-12-08 00:51:16 -05:00
|
|
|
else beta;
|
2024-03-03 16:13:56 -05:00
|
|
|
};
|
|
|
|
|
2024-05-05 23:07:06 -04:00
|
|
|
environment.systemPackages =
|
|
|
|
optionals cfg.enableCUDA [pkgs.cudaPackages.cudatoolkit]
|
2024-08-31 19:16:06 -04:00
|
|
|
++ (builtins.attrValues {
|
|
|
|
inherit (pkgs.nvtopPackages) nvidia;
|
|
|
|
inherit
|
|
|
|
(pkgs)
|
|
|
|
libva-utils
|
|
|
|
nvidia-vaapi-driver
|
|
|
|
pciutils
|
|
|
|
vdpauinfo
|
|
|
|
;
|
|
|
|
});
|
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-08-18 11:00:55 -04:00
|
|
|
|
|
|
|
# Fixes egl-wayland issues with beta drivers
|
|
|
|
environment.etc = let
|
|
|
|
mkEglFile = n: library: let
|
|
|
|
suffix = optionalString (library != "wayland") ".1";
|
|
|
|
pkg =
|
|
|
|
if library != "wayland"
|
|
|
|
then config.hardware.nvidia.package
|
|
|
|
else pkgs.egl-wayland;
|
|
|
|
|
|
|
|
fileName = "${toString n}_nvidia_${library}.json";
|
|
|
|
library_path = "${pkg}/lib/libnvidia-egl-${library}.so${suffix}";
|
|
|
|
in {
|
|
|
|
"egl/egl_external_platform.d/${fileName}".source = pkgs.writeText fileName (toJSON {
|
|
|
|
file_format_version = "1.0.0";
|
|
|
|
ICD = {inherit library_path;};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
in
|
|
|
|
mkIf cfg.enableWayland (
|
|
|
|
{"egl/egl_external_platform.d".enable = false;}
|
|
|
|
// mkEglFile 10 "wayland"
|
|
|
|
// mkEglFile 15 "gbm"
|
|
|
|
// mkEglFile 20 "xcb"
|
|
|
|
// mkEglFile 20 "xlib"
|
|
|
|
);
|
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
|
|
|
}
|