1# Set RUNPATH so that driver libraries in /run/opengl-driver(-32)/lib can be found.
2# This is needed to not rely on LD_LIBRARY_PATH which does not work with setuid
3# executables. Fixes https://github.com/NixOS/nixpkgs/issues/22760. It must be run
4# in postFixup because RUNPATH stripping in fixup would undo it. Note that patchelf
5# actually sets RUNPATH not RPATH, which applies only to dependencies of the binary
6# it set on (including for dlopen), so the RUNPATH must indeed be set on these
7# libraries and would not work if set only on executables.
8addDriverRunpath() {
9 local forceRpath=
10
11 while [ $# -gt 0 ]; do
12 case "$1" in
13 --) shift; break;;
14 --force-rpath) shift; forceRpath=1;;
15 --*)
16 echo "addDriverRunpath: ERROR: Invalid command line" \
17 "argument: $1" >&2
18 return 1;;
19 *) break;;
20 esac
21 done
22
23 for file in "$@"; do
24 if ! isELF "$file"; then continue; fi
25 local origRpath="$(patchelf --print-rpath "$file")"
26 patchelf --set-rpath "@driverLink@/lib:$origRpath" ${forceRpath:+--force-rpath} "$file"
27 done
28}
29