nixdots/system/shared/hardware/gpu/nvidia.nix

107 lines
3.5 KiB
Nix
Raw Normal View History

2024-05-15 18:29:28 +00:00
{ config, lib, pkgs, ... }:
let
dev = config.myOptions.device;
2024-06-10 11:54:03 +00:00
isWayland = config.myOptions.home-manager.wms.isWayland;
inherit (lib) mkIf mkDefault mkMerge;
2024-05-15 18:29:28 +00:00
in
{
2024-06-10 11:54:03 +00:00
config = mkIf (builtins.elem dev.gpu.type ["nvidia" "hybrid-nvidia"]) {
2024-05-15 18:29:28 +00:00
# Nvidia drivers are unfree software
nixpkgs.config.allowUnfree = true;
# Enable nvidia driver for Xorg and Wayland
services.xserver.videoDrivers = ["nvidia"];
2024-06-10 11:54:03 +00:00
# blacklist nouveau module so that it does not conflict with nvidia drm stuff
# also the nouveau performance is horrible in comparison.
boot.blacklistedKernelModules = ["nouveau"];
2024-05-15 18:29:28 +00:00
hardware = {
nvidia = {
# modeestting is required
2024-06-10 11:54:03 +00:00
modesetting.enable = mkDefault true;
2024-05-15 18:29:28 +00:00
# Nvidia power managerment. Experimental, and can cause sleep/suspend to fail.
# Enable this if you have graphical corruption issues or application crashes after waking
# up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead of just
# the bare essentials
2024-06-10 11:54:03 +00:00
powerManagement.enable = mkDefault true;
2024-05-15 18:29:28 +00:00
# Fine-grained power management. Turns off GPU when not in use.
# Experimental and only works on modern Nvidia GPUs (Turing or newer)
2024-06-10 11:54:03 +00:00
powerManagement.finegrained = mkDefault false;
2024-05-15 18:29:28 +00:00
# Use the NVidia open source kernel module (not to be confused with the
# independent third-party "nouveau" open source driver).
# Support is limited to the Turing and later architectures. Full list of
# supported GPUs is at: https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus
#
# Enable this by default, hosts may override this option if their gpu is not
# supported by the open source drivers
2024-06-10 11:54:03 +00:00
open = mkDefault true;
2024-05-15 18:29:28 +00:00
# Add the Nvidia settings package, accessible via `nvidia-settings`.
# (useless on NixOS)
2024-06-10 11:54:03 +00:00
nvidiaSettings = mkDefault false;
2024-05-15 18:29:28 +00:00
# This ensures all GPUs stay awake even during headless mode.
nvidiaPersistenced = true;
2024-06-10 11:54:03 +00:00
# On Hybrid setups, using Nvidia Optimus PRIME is necessary
#
# There are various options/modes prime can work in, this will default to
# using the offload mode, which will default to running everything on igpu
# except apps that run with certain environmental variables set. To simplify
# things, this will also enable the `nvidia-offload` wrapper script/command.
prime.offload = let
isHybrid = dev.gpu.type == "hybrid-nvidia";
in {
enable = isHybrid;
enableOffloadCmd = isHybrid;
};
2024-05-15 18:29:28 +00:00
};
# Enable OpenGL
2024-06-23 19:59:11 +00:00
graphics = {
2024-05-15 18:29:28 +00:00
enable = true;
# VA-API implementation using NVIDIA's NVDEC
extraPackages = with pkgs; [nvidia-vaapi-driver];
extraPackages32 = with pkgs.pkgsi686Linux; [nvidia-vaapi-driver];
};
};
environment = {
systemPackages = with pkgs; [
mesa
vulkan-tools
vulkan-loader
vulkan-validation-layers
vulkan-extension-layer
libva
libva-utils
2024-06-10 11:54:03 +00:00
glxinfo
2024-05-15 18:29:28 +00:00
];
2024-06-10 11:54:03 +00:00
sessionVariables = mkMerge [
{ LIBVA_DRIVER_NAME = "nvidia"; }
(mkIf isWayland {
WLR_NO_HARDWARE_CURSORS = "1";
})
# Run the compositor itself with nvidia GPU?
# Currently disabled
(mkIf (isWayland && (dev.gpu == "hybrid-nvidia")) {
#__NV_PRIME_RENDER_OFFLOAD = "1";
#WLR_DRM_DEVICES = mkDefault "/dev/dri/card1:/dev/dri/card0";
})
];
2024-05-15 18:29:28 +00:00
};
};
}