summaryrefslogtreecommitdiff
path: root/modules/nixos/traits/nvidia.nix
blob: 1b37086610461f57f3519230aed161be652fab16 (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
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.traits.nvidia;
  usingNvidia = lib.elem "nvidia" config.services.xserver.videoDrivers;
in
{
  options.traits.nvidia = {
    enable = lib.mkEnableOption "NVIDIA drivers";
    nvk.enable = lib.mkEnableOption "NVK specialisation";
  };

  config = lib.mkIf cfg.enable (
    lib.mkMerge [
      {
        # NOTE: this is experiemental
        boot.kernelParams = lib.optional usingNvidia "nvidia_drm.fbdev=1";

        services.xserver.videoDrivers = [ "nvidia" ];

        hardware = {
          graphics.extraPackages = [ pkgs.vaapiVdpau ]; # TODO: does this work...?
          nvidia = {
            package = lib.mkDefault config.boot.kernelPackages.nvidiaPackages.latest;
            modesetting.enable = true;
          };
        };
      }

      (lib.mkIf cfg.nvk.enable {
        specialisation = {
          nvk.configuration = {
            boot = {
              # required for GSP firmware
              kernelParams = [ "nouveau.config=NvGspRm=1" ];
              # we want early KMS 
              # https://wiki.archlinux.org/title/Kernel_mode_setting#Early_KMS_start
              initrd.kernelModules = [ "nouveau" ];
            };

            # TODO: make sure we don't need this anymore
            environment.sessionVariables = {
              MESA_VK_VERSION_OVERRIDE = "1.3";
            };

            hardware.graphics.extraPackages = lib.mkForce [ ];

            services.xserver.videoDrivers = lib.mkForce [ "modesetting" ];

            system.nixos.tags = [ "with-nvk" ];
          };
        };
      })
    ]
  );
}