Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions nixos/doc/manual/configuration/gpu-accel.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
];
```
Expand All @@ -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
];
```
Expand All @@ -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
Expand All @@ -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.

Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion nixos/doc/manual/configuration/x-windows.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
130 changes: 80 additions & 50 deletions nixos/modules/hardware/opengl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,90 @@ 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;

videoDrivers = config.services.xserver.videoDrivers;

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

{

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
Expand All @@ -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 ''
Expand All @@ -55,7 +110,7 @@ in
'';
};

driSupport32Bit = mkOption {
opengl.driSupport32Bit = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Expand All @@ -66,15 +121,15 @@ in
'';
};

package = mkOption {
opengl.package = mkOption {
type = types.package;
internal = true;
description = lib.mdDoc ''
The package that provides the OpenGL implementation.
'';
};

package32 = mkOption {
opengl.package32 = mkOption {
type = types.package;
internal = true;
description = lib.mdDoc ''
Expand All @@ -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;
Expand All @@ -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}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The target used to be a relative path ("opengl-driver"), now it's absolute ("/run/opengl-driver"). Shouldn't matter

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;
};
Expand Down
12 changes: 6 additions & 6 deletions nixos/modules/hardware/video/nvidia.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
};
Expand Down Expand Up @@ -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
];
};
Expand Down
6 changes: 3 additions & 3 deletions nixos/modules/services/x11/xserver.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];

Expand Down Expand Up @@ -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 =
Expand Down