diff --git a/nixos/doc/manual/configuration/gpu-accel.chapter.md b/nixos/doc/manual/configuration/gpu-accel.chapter.md index dfccdf291b736..4dabc2748b390 100644 --- a/nixos/doc/manual/configuration/gpu-accel.chapter.md +++ b/nixos/doc/manual/configuration/gpu-accel.chapter.md @@ -30,7 +30,7 @@ $ export \ ``` The second mechanism is to add the OpenCL driver package to -[](#opt-hardware.opengl.extraPackages). +[](#opt-hardware.impure-drivers.packages). This links the ICD file under `/run/opengl-driver`, where it will be visible to the ICD loader. @@ -51,11 +51,11 @@ Platform Vendor Advanced Micro Devices, Inc. Modern AMD [Graphics Core Next](https://en.wikipedia.org/wiki/Graphics_Core_Next) (GCN) GPUs are supported through the rocmPackages.clr.icd package. Adding this package to -[](#opt-hardware.opengl.extraPackages) +[](#opt-hardware.impure-drivers.packages) enables OpenCL support: ```nix -hardware.opengl.extraPackages = [ +hardware.impure-drivers.packages = [ rocmPackages.clr.icd ]; ``` @@ -71,12 +71,12 @@ proprietary Intel OpenCL runtime, in the intel-ocl package, is an alternative for Gen7 GPUs. The intel-compute-runtime, beignet, or intel-ocl package can be added to -[](#opt-hardware.opengl.extraPackages) +[](#opt-hardware.impure-drivers.packages) to enable OpenCL support. For example, for Gen8 and later GPUs, the following configuration can be used: ```nix -hardware.opengl.extraPackages = [ +hardware.impure-drivers.packages = [ intel-compute-runtime ]; ``` @@ -88,7 +88,7 @@ compute API for GPUs. It is used directly by games or indirectly though compatibility layers like [DXVK](https://github.com/doitsujin/dxvk/wiki). -By default, if [](#opt-hardware.opengl.driSupport) +By default, if [](#opt-hardware.impure-drivers.opengl.driSupport) is enabled, mesa is installed and provides Vulkan for supported hardware. Similar to OpenCL, Vulkan drivers are loaded through the *Installable @@ -108,7 +108,7 @@ $ export \ ``` The second mechanism is to add the Vulkan driver package to -[](#opt-hardware.opengl.extraPackages). +[](#opt-hardware.impure-drivers.packages). This links the ICD file under `/run/opengl-driver`, where it will be visible to the ICD loader. @@ -138,7 +138,7 @@ Modern AMD [Graphics Core Next](https://en.wikipedia.org/wiki/Graphics_Core_Next) (GCN) GPUs are supported through either radv, which is part of mesa, or the amdvlk package. Adding the amdvlk package to -[](#opt-hardware.opengl.extraPackages) +[](#opt-hardware.impure-drivers.packages) makes amdvlk the default driver and hides radv and lavapipe from the device list. A specific driver can be forced as follows: @@ -167,7 +167,7 @@ graphics hardware acceleration capabilities for video processing. VA-API drivers are loaded by `libva`. The version in nixpkgs is built to search the opengl driver path, so drivers can be installed in -[](#opt-hardware.opengl.extraPackages). +[](#opt-hardware.impure-drivers.packages). VA-API can be tested using: diff --git a/nixos/doc/manual/configuration/x-windows.chapter.md b/nixos/doc/manual/configuration/x-windows.chapter.md index 0451e4d25265f..f4dd1eb200b94 100644 --- a/nixos/doc/manual/configuration/x-windows.chapter.md +++ b/nixos/doc/manual/configuration/x-windows.chapter.md @@ -66,7 +66,7 @@ On 64-bit systems, if you want OpenGL for 32-bit programs such as in Wine, you should also set the following: ```nix -hardware.opengl.driSupport32Bit = true; +hardware.impure-drivers.opengl.driSupport32Bit = true; ``` ## Auto-login {#sec-x11-auto-login} diff --git a/nixos/modules/hardware/opengl.nix b/nixos/modules/hardware/opengl.nix index 0ff018ddc47d1..3f726e4e55ca0 100644 --- a/nixos/modules/hardware/opengl.nix +++ b/nixos/modules/hardware/opengl.nix @@ -4,7 +4,10 @@ with lib; let - cfg = config.hardware.opengl; + cfg = config.hardware.impure-drivers; + + impurePath = pkgs.addDriverRunpath.driverLink; + impurePath32 = pkgs.pkgsi686Linux.addDriverRunpath.driverLink; kernelPackages = config.boot.kernelPackages; @@ -12,12 +15,12 @@ let package = pkgs.buildEnv { name = "opengl-drivers"; - paths = [ cfg.package ] ++ cfg.extraPackages; + paths = cfg.packages; }; package32 = pkgs.buildEnv { name = "opengl-drivers-32bit"; - paths = [ cfg.package32 ] ++ cfg.extraPackages32; + paths = cfg.packages32; }; in @@ -25,14 +28,66 @@ in { imports = [ - (mkRenamedOptionModule [ "services" "xserver" "vaapiDrivers" ] [ "hardware" "opengl" "extraPackages" ]) + (mkRenamedOptionModule [ "services" "xserver" "vaapiDrivers" ] [ "hardware" "impure-drivers" "packages" ]) (mkRemovedOptionModule [ "hardware" "opengl" "s3tcSupport" ] "S3TC support is now always enabled in Mesa.") + + # The old option `hardware.opengl.enable` corresponds to `hardware.impure-drivers.opengl.enable` (defaults to `true`). + # However, in order support the transition of the systems that have been setting `hardware.opengl.enable`, + # we need to translate it into `hardware.impure-drivers.enable` (defaults to `false`) + (mkRenamedOptionModule [ "hardware" "opengl" "enable" ] [ "hardware" "impure-drivers" "enable" ]) + (mkRenamedOptionModule [ "hardware" "opengl" "extraPackages32" ] [ "hardware" "impure-drivers" "packages32" ]) + (mkRenamedOptionModule [ "hardware" "opengl" "extraPackages" ] [ "hardware" "impure-drivers" "packages" ]) + + # Since we've treated `hardware.opengl.enable` specially, we cannot just use + # `(mkRenamedOptionModule [ "hardware" "opengl" ] [ "hardware" "impure-drivers" "opengl" ])`. + (mkRenamedOptionModule [ "hardware" "opengl" "driSupport32Bit" ] [ "hardware" "impure-drivers" "opengl" "driSupport32Bit" ]) + (mkRenamedOptionModule [ "hardware" "opengl" "driSupport" ] [ "hardware" "impure-drivers" "opengl" "driSupport" ]) + (mkRenamedOptionModule [ "hardware" "opengl" "package32" ] [ "hardware" "impure-drivers" "opengl" "package32" ]) + (mkRenamedOptionModule [ "hardware" "opengl" "package" ] [ "hardware" "impure-drivers" "opengl" "package" ]) + (mkRenamedOptionModule [ "hardware" "opengl" "setLdLibraryPath" ] [ "hardware" "impure-drivers" "setLdLibraryPath" ]) ]; options = { - hardware.opengl = { - enable = mkOption { + hardware.impure-drivers = { + + enable = mkEnableOption (lib.mdDoc '' + Deploy user-space drivers in the impure location expected by Nixpkgs. + This may be necessary to use graphical (OpenGL, Vulkan) or + hardware-acclerated (CUDA) applications from Nixpkgs. + + ::: {.note} + In the current implementation, this will create a directory at + `/run/opengl-driver/lib` (`pkgs.addDriverRunpath.driverLink`), + populated with symlinks to the enabled driver libraries. + ::: + ''); + + packages = mkOption { + type = types.listOf types.package; + default = []; + example = literalExpression "with pkgs; [ intel-media-driver intel-ocl intel-vaapi-driver config.hardware.nvidia.package ]"; + description = lib.mdDoc '' + Packages to deploy in the user-space drivers' impure location. + This can be used to add e.g. OpenCL, VA-API/VDPAU, or CUDA drivers. + + ::: {.note} + intel-media-driver supports hardware Broadwell (2014) or newer. Older hardware should use the mostly unmaintained intel-vaapi-driver driver. + ::: + ''; + }; + + packages32 = mkOption { + type = types.listOf types.package; + default = []; + example = literalExpression "with pkgs.pkgsi686Linux; [ intel-media-driver intel-vaapi-driver ]"; + description = lib.mdDoc '' + Packages to deploy in the 32-bit user-space drivers' impure location. + Used when {option}`driSupport32Bit` is set. Cf. the documentation for [](#opt-hardware.impure-drivers.packages). + ''; + }; + + opengl.enable = mkOption { description = lib.mdDoc '' Whether to enable OpenGL drivers. This is needed to enable OpenGL support in X11 systems, as well as for Wayland compositors @@ -43,10 +98,10 @@ in programs.sway.enable. ''; type = types.bool; - default = false; + default = true; }; - driSupport = mkOption { + opengl.driSupport = mkOption { type = types.bool; default = true; description = lib.mdDoc '' @@ -55,7 +110,7 @@ in ''; }; - driSupport32Bit = mkOption { + opengl.driSupport32Bit = mkOption { type = types.bool; default = false; description = lib.mdDoc '' @@ -66,7 +121,7 @@ in ''; }; - package = mkOption { + opengl.package = mkOption { type = types.package; internal = true; description = lib.mdDoc '' @@ -74,7 +129,7 @@ in ''; }; - package32 = mkOption { + opengl.package32 = mkOption { type = types.package; internal = true; description = lib.mdDoc '' @@ -84,34 +139,6 @@ in ''; }; - extraPackages = mkOption { - type = types.listOf types.package; - default = []; - example = literalExpression "with pkgs; [ intel-media-driver intel-ocl intel-vaapi-driver ]"; - description = lib.mdDoc '' - Additional packages to add to OpenGL drivers. - This can be used to add OpenCL drivers, VA-API/VDPAU drivers etc. - - ::: {.note} - intel-media-driver supports hardware Broadwell (2014) or newer. Older hardware should use the mostly unmaintained intel-vaapi-driver driver. - ::: - ''; - }; - - extraPackages32 = mkOption { - type = types.listOf types.package; - default = []; - example = literalExpression "with pkgs.pkgsi686Linux; [ intel-media-driver intel-vaapi-driver ]"; - description = lib.mdDoc '' - Additional packages to add to 32-bit OpenGL drivers on 64-bit systems. - Used when {option}`driSupport32Bit` is set. This can be used to add OpenCL drivers, VA-API/VDPAU drivers etc. - - ::: {.note} - intel-media-driver supports hardware Broadwell (2014) or newer. Older hardware should use the mostly unmaintained intel-vaapi-driver driver. - ::: - ''; - }; - setLdLibraryPath = mkOption { type = types.bool; internal = true; @@ -129,32 +156,35 @@ in }; config = mkIf cfg.enable { - assertions = [ - { assertion = cfg.driSupport32Bit -> pkgs.stdenv.isx86_64; + assertions = mkIf cfg.opengl.enable [ + { assertion = cfg.opengl.driSupport32Bit -> pkgs.stdenv.isx86_64; message = "Option driSupport32Bit only makes sense on a 64-bit system."; } - { assertion = cfg.driSupport32Bit -> (config.boot.kernelPackages.kernel.features.ia32Emulation or false); + { assertion = cfg.opengl.driSupport32Bit -> (config.boot.kernelPackages.kernel.features.ia32Emulation or false); message = "Option driSupport32Bit requires a kernel that supports 32bit emulation"; } ]; systemd.tmpfiles.rules = [ - "L+ /run/opengl-driver - - - - ${package}" + "L+ ${impurePath} - - - - ${package}" ( if pkgs.stdenv.isi686 then - "L+ /run/opengl-driver-32 - - - - opengl-driver" - else if cfg.driSupport32Bit then - "L+ /run/opengl-driver-32 - - - - ${package32}" + "L+ ${impurePath32} - - - - ${impurePath}" + else if cfg.opengl.driSupport32Bit then + "L+ ${impurePath32} - - - - ${package32}" else - "r /run/opengl-driver-32" + "r ${impurePath32}" ) ]; environment.sessionVariables.LD_LIBRARY_PATH = mkIf cfg.setLdLibraryPath - ([ "/run/opengl-driver/lib" ] ++ optional cfg.driSupport32Bit "/run/opengl-driver-32/lib"); + ([ "${impurePath}/lib" ] ++ optionals cfg.driSupport32Bit ["${impurePath32}/lib"]); + + hardware.impure-drivers.opengl.package = mkDefault pkgs.mesa.drivers; + hardware.impure-drivers.opengl.package32 = mkDefault pkgs.pkgsi686Linux.mesa.drivers; - hardware.opengl.package = mkDefault pkgs.mesa.drivers; - hardware.opengl.package32 = mkDefault pkgs.pkgsi686Linux.mesa.drivers; + hardware.impure-drivers.packages = mkIf cfg.opengl.enable [ cfg.opengl.package ]; + hardware.impure-drivers.packages32 = mkIf cfg.opengl.enable [ cfg.opengl.package32 ]; boot.extraModulePackages = optional (elem "virtualbox" videoDrivers) kernelPackages.virtualboxGuestAdditions; }; diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix index 3b983f768f91a..24c0456156676 100644 --- a/nixos/modules/hardware/video/nvidia.nix +++ b/nixos/modules/hardware/video/nvidia.nix @@ -286,11 +286,11 @@ in { KERNEL=="nvidia_uvm", RUN+="${pkgs.runtimeShell} -c 'mknod -m 666 /dev/nvidia-uvm c $$(grep nvidia-uvm /proc/devices | cut -d \ -f 1) 0'" KERNEL=="nvidia_uvm", RUN+="${pkgs.runtimeShell} -c 'mknod -m 666 /dev/nvidia-uvm-tools c $$(grep nvidia-uvm /proc/devices | cut -d \ -f 1) 1'" ''; - hardware.opengl = { - extraPackages = [ + hardware.impure-drivers = { + packages = [ nvidia_x11.out ]; - extraPackages32 = [ + packages32 = [ nvidia_x11.lib32 ]; }; @@ -453,11 +453,11 @@ in { "egl/egl_external_platform.d".source = "/run/opengl-driver/share/egl/egl_external_platform.d/"; }; - hardware.opengl = { - extraPackages = [ + hardware.impure-drivers = { + packages = [ pkgs.nvidia-vaapi-driver ]; - extraPackages32 = [ + packages32 = [ pkgs.pkgsi686Linux.nvidia-vaapi-driver ]; }; diff --git a/nixos/modules/services/x11/xserver.nix b/nixos/modules/services/x11/xserver.nix index 4a8f2f61caaf4..48c6a09881eb9 100644 --- a/nixos/modules/services/x11/xserver.nix +++ b/nixos/modules/services/x11/xserver.nix @@ -661,7 +661,7 @@ in || dmConf.lightdm.enable); in mkIf (noDmUsed) (mkDefault false); - hardware.opengl.enable = mkDefault true; + hardware.impure-drivers.enable = mkDefault true; services.xserver.videoDrivers = mkIf (cfg.videoDriver != null) [ cfg.videoDriver ]; @@ -759,8 +759,8 @@ in restartIfChanged = false; environment = - optionalAttrs config.hardware.opengl.setLdLibraryPath - { LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.addOpenGLRunpath.driverLink ]; } + optionalAttrs config.impure-drivers.setLdLibraryPath + { LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.addDriverRunpath.driverLink ]; } // cfg.displayManager.job.environment; preStart =