2023-10-20 22:28:37 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.sisyphus.hardware.nvidia;
|
|
|
|
|
2023-10-24 21:00:53 +02:00
|
|
|
do-offloading = builtins.elem cfg.model [ "Quadro T2000" ];
|
2023-10-20 22:28:37 +02:00
|
|
|
nvidia-offload = pkgs.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 "$@"
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
options.sisyphus.hardware.nvidia = {
|
|
|
|
enable = lib.mkEnableOption "NVIDIA GPU support";
|
|
|
|
model = lib.mkOption {
|
2023-10-24 12:45:40 +02:00
|
|
|
type = lib.types.enum [ "" "Quadro T2000" "RTX 2060" ];
|
2023-10-20 22:28:37 +02:00
|
|
|
default = "";
|
2023-10-24 12:45:40 +02:00
|
|
|
example = "Quadro T2000";
|
2023-10-20 22:28:37 +02:00
|
|
|
description = lib.mdDoc "The model of NVIDIA GPU card";
|
|
|
|
};
|
2023-10-24 12:45:40 +02:00
|
|
|
gui-settings = lib.mkEnableOption "NVIDIA settings menu";
|
2023-10-20 22:28:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services.xserver.videoDrivers = [ "nvidia" ];
|
|
|
|
|
|
|
|
hardware = {
|
2023-10-24 12:45:40 +02:00
|
|
|
opengl = {
|
|
|
|
enable = true;
|
|
|
|
driSupport = true;
|
|
|
|
driSupport32Bit = true;
|
|
|
|
};
|
2023-10-20 22:28:37 +02:00
|
|
|
nvidia = {
|
|
|
|
open = true;
|
|
|
|
package = config.boot.kernelPackages.nvidiaPackages.stable;
|
|
|
|
modesetting.enable = true;
|
2023-10-24 21:00:53 +02:00
|
|
|
nvidiaSettings = cfg.gui-settings;
|
2023-10-24 12:45:40 +02:00
|
|
|
powerManagement = {
|
2023-10-24 21:00:53 +02:00
|
|
|
enable = do-offloading;
|
|
|
|
finegrained = do-offloading;
|
2023-10-24 12:45:40 +02:00
|
|
|
};
|
2023-10-20 22:28:37 +02:00
|
|
|
|
2023-10-24 21:00:53 +02:00
|
|
|
prime = lib.mkMerge [
|
|
|
|
(lib.mkIf do-offloading {
|
|
|
|
offload = {
|
|
|
|
enable = true;
|
|
|
|
enableOffloadCmd = true;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
(lib.mkIf (cfg.model == "Quadro T2000") {
|
|
|
|
intelBusId = "PCI::00:02:0";
|
|
|
|
nvidiaBusId = "PCI:01:00:0";
|
|
|
|
})
|
|
|
|
(lib.mkIf (cfg.model == "RTX 2060") {
|
|
|
|
sync.enable = true;
|
|
|
|
intelBusId = "PCI::00:02:0";
|
|
|
|
nvidiaBusId = "PCI:01:00:0";
|
|
|
|
})
|
|
|
|
];
|
2023-10-20 22:28:37 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-10-24 21:00:53 +02:00
|
|
|
environment.systemPackages = lib.mkIf do-offloading [
|
2023-10-20 22:28:37 +02:00
|
|
|
nvidia-offload
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|