{ lib, config, pkgs, ... }: let inherit (lib) mkMerge mkIf optionals; cfg = config.nvidia; in { config = mkIf cfg.enable { # kernel modules boot = { blacklistedKernelModules = ["nouveau"]; kernelParams = [ "nvidia.NVreg_PreserveVideoMemoryAllocations=1" "nvidia.NVreg_TemporaryFilePath=/var/tmp" ]; }; services.xserver.videoDrivers = ["modesetting" "nvidia"]; # nvidia driver hardware.nvidia = { modesetting.enable = true; powerManagement = { enable = true; finegrained = false; }; prime = cfg.primeBusIds // { offload = { enable = true; enableOffloadCmd = true; }; }; open = true; nvidiaSettings = true; package = config.boot.kernelPackages.nvidiaPackages.latest; }; # NVIDIA Reflex hardware.graphics.extraPackages = with pkgs; [ low-latency-layer ]; environment = mkMerge [ { variables = { # NVIDIA Reflex LOW_LATENCY_LAYER = "1"; LOW_LATENCY_LAYER_REFLEX = "1"; }; } # cuda (mkIf cfg.cuda.enable { systemPackages = with pkgs; [ cudaPackages.cuda_cudart cudaPackages.cudnn cudatoolkit ]; variables = { NVIDIA_VISIBLE_DEVICES = "all"; NVIDIA_DRIVER_CAPABILITIES = "compute,utility"; CUDA_VISIBLE_DEVICES = 0; CUDA_PATH = "${pkgs.cudatoolkit}"; }; }) ]; nix.settings = mkIf cfg.cuda.enable { substituters = ["https://cache.nixos-cuda.org"]; trusted-public-keys = ["cache.nixos-cuda.org:74DUi4Ye579gUqzH4ziL9IyiJBlDpMRn9MBN8oNan9M="]; }; }; }