aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/build-support/add-opengl-runpath
diff options
context:
space:
mode:
authorMx Kookie <kookie@spacekookie.de>2020-10-31 19:35:09 +0100
committerMx Kookie <kookie@spacekookie.de>2020-10-31 19:35:09 +0100
commitc4625b175f8200f643fd6e11010932ea44c78433 (patch)
treebce3f89888c8ac3991fa5569a878a9eab6801ccc /infra/libkookie/nixpkgs/pkgs/build-support/add-opengl-runpath
parent49f735974dd103039ddc4cb576bb76555164a9e7 (diff)
parentd661aa56a8843e991261510c1bb28fdc2f6975ae (diff)
Add 'infra/libkookie/' from commit 'd661aa56a8843e991261510c1bb28fdc2f6975ae'
git-subtree-dir: infra/libkookie git-subtree-mainline: 49f735974dd103039ddc4cb576bb76555164a9e7 git-subtree-split: d661aa56a8843e991261510c1bb28fdc2f6975ae
Diffstat (limited to 'infra/libkookie/nixpkgs/pkgs/build-support/add-opengl-runpath')
-rw-r--r--infra/libkookie/nixpkgs/pkgs/build-support/add-opengl-runpath/default.nix12
-rw-r--r--infra/libkookie/nixpkgs/pkgs/build-support/add-opengl-runpath/setup-hook.sh29
2 files changed, 41 insertions, 0 deletions
diff --git a/infra/libkookie/nixpkgs/pkgs/build-support/add-opengl-runpath/default.nix b/infra/libkookie/nixpkgs/pkgs/build-support/add-opengl-runpath/default.nix
new file mode 100644
index 000000000000..5cab0937e074
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/build-support/add-opengl-runpath/default.nix
@@ -0,0 +1,12 @@
+{ lib, stdenv }:
+
+stdenv.mkDerivation {
+ name = "add-opengl-runpath";
+
+ 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/infra/libkookie/nixpkgs/pkgs/build-support/add-opengl-runpath/setup-hook.sh b/infra/libkookie/nixpkgs/pkgs/build-support/add-opengl-runpath/setup-hook.sh
new file mode 100644
index 000000000000..e556e7ead2a7
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/build-support/add-opengl-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.
+addOpenGLRunpath() {
+ local forceRpath=
+
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ --) shift; break;;
+ --force-rpath) shift; forceRpath=1;;
+ --*)
+ echo "addOpenGLRunpath: 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
+}
+