about summary refs log tree commit diff
path: root/pkgs/games/build-support
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2017-09-13 06:04:38 +0200
committeraszlig <aszlig@redmoonstudios.org>2017-09-13 15:26:33 +0200
commite273773c4e66c2e553e1cbf0c453fc225fe808e3 (patch)
tree80a9b690daab736d0b28677a1ce4ffe5bc993aca /pkgs/games/build-support
parentef6c66560175e4b5a798bd09caa31cd5ebad8127 (diff)
pkgs/build-game: Add runtimeDependencies attribute
This allows us to add libraries to the RPATH despite being required by
the respective game. By default there is only PulseAudio at the moment.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'pkgs/games/build-support')
-rw-r--r--pkgs/games/build-support/build-game.nix11
-rw-r--r--pkgs/games/build-support/default.nix6
-rw-r--r--pkgs/games/build-support/setup-hooks/auto-patchelf.sh17
3 files changed, 23 insertions, 11 deletions
diff --git a/pkgs/games/build-support/build-game.nix b/pkgs/games/build-support/build-game.nix
index 2ada5eb7..46ed83df 100644
--- a/pkgs/games/build-support/build-game.nix
+++ b/pkgs/games/build-support/build-game.nix
@@ -1,8 +1,11 @@
-{ stdenv, lib, file }:
+{ stdenv, lib, file, withPulseAudio ? true, libpulseaudio ? null }:
+
+assert withPulseAudio -> libpulseaudio != null;
 
 { buildInputs ? []
 , nativeBuildInputs ? []
 , installCheckPhase ? ""
+, runtimeDependencies ? []
 , ...
 }@attrs:
 
@@ -13,6 +16,10 @@ stdenv.mkDerivation ({
     file ./setup-hooks/auto-patchelf.sh
   ] ++ nativeBuildInputs;
 
+  runtimeDependencies = let
+    deps = lib.optional withPulseAudio libpulseaudio ++ runtimeDependencies;
+  in map (dep: dep.lib or dep) deps;
+
   doInstallCheck = true;
 
   installCheckPhase = ''
@@ -38,5 +45,5 @@ stdenv.mkDerivation ({
   dontStrip = true;
   dontPatchELF = true;
 } // removeAttrs attrs [
-  "buildInputs" "nativeBuildInputs" "installCheckPhase"
+  "buildInputs" "nativeBuildInputs" "installCheckPhase" "runtimeDependencies"
 ])
diff --git a/pkgs/games/build-support/default.nix b/pkgs/games/build-support/default.nix
index 23e03c3b..8e227afc 100644
--- a/pkgs/games/build-support/default.nix
+++ b/pkgs/games/build-support/default.nix
@@ -1,6 +1,8 @@
-{ callPackage, ... }:
+{ config, callPackage, ... }:
 
 {
-  buildGame = callPackage ./build-game.nix {};
+  buildGame = callPackage ./build-game.nix {
+    withPulseAudio = config.pulseaudio or true;
+  };
   buildUnity = callPackage ./build-unity.nix {};
 }
diff --git a/pkgs/games/build-support/setup-hooks/auto-patchelf.sh b/pkgs/games/build-support/setup-hooks/auto-patchelf.sh
index b0982a45..33408533 100644
--- a/pkgs/games/build-support/setup-hooks/auto-patchelf.sh
+++ b/pkgs/games/build-support/setup-hooks/auto-patchelf.sh
@@ -51,7 +51,6 @@ checkElfDep() {
 populateCacheWithRecursiveDeps() {
     local so found foundso
     for so in "${cachedDependencies[@]}"; do
-        local IFS=$'\n'
         for found in $(getDepsFromSo "$so"); do
             local libdir="${found%/*}"
             local base="${found##*/}"
@@ -91,21 +90,23 @@ findDependency() {
 }
 
 autoPatchelfFile() {
-    local toPatch="$1"
-    local dep
+    local dep rpath="" toPatch="$1"
 
     local interpreter="$(cat $NIX_CC/nix-support/dynamic-linker)"
     if isExecutable "$toPatch"; then
         patchelf --set-interpreter "$interpreter" "$toPatch"
+        if [ -n "$runtimeDependencies" ]; then
+            for dep in $runtimeDependencies; do
+                rpath="$rpath${rpath:+:}$dep/lib"
+            done
+        fi
     fi
 
     patchelf --remove-rpath "$toPatch"
 
-    local rpath=""
     local missing="$(
         ldd "$toPatch" | sed -n -e 's/^[\t ]*\([^ ]\+\) => not found.*/\1/p'
     )"
-    local IFS=$'\n'
     for dep in $missing; do
         echo -n "searching for dependency $dep..." >&2
         if findDependency "$dep"; then
@@ -125,11 +126,13 @@ autoPatchelfFile() {
 autoPatchelf() {
     echo "automatically fixing dependencies for ELF files" >&2
 
-    local i IFS=$'\n'
     cachedDependencies+=(
         $(find "$out" \! -type d \( -name '*.so' -o -name '*.so.*' \))
     )
-    for i in $(findElfs "$prefix"); do autoPatchelfFile "$i"; done
+    local elffile
+    findElfs "$prefix" | while read -r elffile; do
+        autoPatchelfFile "$elffile"
+    done
 }
 
 postInstallHooks+=(autoPatchelf)