diff options
author | Jonathan Ringer <jonringer117@gmail.com> | 2023-11-23 10:15:38 -0800 |
---|---|---|
committer | Jonathan Ringer <jonringer117@gmail.com> | 2023-12-03 07:22:51 -0800 |
commit | c7c1388e82b88378b46a9d37e7ad2e1adf23961b (patch) | |
tree | b411624020f0fabdd63b61f23945a5f908005b6a /pkgs/build-support/add-driver-runpath | |
parent | 4b9cbf75912987a429fb8688e8c87c617c3d73de (diff) |
addDriverRunpath: init
Diffstat (limited to 'pkgs/build-support/add-driver-runpath')
-rw-r--r-- | pkgs/build-support/add-driver-runpath/default.nix | 14 | ||||
-rw-r--r-- | pkgs/build-support/add-driver-runpath/setup-hook.sh | 29 |
2 files changed, 43 insertions, 0 deletions
diff --git a/pkgs/build-support/add-driver-runpath/default.nix b/pkgs/build-support/add-driver-runpath/default.nix new file mode 100644 index 0000000000000..08547a4453c5f --- /dev/null +++ b/pkgs/build-support/add-driver-runpath/default.nix @@ -0,0 +1,14 @@ +{ lib, stdenv }: + +stdenv.mkDerivation { + name = "add-driver-runpath"; + + # Named "opengl-driver" for legacy reasons, but it is the path to + # hardware drivers installed by NixOS + driverLink = "/run/opengl-driver" + lib.optionalString stdenv.isi686 "-32"; + + buildCommand = '' + mkdir -p $out/nix-support + substituteAll ${./setup-hook.sh} $out/nix-support/setup-hook + ''; +} diff --git a/pkgs/build-support/add-driver-runpath/setup-hook.sh b/pkgs/build-support/add-driver-runpath/setup-hook.sh new file mode 100644 index 0000000000000..86a41a7e25192 --- /dev/null +++ b/pkgs/build-support/add-driver-runpath/setup-hook.sh @@ -0,0 +1,29 @@ +# Set RUNPATH so that driver libraries in /run/opengl-driver(-32)/lib can be found. +# This is needed to not rely on LD_LIBRARY_PATH which does not work with setuid +# executables. Fixes https://github.com/NixOS/nixpkgs/issues/22760. It must be run +# in postFixup because RUNPATH stripping in fixup would undo it. Note that patchelf +# actually sets RUNPATH not RPATH, which applies only to dependencies of the binary +# it set on (including for dlopen), so the RUNPATH must indeed be set on these +# libraries and would not work if set only on executables. +addDriverRunpath() { + local forceRpath= + + while [ $# -gt 0 ]; do + case "$1" in + --) shift; break;; + --force-rpath) shift; forceRpath=1;; + --*) + echo "addDriverRunpath: ERROR: Invalid command line" \ + "argument: $1" >&2 + return 1;; + *) break;; + esac + done + + for file in "$@"; do + if ! isELF "$file"; then continue; fi + local origRpath="$(patchelf --print-rpath "$file")" + patchelf --set-rpath "@driverLink@/lib:$origRpath" ${forceRpath:+--force-rpath} "$file" + done +} + |