nixos-configs/modules/nvidia/default.nix
matt1432 0a823fbb1a
All checks were successful
Discord / discord commits (push) Has been skipped
refactor(nvidia): remove unneeded declarations and clean up
2024-12-31 11:34:14 -05:00

110 lines
2.5 KiB
Nix

{
config,
lib,
pkgs,
...
}: let
inherit (builtins) attrValues toJSON;
inherit (lib) mkIf mkEnableOption mkOption optionals optionalString types;
cfg = config.nvidia;
in {
options.nvidia = {
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 {
hardware.graphics = {
enable = true;
enable32Bit = true;
extraPackages = attrValues {
inherit
(pkgs)
vaapiVdpau
libvdpau-va-gl
nvidia-vaapi-driver
;
};
extraPackages32 = attrValues {
inherit
(pkgs)
vaapiVdpau
;
};
};
services.xserver.videoDrivers = ["nvidia"];
hardware.nvidia = {
open = true;
package = config.boot.kernelPackages.nvidiaPackages.latest;
# Whether to enable nvidia-settings, NVIDIA's GUI configuration tool
nvidiaSettings = cfg.enableNvidiaSettings;
};
environment.systemPackages =
optionals cfg.enableCUDA [pkgs.cudaPackages.cudatoolkit]
++ (attrValues {
inherit (pkgs.nvtopPackages) nvidia;
inherit
(pkgs)
libva-utils
nvidia-vaapi-driver
pciutils
vdpauinfo
;
});
boot.kernelModules =
optionals cfg.enableCUDA ["nvidia-uvm"]
++ ["nvidia" "nvidia-drm"];
# Fixes egl-wayland issues with beta drivers
# https://github.com/hyprwm/Hyprland/issues/7202
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"
);
};
# For accurate stack trace
_file = ./default.nix;
}