summaryrefslogtreecommitdiffstats
path: root/modules/hardware/gpu.nix
blob: bb8b831bfc8f0cc56ab3e36961b4f2f9711236b2 (plain) (blame)
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
{
    config,
    options,
    lib,
    pkgs,
    ...
}: let
    gpuConfig = config.modules.hardware.gpu;
    device = config.modules.device;
in {
    options.modules.hardware.gpu = {
        enable = lib.mkOption {
            type = lib.types.bool;
            default = true;
        };
    };

    config = lib.mkIf (gpuConfig.enable) (lib.mkMerge [
        {
            hardware.graphics = {
                enable = true;
            };
        }
        (lib.mkIf (device.gpu == "intel") {
            boot.initrd.kernelModules = ["i915"];
            services.xserver.videoDrivers = ["modesetting"];

            hardware.opengl.extraPackages = [
                pkgs.intel-compute-runtime
                pkgs.intel-media-driver
                pkgs.vaapiIntel
                pkgs.vaapiVdpau
                pkgs.libvdpau-va-gl
            ];

            environment.variables.VDPAU_DRIVER = "va_gl";
        })
        (lib.mkIf (device.gpu == "nvidia") {
          boot = {
            extraModulePackages = [
              config.boot.kernelPackages.nvidia_x11_beta
            ];
            initrd.kernelModules = [ 
                "nvidia"
                "nvidia_modeset"
                "nvidia_uvm"
                "nvidia_drm"
              ];
              blacklistedKernelModules = [ "nouveau" ];
            };

            environment.systemPackages = with pkgs; [
              pkgs.nvidia-vaapi-driver
            ];

            services.xserver.videoDrivers = ["nvidia"];
            hardware.nvidia = {
                modesetting.enable = true;
                powerManagement.enable = true;
                open = false;
                nvidiaSettings = true;
                package = config.boot.kernelPackages.nvidiaPackages.beta;
            };
        })
    ]);
}