summaryrefslogtreecommitdiff
path: root/system/nvidia.nix
blob: f3dd1de94428da31b236e0fa4498a3b6644e97a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{
  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="];
    };
  };
}