2023-06-18 23:36:17 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
{
|
|
|
|
# assumes common-gpu-nvidia from nixos-hardware is also added
|
|
|
|
# TODO: should we move it from flake.nix to here?
|
|
|
|
|
|
|
|
# https://nixos.wiki/wiki/Nvidia
|
|
|
|
|
2023-07-04 16:32:09 +02:00
|
|
|
#https://nixpk.gs/pr-tracker.html?pr=235481
|
2023-06-19 02:45:50 +02:00
|
|
|
#nixpkgs.config.cudaSupport = true; # TODO: TOO SLOW, BREAKS
|
2023-06-24 19:11:49 +02:00
|
|
|
#nixpkgs.config.nvidiaSupport = true; # TODO: slow? used only by zenith
|
2023-07-04 16:32:09 +02:00
|
|
|
|
2023-06-18 23:36:17 +02:00
|
|
|
nixpkgs.config.allowUnfreePredicate = pkg: lib.any (x: x) [
|
|
|
|
(lib.hasInfix "nvidia" (lib.toLower (lib.getName pkg)))
|
|
|
|
(lib.hasInfix "cuda" (lib.toLower (lib.getName pkg)))
|
|
|
|
(lib.hasInfix "cudnn" (lib.toLower (lib.getName pkg)))
|
|
|
|
(lib.hasInfix "cublas" (lib.toLower (lib.getName pkg)))
|
|
|
|
];
|
|
|
|
|
|
|
|
hardware.opengl.enable = true;
|
2023-06-24 14:48:53 +02:00
|
|
|
hardware.opengl.driSupport = true;
|
|
|
|
hardware.opengl.extraPackages = with pkgs; [
|
|
|
|
vaapiVdpau
|
|
|
|
libvdpau-va-gl
|
|
|
|
];
|
|
|
|
|
2023-06-24 19:11:49 +02:00
|
|
|
hardware.nvidia.modesetting.enable = lib.mkDefault true; # needed for most wayland compositors
|
2023-06-24 14:48:53 +02:00
|
|
|
hardware.nvidia.nvidiaSettings = true;
|
|
|
|
#hardware.nvidia.open = true; # open source version of kernel module, only on driver 515.43.04+
|
2023-06-24 19:11:49 +02:00
|
|
|
#hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.latest; # only do this per-host
|
|
|
|
hardware.nvidia.powerManagement.enable = true; # Fix graphical corruption on suspend/resume
|
2023-06-18 23:36:17 +02:00
|
|
|
|
2023-07-04 16:32:09 +02:00
|
|
|
|
|
|
|
|
2023-06-18 23:36:17 +02:00
|
|
|
# add this to the host in question:
|
|
|
|
#hardware.nvidia.prime = {
|
|
|
|
# offload.enable = true;
|
|
|
|
# # Bus IDs. You can find them using lspci, grepping for "3D" or "VGA"
|
|
|
|
# intelBusId = "PCI:0:2:0";
|
|
|
|
# nvidiaBusId = "PCI:1:0:0";
|
|
|
|
#};
|
|
|
|
|
2023-06-24 14:48:53 +02:00
|
|
|
|
2023-06-18 23:36:17 +02:00
|
|
|
environment.systemPackages = with pkgs; ([
|
2023-06-23 21:45:16 +02:00
|
|
|
nvtop-nvidia
|
2023-06-18 23:36:17 +02:00
|
|
|
|
2023-06-24 19:11:49 +02:00
|
|
|
] ++ lib.optionals config.hardware.nvidia.prime.offload.enable [
|
2023-06-18 23:36:17 +02:00
|
|
|
(writeShellScriptBin "prime-run" ''
|
|
|
|
export __NV_PRIME_RENDER_OFFLOAD=1
|
|
|
|
export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
|
|
|
|
export __GLX_VENDOR_LIBRARY_NAME=nvidia
|
|
|
|
export __VK_LAYER_NV_optimus=NVIDIA_only
|
|
|
|
exec "$@"
|
|
|
|
'')
|
|
|
|
# already added by nixos-hardware.common-gpu-nvidia
|
|
|
|
#(writeShellScriptBin "nvidia-offload" ''
|
|
|
|
# export __NV_PRIME_RENDER_OFFLOAD=1
|
|
|
|
# export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
|
|
|
|
# export __GLX_VENDOR_LIBRARY_NAME=nvidia
|
|
|
|
# export __VK_LAYER_NV_optimus=NVIDIA_only
|
|
|
|
# exec "$@"
|
|
|
|
#'')
|
|
|
|
]);
|
|
|
|
}
|