1 { config, lib, pkgs, ... }:
3 cfg = config.hardware.graphics;
5 driversEnv = pkgs.buildEnv {
6 name = "graphics-drivers";
7 paths = [ cfg.package ] ++ cfg.extraPackages;
10 driversEnv32 = pkgs.buildEnv {
11 name = "graphics-drivers-32bit";
12 paths = [ cfg.package32 ] ++ cfg.extraPackages32;
17 (lib.mkRenamedOptionModule [ "services" "xserver" "vaapiDrivers" ] [ "hardware" "graphics" "extraPackages" ])
18 (lib.mkRemovedOptionModule [ "hardware" "opengl" "s3tcSupport" ] "S3TC support is now always enabled in Mesa.")
19 (lib.mkRemovedOptionModule [ "hardware" "opengl" "driSupport"] "The setting can be removed.")
21 (lib.mkRenamedOptionModule [ "hardware" "opengl" "enable"] [ "hardware" "graphics" "enable" ])
22 (lib.mkRenamedOptionModule [ "hardware" "opengl" "driSupport32Bit"] [ "hardware" "graphics" "enable32Bit" ])
23 (lib.mkRenamedOptionModule [ "hardware" "opengl" "package"] [ "hardware" "graphics" "package" ])
24 (lib.mkRenamedOptionModule [ "hardware" "opengl" "package32"] [ "hardware" "graphics" "package32" ])
25 (lib.mkRenamedOptionModule [ "hardware" "opengl" "extraPackages"] [ "hardware" "graphics" "extraPackages" ])
26 (lib.mkRenamedOptionModule [ "hardware" "opengl" "extraPackages32"] [ "hardware" "graphics" "extraPackages32" ])
29 options.hardware.graphics = {
30 enable = lib.mkOption {
32 Whether to enable hardware accelerated graphics drivers.
34 This is required to allow most graphical applications and
35 environments to use hardware rendering, video encode/decode
38 This option should be enabled by default by the corresponding modules,
39 so you do not usually have to set it yourself.
41 type = lib.types.bool;
45 enable32Bit = lib.mkOption {
47 On 64-bit systems, whether to also install 32-bit drivers for
48 32-bit applications (such as Wine).
50 type = lib.types.bool;
54 package = lib.mkOption {
56 The package that provides the default driver set.
58 type = lib.types.package;
62 package32 = lib.mkOption {
64 The package that provides the 32-bit driver set. Used when {option}`enable32Bit` is enabled.
67 type = lib.types.package;
71 extraPackages = lib.mkOption {
73 Additional packages to add to the default graphics driver lookup path.
74 This can be used to add OpenCL drivers, VA-API/VDPAU drivers, etc.
77 intel-media-driver supports hardware Broadwell (2014) or newer. Older hardware should use the mostly unmaintained intel-vaapi-driver driver.
80 type = lib.types.listOf lib.types.package;
82 example = lib.literalExpression "with pkgs; [ intel-media-driver intel-ocl intel-vaapi-driver ]";
85 extraPackages32 = lib.mkOption {
87 Additional packages to add to 32-bit graphics driver lookup path on 64-bit systems.
88 Used when {option}`enable32Bit` is set. This can be used to add OpenCL drivers, VA-API/VDPAU drivers, etc.
91 intel-media-driver supports hardware Broadwell (2014) or newer. Older hardware should use the mostly unmaintained intel-vaapi-driver driver.
94 type = lib.types.listOf lib.types.package;
96 example = lib.literalExpression "with pkgs.pkgsi686Linux; [ intel-media-driver intel-vaapi-driver ]";
100 config = lib.mkIf cfg.enable {
103 assertion = cfg.enable32Bit -> pkgs.stdenv.hostPlatform.isx86_64;
104 message = "`hardware.graphics.enable32Bit` only makes sense on a 64-bit system.";
107 assertion = cfg.enable32Bit -> (config.boot.kernelPackages.kernel.features.ia32Emulation or false);
108 message = "`hardware.graphics.enable32Bit` requires a kernel that supports 32-bit emulation";
112 systemd.tmpfiles.settings.graphics-driver = {
113 "/run/opengl-driver"."L+".argument = toString driversEnv;
114 "/run/opengl-driver-32" =
115 if pkgs.stdenv.hostPlatform.isi686 then
116 { "L+".argument = "opengl-driver"; }
117 else if cfg.enable32Bit then
118 { "L+".argument = toString driversEnv32; }
123 hardware.graphics.package = lib.mkDefault pkgs.mesa.drivers;
124 hardware.graphics.package32 = lib.mkDefault pkgs.pkgsi686Linux.mesa.drivers;