refactor(nvidia): make global module for enabling nvidia easily
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-03-03 16:13:56 -05:00
parent 5ea6f8ef99
commit a13b221e49
7 changed files with 94 additions and 80 deletions

View file

@ -20,6 +20,7 @@
../modules/arion
../modules/borgbackup
../modules/nvidia.nix
];
nixpkgs = {

View file

@ -15,7 +15,6 @@ in {
./modules/gpu-replay.nix
./modules/nix-gaming.nix
./modules/nvidia.nix
];
vars = {

View file

@ -75,4 +75,11 @@
qemu
virtiofsd
];
nvidia = {
enable = true;
enableNvidiaSettings = true;
enableWayland = true;
enableCUDA = true;
};
}

View file

@ -50,9 +50,6 @@
'';
};
in {
# Allow CUDA on boot
boot.kernelModules = ["nvidia-uvm"];
security.wrappers = {
gpu-screen-recorder = {
owner = "root";

View file

@ -1,40 +0,0 @@
{
config,
pkgs,
...
}: {
# FIXME: move this to hardware-config?
# Enable OpenGL
hardware.opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;
extraPackages = with pkgs; [
vaapiVdpau
];
};
# Load nvidia driver for Xorg and Wayland
services.xserver.videoDrivers = ["nvidia"];
hardware.nvidia = {
modesetting.enable = true;
# 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).
powerManagement.finegrained = false;
open = true;
# Enable the Nvidia settings menu,
# accessible via `nvidia-settings`.
nvidiaSettings = true;
# Vulkan is much more stable in Wayland
package = config.boot.kernelPackages.nvidiaPackages.vulkan_beta;
};
}

View file

@ -1,14 +1,13 @@
{
config,
modulesPath,
pkgs,
...
}: {
nixpkgs.hostPlatform = "x86_64-linux";
imports = [(modulesPath + "/installer/scan/not-detected.nix")];
boot = {
kernelModules = ["kvm-intel" "nvidia-uvm"];
kernelModules = ["kvm-intel"];
initrd.availableKernelModules = [
"xhci_pci"
@ -47,40 +46,8 @@
hardware.cpu.intel.updateMicrocode = config.hardware.enableRedistributableFirmware;
# NVIDIA settings
services.xserver.videoDrivers = ["nvidia"];
hardware.opengl = {
nvidia = {
enable = true;
driSupport = true;
driSupport32Bit = true;
extraPackages = with pkgs; [
vaapiVdpau
libvdpau-va-gl
nvidia-vaapi-driver
];
extraPackages32 = with pkgs; [vaapiVdpau];
enableCUDA = true;
};
hardware.nvidia = {
modesetting.enable = true;
powerManagement.enable = false;
powerManagement.finegrained = false;
open = false;
nvidiaSettings = false;
# Vulkan is much more stable in Wayland
package = config.boot.kernelPackages.nvidiaPackages.stable;
};
environment.systemPackages = with pkgs; [
libva-utils
nvidia-vaapi-driver
nvtop-nvidia
pciutils
vdpauinfo
cudaPackages.cudatoolkit
];
}

83
modules/nvidia.nix Normal file
View file

@ -0,0 +1,83 @@
{
config,
lib,
pkgs,
...
}: let
inherit (lib) mdDoc mkIf mkEnableOption mkOption optionals types;
cfg = config.nvidia;
in {
options.nvidia = {
enable = mkEnableOption (mdDoc "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 {
# Enable OpenGL
hardware.opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;
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;
};
open = cfg.enableWayland;
package = with config.boot.kernelPackages.nvidiaPackages;
if cfg.enableWayland
# Vulkan is much more stable in Wayland
then vulkan_beta
else stable;
};
environment.systemPackages = with pkgs; ([
libva-utils
nvidia-vaapi-driver
nvtop-nvidia
pciutils
vdpauinfo
]
++ optionals cfg.enableCUDA [cudaPackages.cudatoolkit]);
boot.kernelModules = optionals cfg.enableCUDA ["nvidia-uvm"];
};
}