1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.hardware.opengl;
8
9 kernelPackages = config.boot.kernelPackages;
10
11 videoDrivers = config.services.xserver.videoDrivers;
12
13 package = pkgs.buildEnv {
14 name = "opengl-drivers";
15 paths = [ cfg.package ] ++ cfg.extraPackages;
16 };
17
18 package32 = pkgs.buildEnv {
19 name = "opengl-drivers-32bit";
20 paths = [ cfg.package32 ] ++ cfg.extraPackages32;
21 };
22
23in
24
25{
26
27 imports = [
28 (mkRenamedOptionModule [ "services" "xserver" "vaapiDrivers" ] [ "hardware" "opengl" "extraPackages" ])
29 (mkRemovedOptionModule [ "hardware" "opengl" "s3tcSupport" ] ''
30 S3TC support is now always enabled in Mesa.
31 '')
32 ];
33
34 options = {
35
36 hardware.opengl = {
37 enable = mkOption {
38 description = ''
39 Whether to enable OpenGL drivers. This is needed to enable
40 OpenGL support in X11 systems, as well as for Wayland compositors
41 like sway and Weston. It is enabled by default
42 by the corresponding modules, so you do not usually have to
43 set it yourself, only if there is no module for your wayland
44 compositor of choice. See services.xserver.enable and
45 programs.sway.enable.
46 '';
47 type = types.bool;
48 default = false;
49 };
50
51 driSupport = mkOption {
52 type = types.bool;
53 default = true;
54 description = ''
55 Whether to enable accelerated OpenGL rendering through the
56 Direct Rendering Interface (DRI).
57 '';
58 };
59
60 driSupport32Bit = mkOption {
61 type = types.bool;
62 default = false;
63 description = ''
64 On 64-bit systems, whether to support Direct Rendering for
65 32-bit applications (such as Wine). This is currently only
66 supported for the <literal>nvidia</literal> as well as
67 <literal>Mesa</literal>.
68 '';
69 };
70
71 package = mkOption {
72 type = types.package;
73 internal = true;
74 description = ''
75 The package that provides the OpenGL implementation.
76 '';
77 };
78
79 package32 = mkOption {
80 type = types.package;
81 internal = true;
82 description = ''
83 The package that provides the 32-bit OpenGL implementation on
84 64-bit systems. Used when <option>driSupport32Bit</option> is
85 set.
86 '';
87 };
88
89 extraPackages = mkOption {
90 type = types.listOf types.package;
91 default = [];
92 example = literalExpression "with pkgs; [ vaapiIntel libvdpau-va-gl vaapiVdpau intel-ocl ]";
93 description = ''
94 Additional packages to add to OpenGL drivers. This can be used
95 to add OpenCL drivers, VA-API/VDPAU drivers etc.
96 '';
97 };
98
99 extraPackages32 = mkOption {
100 type = types.listOf types.package;
101 default = [];
102 example = literalExpression "with pkgs.pkgsi686Linux; [ vaapiIntel libvdpau-va-gl vaapiVdpau ]";
103 description = ''
104 Additional packages to add to 32-bit OpenGL drivers on
105 64-bit systems. Used when <option>driSupport32Bit</option> is
106 set. This can be used to add OpenCL drivers, VA-API/VDPAU drivers etc.
107 '';
108 };
109
110 setLdLibraryPath = mkOption {
111 type = types.bool;
112 internal = true;
113 default = false;
114 description = ''
115 Whether the <literal>LD_LIBRARY_PATH</literal> environment variable
116 should be set to the locations of driver libraries. Drivers which
117 rely on overriding libraries should set this to true. Drivers which
118 support <literal>libglvnd</literal> and other dispatch libraries
119 instead of overriding libraries should not set this.
120 '';
121 };
122 };
123
124 };
125
126 config = mkIf cfg.enable {
127
128 assertions = [
129 { assertion = cfg.driSupport32Bit -> pkgs.stdenv.isx86_64;
130 message = "Option driSupport32Bit only makes sense on a 64-bit system.";
131 }
132 { assertion = cfg.driSupport32Bit -> (config.boot.kernelPackages.kernel.features.ia32Emulation or false);
133 message = "Option driSupport32Bit requires a kernel that supports 32bit emulation";
134 }
135 ];
136
137 systemd.tmpfiles.rules = [
138 "L+ /run/opengl-driver - - - - ${package}"
139 (
140 if pkgs.stdenv.isi686 then
141 "L+ /run/opengl-driver-32 - - - - opengl-driver"
142 else if cfg.driSupport32Bit then
143 "L+ /run/opengl-driver-32 - - - - ${package32}"
144 else
145 "r /run/opengl-driver-32"
146 )
147 ];
148
149 environment.sessionVariables.LD_LIBRARY_PATH = mkIf cfg.setLdLibraryPath
150 ([ "/run/opengl-driver/lib" ] ++ optional cfg.driSupport32Bit "/run/opengl-driver-32/lib");
151
152 hardware.opengl.package = mkDefault pkgs.mesa.drivers;
153 hardware.opengl.package32 = mkDefault pkgs.pkgsi686Linux.mesa.drivers;
154
155 boot.extraModulePackages = optional (elem "virtualbox" videoDrivers) kernelPackages.virtualboxGuestAdditions;
156 };
157}