2024-03-03 16:13:56 -05:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
2024-12-31 11:34:14 -05:00
|
|
|
inherit (builtins) attrValues toJSON;
|
2024-08-18 11:00:55 -04:00
|
|
|
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-12-31 11:34:14 -05:00
|
|
|
extraPackages = attrValues {
|
2024-08-31 19:16:06 -04:00
|
|
|
inherit
|
|
|
|
(pkgs)
|
|
|
|
vaapiVdpau
|
|
|
|
libvdpau-va-gl
|
|
|
|
nvidia-vaapi-driver
|
|
|
|
;
|
|
|
|
};
|
2024-12-31 11:34:14 -05:00
|
|
|
extraPackages32 = attrValues {
|
|
|
|
inherit
|
|
|
|
(pkgs)
|
|
|
|
vaapiVdpau
|
|
|
|
;
|
|
|
|
};
|
2024-03-03 16:13:56 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
services.xserver.videoDrivers = ["nvidia"];
|
|
|
|
|
|
|
|
hardware.nvidia = {
|
2024-12-31 11:34:14 -05:00
|
|
|
open = true;
|
2024-03-03 16:13:56 -05:00
|
|
|
|
2024-12-31 11:34:14 -05:00
|
|
|
package = config.boot.kernelPackages.nvidiaPackages.latest;
|
2024-03-03 16:13:56 -05:00
|
|
|
|
2024-12-31 11:34:14 -05:00
|
|
|
# Whether to enable nvidia-settings, NVIDIA's GUI configuration tool
|
|
|
|
nvidiaSettings = cfg.enableNvidiaSettings;
|
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-12-31 11:34:14 -05:00
|
|
|
++ (attrValues {
|
2024-08-31 19:16:06 -04:00
|
|
|
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
|
2024-12-31 11:34:14 -05:00
|
|
|
# https://github.com/hyprwm/Hyprland/issues/7202
|
2024-08-18 11:00:55 -04:00
|
|
|
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
|
|
|
}
|