at 18.03-beta 4.8 kB view raw
1{ config, lib, pkgs, pkgs_i686, ... }: 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 makePackage = p: pkgs.buildEnv { 14 name = "mesa-drivers+txc-${p.mesa_drivers.version}"; 15 paths = 16 [ p.mesa_drivers 17 p.mesa_drivers.out # mainly for libGL 18 (if cfg.s3tcSupport then p.libtxc_dxtn else p.libtxc_dxtn_s2tc) 19 ]; 20 }; 21 22 package = pkgs.buildEnv { 23 name = "opengl-drivers"; 24 paths = [ cfg.package ] ++ cfg.extraPackages; 25 }; 26 27 package32 = pkgs.buildEnv { 28 name = "opengl-drivers-32bit"; 29 paths = [ cfg.package32 ] ++ cfg.extraPackages32; 30 }; 31 32in 33 34{ 35 options = { 36 hardware.opengl.enable = mkOption { 37 description = '' 38 Whether to enable OpenGL drivers. This is needed to enable 39 OpenGL support in X11 systems, as well as for Wayland compositors 40 like sway, way-cooler and Weston. It is enabled by default 41 by the corresponding modules, so you do not usually have to 42 set it yourself, only if there is no module for your wayland 43 compositor of choice. See services.xserver.enable, 44 programs.sway.enable, and programs.way-cooler.enable. 45 ''; 46 type = types.bool; 47 default = false; 48 }; 49 50 hardware.opengl.driSupport = mkOption { 51 type = types.bool; 52 default = true; 53 description = '' 54 Whether to enable accelerated OpenGL rendering through the 55 Direct Rendering Interface (DRI). 56 ''; 57 }; 58 59 hardware.opengl.driSupport32Bit = mkOption { 60 type = types.bool; 61 default = false; 62 description = '' 63 On 64-bit systems, whether to support Direct Rendering for 64 32-bit applications (such as Wine). This is currently only 65 supported for the <literal>nvidia</literal> and 66 <literal>ati_unfree</literal> drivers, as well as 67 <literal>Mesa</literal>. 68 ''; 69 }; 70 71 hardware.opengl.s3tcSupport = mkOption { 72 type = types.bool; 73 default = false; 74 description = '' 75 Make S3TC(S3 Texture Compression) via libtxc_dxtn available 76 to OpenGL drivers instead of the patent-free S2TC replacement. 77 78 Using this library may require a patent license depending on your location. 79 ''; 80 }; 81 82 hardware.opengl.package = mkOption { 83 type = types.package; 84 internal = true; 85 description = '' 86 The package that provides the OpenGL implementation. 87 ''; 88 }; 89 90 hardware.opengl.package32 = mkOption { 91 type = types.package; 92 internal = true; 93 description = '' 94 The package that provides the 32-bit OpenGL implementation on 95 64-bit systems. Used when <option>driSupport32Bit</option> is 96 set. 97 ''; 98 }; 99 100 hardware.opengl.extraPackages = mkOption { 101 type = types.listOf types.package; 102 default = []; 103 example = literalExample "with pkgs; [ vaapiIntel libvdpau-va-gl vaapiVdpau intel-ocl ]"; 104 description = '' 105 Additional packages to add to OpenGL drivers. This can be used 106 to add OpenCL drivers, VA-API/VDPAU drivers etc. 107 ''; 108 }; 109 110 hardware.opengl.extraPackages32 = mkOption { 111 type = types.listOf types.package; 112 default = []; 113 example = literalExample "with pkgs.pkgsi686Linux; [ vaapiIntel libvdpau-va-gl vaapiVdpau ]"; 114 description = '' 115 Additional packages to add to 32-bit OpenGL drivers on 116 64-bit systems. Used when <option>driSupport32Bit</option> is 117 set. This can be used to add OpenCL drivers, VA-API/VDPAU drivers etc. 118 ''; 119 }; 120 121 }; 122 123 config = mkIf cfg.enable { 124 125 assertions = lib.singleton { 126 assertion = cfg.driSupport32Bit -> pkgs.stdenv.isx86_64; 127 message = "Option driSupport32Bit only makes sense on a 64-bit system."; 128 }; 129 130 system.activationScripts.setup-opengl = 131 '' 132 ln -sfn ${package} /run/opengl-driver 133 ${if pkgs.stdenv.isi686 then '' 134 ln -sfn opengl-driver /run/opengl-driver-32 135 '' else if cfg.driSupport32Bit then '' 136 ln -sfn ${package32} /run/opengl-driver-32 137 '' else '' 138 rm -f /run/opengl-driver-32 139 ''} 140 ''; 141 142 environment.sessionVariables.LD_LIBRARY_PATH = 143 [ "/run/opengl-driver/lib" ] ++ optional cfg.driSupport32Bit "/run/opengl-driver-32/lib"; 144 145 environment.variables.XDG_DATA_DIRS = 146 [ "/run/opengl-driver/share" ] ++ optional cfg.driSupport32Bit "/run/opengl-driver-32/share"; 147 148 hardware.opengl.package = mkDefault (makePackage pkgs); 149 hardware.opengl.package32 = mkDefault (makePackage pkgs_i686); 150 151 boot.extraModulePackages = optional (elem "virtualbox" videoDrivers) kernelPackages.virtualboxGuestAdditions; 152 }; 153}