summaryrefslogtreecommitdiff
path: root/system/nvidia.nix
blob: 810f685bda6566da68f6af7fef1611dc0fc62aee (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
75
76
77
78
79
80
81
82
83
84
85
{
  lib,
  config,
  pkgs,
  ...
}: let
  inherit (lib) mkIf optionals;
  cfg = config.nvidia;
in {
  config = mkIf cfg.enable {
    # kernel modules
    boot.blacklistedKernelModules = ["nouveau"];
    services.xserver.videoDrivers = ["modesetting" "nvidia"];

    # nvidia driver
    hardware.nvidia = {
      modesetting.enable = true;
      powerManagement = {
        enable = false;
        finegrained = false;
      };
      prime =
        cfg.primeBusIds
        // {
          offload = {
            enable = true;
            enableOffloadCmd = true;
          };
        };
      open = true;
      nvidiaSettings = true;
      package = config.boot.kernelPackages.nvidiaPackages.latest;
    };

    # cuda
    environment = 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="];
    };

    unfreePackages =
      [
        "nvidia-x11"
        "nvidia-settings"
      ]
      ++ (optionals cfg.cuda.enable [
        "cuda-merged"
        "cuda_cccl"
        "cuda_cudart"
        "cuda_cuobjdump"
        "cuda_cupti"
        "cuda_cuxxfilt"
        "cuda_gdb"
        "cuda_nvcc"
        "cuda_nvdisasm"
        "cuda_nvml_dev"
        "cuda_nvprune"
        "cuda_nvrtc"
        "cuda_nvtx"
        "cuda_profiler_api"
        "cuda_sanitizer_api"
        "cudnn"
        "libcublas"
        "libcufft"
        "libcurand"
        "libcusolver"
        "libcusparse"
        "libnpp"
        "libnvjitlink"
      ]);
  };
}