1 { config, lib, pkgs, ... }:
7 cfg = config.hardware.opengl;
9 kernelPackages = config.boot.kernelPackages;
11 videoDrivers = config.services.xserver.videoDrivers;
13 package = pkgs.buildEnv {
14 name = "opengl-drivers";
15 paths = [ cfg.package ] ++ cfg.extraPackages;
18 package32 = pkgs.buildEnv {
19 name = "opengl-drivers-32bit";
20 paths = [ cfg.package32 ] ++ cfg.extraPackages32;
28 (mkRenamedOptionModule [ "services" "xserver" "vaapiDrivers" ] [ "hardware" "opengl" "extraPackages" ])
29 (mkRemovedOptionModule [ "hardware" "opengl" "s3tcSupport" ] "S3TC support is now always enabled in Mesa.")
36 description = lib.mdDoc ''
37 Whether to enable OpenGL drivers. This is needed to enable
38 OpenGL support in X11 systems, as well as for Wayland compositors
39 like sway and Weston. It is enabled by default
40 by the corresponding modules, so you do not usually have to
41 set it yourself, only if there is no module for your wayland
42 compositor of choice. See services.xserver.enable and
49 driSupport = mkOption {
52 description = lib.mdDoc ''
53 Whether to enable accelerated OpenGL rendering through the
54 Direct Rendering Interface (DRI).
58 driSupport32Bit = mkOption {
61 description = lib.mdDoc ''
62 On 64-bit systems, whether to support Direct Rendering for
63 32-bit applications (such as Wine). This is currently only
64 supported for the `nvidia` as well as
72 description = lib.mdDoc ''
73 The package that provides the OpenGL implementation.
77 package32 = mkOption {
80 description = lib.mdDoc ''
81 The package that provides the 32-bit OpenGL implementation on
82 64-bit systems. Used when {option}`driSupport32Bit` is
87 extraPackages = mkOption {
88 type = types.listOf types.package;
90 example = literalExpression "with pkgs; [ intel-media-driver intel-ocl intel-vaapi-driver ]";
91 description = lib.mdDoc ''
92 Additional packages to add to OpenGL drivers.
93 This can be used to add OpenCL drivers, VA-API/VDPAU drivers etc.
96 intel-media-driver supports hardware Broadwell (2014) or newer. Older hardware should use the mostly unmaintained intel-vaapi-driver driver.
101 extraPackages32 = mkOption {
102 type = types.listOf types.package;
104 example = literalExpression "with pkgs.pkgsi686Linux; [ intel-media-driver intel-vaapi-driver ]";
105 description = lib.mdDoc ''
106 Additional packages to add to 32-bit OpenGL drivers on 64-bit systems.
107 Used when {option}`driSupport32Bit` is set. This can be used to add OpenCL drivers, VA-API/VDPAU drivers etc.
110 intel-media-driver supports hardware Broadwell (2014) or newer. Older hardware should use the mostly unmaintained intel-vaapi-driver driver.
115 setLdLibraryPath = mkOption {
119 description = lib.mdDoc ''
120 Whether the `LD_LIBRARY_PATH` environment variable
121 should be set to the locations of driver libraries. Drivers which
122 rely on overriding libraries should set this to true. Drivers which
123 support `libglvnd` and other dispatch libraries
124 instead of overriding libraries should not set this.
131 config = mkIf cfg.enable {
133 { assertion = cfg.driSupport32Bit -> pkgs.stdenv.isx86_64;
134 message = "Option driSupport32Bit only makes sense on a 64-bit system.";
136 { assertion = cfg.driSupport32Bit -> (config.boot.kernelPackages.kernel.features.ia32Emulation or false);
137 message = "Option driSupport32Bit requires a kernel that supports 32bit emulation";
141 systemd.tmpfiles.rules = [
142 "L+ /run/opengl-driver - - - - ${package}"
144 if pkgs.stdenv.isi686 then
145 "L+ /run/opengl-driver-32 - - - - opengl-driver"
146 else if cfg.driSupport32Bit then
147 "L+ /run/opengl-driver-32 - - - - ${package32}"
149 "r /run/opengl-driver-32"
153 environment.sessionVariables.LD_LIBRARY_PATH = mkIf cfg.setLdLibraryPath
154 ([ "/run/opengl-driver/lib" ] ++ optional cfg.driSupport32Bit "/run/opengl-driver-32/lib");
156 hardware.opengl.package = mkDefault pkgs.mesa.drivers;
157 hardware.opengl.package32 = mkDefault pkgs.pkgsi686Linux.mesa.drivers;
159 boot.extraModulePackages = optional (elem "virtualbox" videoDrivers) kernelPackages.virtualboxGuestAdditions;