pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / build-support / add-driver-runpath / setup-hook.sh
blob86a41a7e251922de496b1b2682fd3edb959a6048
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.
8 addDriverRunpath() {
9 local forceRpath=
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
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