Skip to content

Commit

Permalink
nixos: Don't set LD_LIBRARY_PATH for graphics drivers that don't need…
Browse files Browse the repository at this point in the history
… it.

A new internal option `hardware.opengl.setLdLibraryPath` is added which controls if `LD_LIBRARY_PATH` should be set to `/run/opengl-driver(-32)/lib`. It is false by default and is meant to be set to true by any driver which requires it. If this option is false, then `opengl.nix` and `xserver.nix` will not set `LD_LIBRARY_PATH`.

Currently Mesa and NVidia drivers don't set `setLdLibraryPath` because they work with libglvnd and do not override libraries, while `amdgpu-pro`, `ati` and `parallels-guest` set it to true (the former two really need it, the last one doesn't build so is presumed to).

Additionally, the `libPath` attribute within entries of `services.xserver.drivers` is removed. This made `xserver.nix` add the driver path directly to the `LD_LIBRARY_PATH` for the display manager (including X server). Not only is it redundant when the driver is added to `hardware.opengl.package` (assuming that `hardware.opengl.enable` is true), in fact all current drivers except `ati` set it incorrectly to the package path instead of package/lib.

This removal of `LD_LIBRARY_PATH` could break certain packages using CUDA, but only those that themselves load `libcuda` or other NVidia driver libraries using `dlopen` (not if they just use `cudatoolkit`). A few have already been fixed but it is practically impossible to test all because most packages using CUDA are libraries/frameworks without a simple way to test.

Fixes #11434 if only Mesa or NVidia graphics drivers are used.
  • Loading branch information
ambrop72 committed May 26, 2019
1 parent 2143f59 commit 370d3af
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
17 changes: 15 additions & 2 deletions nixos/modules/hardware/opengl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ in
set. This can be used to add OpenCL drivers, VA-API/VDPAU drivers etc.
'';
};

setLdLibraryPath = mkOption {
type = types.bool;
internal = true;
default = false;
description = ''
Whether the <literal>LD_LIBRARY_PATH</literal> environment variable
should be set to the locations of driver libraries. Drivers which
rely on overriding libraries should set this to true. Drivers which
support <literal>libglvnd</literal> and other dispatch libraries
instead of overriding libraries should not set this.
'';
};
};

};
Expand Down Expand Up @@ -145,8 +158,8 @@ in
)
];

environment.sessionVariables.LD_LIBRARY_PATH =
[ "/run/opengl-driver/lib" ] ++ optional cfg.driSupport32Bit "/run/opengl-driver-32/lib";
environment.sessionVariables.LD_LIBRARY_PATH = mkIf cfg.setLdLibraryPath
([ "/run/opengl-driver/lib" ] ++ optional cfg.driSupport32Bit "/run/opengl-driver-32/lib");

environment.variables.XDG_DATA_DIRS =
[ "/run/opengl-driver/share" ] ++ optional cfg.driSupport32Bit "/run/opengl-driver-32/share";
Expand Down
3 changes: 2 additions & 1 deletion nixos/modules/hardware/video/amdgpu-pro.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ in
nixpkgs.config.xorg.abiCompat = "1.19";

services.xserver.drivers = singleton
{ name = "amdgpu"; modules = [ package ]; libPath = [ package ]; };
{ name = "amdgpu"; modules = [ package ]; };

hardware.opengl.package = package;
hardware.opengl.package32 = package32;
hardware.opengl.setLdLibraryPath = true;

boot.extraModulePackages = [ package ];

Expand Down
3 changes: 2 additions & 1 deletion nixos/modules/hardware/video/ati.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ in
nixpkgs.config.xorg.abiCompat = "1.17";

services.xserver.drivers = singleton
{ name = "fglrx"; modules = [ ati_x11 ]; libPath = [ "${ati_x11}/lib" ]; };
{ name = "fglrx"; modules = [ ati_x11 ]; };

hardware.opengl.package = ati_x11;
hardware.opengl.package32 = pkgs.pkgsi686Linux.linuxPackages.ati_drivers_x11.override { libsOnly = true; kernel = null; };
hardware.opengl.setLdLibraryPath = true;

environment.systemPackages = [ ati_x11 ];

Expand Down
1 change: 0 additions & 1 deletion nixos/modules/hardware/video/nvidia.nix
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ in
services.xserver.drivers = singleton {
name = "nvidia";
modules = [ nvidia_x11.bin ];
libPath = [ nvidia_x11 ];
deviceSection = optionalString optimusCfg.enable
''
BusID "${optimusCfg.nvidiaBusId}"
Expand Down
7 changes: 3 additions & 4 deletions nixos/modules/services/x11/xserver.nix
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,9 @@ in
restartIfChanged = false;

environment =
{
LD_LIBRARY_PATH = concatStringsSep ":" ([ "/run/opengl-driver/lib" ]
++ concatLists (catAttrs "libPath" cfg.drivers));
} // cfg.displayManager.job.environment;
optionalAttrs config.hardware.opengl.setLdLibraryPath
{ LD_LIBRARY_PATH = pkgs.addOpenGLRunpath.driverLink; }
// cfg.displayManager.job.environment;

preStart =
''
Expand Down
3 changes: 2 additions & 1 deletion nixos/modules/virtualisation/parallels-guest.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ in
config = mkIf config.hardware.parallels.enable {
services.xserver = {
drivers = singleton
{ name = "prlvideo"; modules = [ prl-tools ]; libPath = [ prl-tools ]; };
{ name = "prlvideo"; modules = [ prl-tools ]; };

screenSection = ''
Option "NoMTRR"
Expand All @@ -65,6 +65,7 @@ in

hardware.opengl.package = prl-tools;
hardware.opengl.package32 = pkgs.pkgsi686Linux.linuxPackages.prl-tools.override { libsOnly = true; kernel = null; };
hardware.opengl.setLdLibraryPath = true;

services.udev.packages = [ prl-tools ];

Expand Down

0 comments on commit 370d3af

Please sign in to comment.