at 23.11-pre 5.3 kB view raw
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" ] "S3TC support is now always enabled in Mesa.") 30 ]; 31 32 options = { 33 34 hardware.opengl = { 35 enable = mkOption { 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 43 programs.sway.enable. 44 ''; 45 type = types.bool; 46 default = false; 47 }; 48 49 driSupport = mkOption { 50 type = types.bool; 51 default = true; 52 description = lib.mdDoc '' 53 Whether to enable accelerated OpenGL rendering through the 54 Direct Rendering Interface (DRI). 55 ''; 56 }; 57 58 driSupport32Bit = mkOption { 59 type = types.bool; 60 default = false; 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 65 `Mesa`. 66 ''; 67 }; 68 69 package = mkOption { 70 type = types.package; 71 internal = true; 72 description = lib.mdDoc '' 73 The package that provides the OpenGL implementation. 74 ''; 75 }; 76 77 package32 = mkOption { 78 type = types.package; 79 internal = true; 80 description = lib.mdDoc '' 81 The package that provides the 32-bit OpenGL implementation on 82 64-bit systems. Used when {option}`driSupport32Bit` is 83 set. 84 ''; 85 }; 86 87 extraPackages = mkOption { 88 type = types.listOf types.package; 89 default = []; 90 example = literalExpression "with pkgs; [ intel-media-driver intel-ocl vaapiIntel ]"; 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. 94 95 ::: {.note} 96 intel-media-driver supports hardware Broadwell (2014) or newer. Older hardware should use the mostly unmaintained vaapiIntel driver. 97 ::: 98 ''; 99 }; 100 101 extraPackages32 = mkOption { 102 type = types.listOf types.package; 103 default = []; 104 example = literalExpression "with pkgs.pkgsi686Linux; [ intel-media-driver vaapiIntel ]"; 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. 108 109 ::: {.note} 110 intel-media-driver supports hardware Broadwell (2014) or newer. Older hardware should use the mostly unmaintained vaapiIntel driver. 111 ::: 112 ''; 113 }; 114 115 setLdLibraryPath = mkOption { 116 type = types.bool; 117 internal = true; 118 default = false; 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. 125 ''; 126 }; 127 }; 128 129 }; 130 131 config = mkIf cfg.enable { 132 assertions = [ 133 { assertion = cfg.driSupport32Bit -> pkgs.stdenv.isx86_64; 134 message = "Option driSupport32Bit only makes sense on a 64-bit system."; 135 } 136 { assertion = cfg.driSupport32Bit -> (config.boot.kernelPackages.kernel.features.ia32Emulation or false); 137 message = "Option driSupport32Bit requires a kernel that supports 32bit emulation"; 138 } 139 ]; 140 141 systemd.tmpfiles.rules = [ 142 "L+ /run/opengl-driver - - - - ${package}" 143 ( 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}" 148 else 149 "r /run/opengl-driver-32" 150 ) 151 ]; 152 153 environment.sessionVariables.LD_LIBRARY_PATH = mkIf cfg.setLdLibraryPath 154 ([ "/run/opengl-driver/lib" ] ++ optional cfg.driSupport32Bit "/run/opengl-driver-32/lib"); 155 156 hardware.opengl.package = mkDefault pkgs.mesa.drivers; 157 hardware.opengl.package32 = mkDefault pkgs.pkgsi686Linux.mesa.drivers; 158 159 boot.extraModulePackages = optional (elem "virtualbox" videoDrivers) kernelPackages.virtualboxGuestAdditions; 160 }; 161}