about summary refs log tree commit diff
path: root/apple-silicon-support/modules/mesa/default.nix
blob: 34966d05d7ad2766f327603b900a5d12182c00e2 (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
67
68
69
70
71
72
{ config, pkgs, lib, ... }:
{
  config = let
    isMode = mode: (config.hardware.asahi.useExperimentalGPUDriver
        && config.hardware.asahi.experimentalGPUInstallMode == mode);
  in lib.mkMerge [
    {
      # required for proper DRM setup even without GPU driver
      services.xserver.config = ''
        Section "OutputClass"
            Identifier "appledrm"
            MatchDriver "apple"
            Driver "modesetting"
            Option "PrimaryGPU" "true"
        EndSection
      '';
    }
    (lib.mkIf config.hardware.asahi.useExperimentalGPUDriver {
      # install the drivers
      hardware.opengl.package = config.hardware.asahi.pkgs.mesa-asahi-edge.drivers;

      # required for in-kernel GPU driver
      hardware.asahi.withRust = true;
    })
    (lib.mkIf (isMode "replace") {
      # replace the Mesa linked into system packages with the Asahi version
      # without rebuilding them to avoid rebuilding the world.
      system.replaceRuntimeDependencies = [
        { original = pkgs.mesa;
          replacement = config.hardware.asahi.pkgs.mesa-asahi-edge;
        }
      ];
    })
    (lib.mkIf (isMode "overlay") {
      # replace the Mesa used in Nixpkgs with the Asahi version using an overlay,
      # which requires rebuilding the world but ensures it is done faithfully
      # (and in a way compatible with pure evaluation)
      nixpkgs.overlays = [
        (final: prev: {
          mesa = final.mesa-asahi-edge;
        })
      ];
    })
  ];

  options.hardware.asahi.useExperimentalGPUDriver = lib.mkOption {
    type = lib.types.bool;
    default = false;
    description = ''
      Use the experimental Asahi Mesa GPU driver.

      Do not report issues using this driver under NixOS to the Asahi project.
    '';
  };

  options.hardware.asahi.experimentalGPUInstallMode = lib.mkOption {
    type = lib.types.enum [ "driver" "replace" "overlay" ];
    default = "replace";
    description = ''
      Mode to use to install the experimental GPU driver into the system.

      driver: install only as a driver, do not replace system Mesa.
        Causes issues with certain programs like Plasma Wayland.

      replace (default): use replaceRuntimeDependencies to replace system Mesa with Asahi Mesa.
        Does not work in pure evaluation context (i.e. in flakes by default).

      overlay: overlay system Mesa with Asahi Mesa
        Requires rebuilding the world.
    '';
  };
}