From e273773c4e66c2e553e1cbf0c453fc225fe808e3 Mon Sep 17 00:00:00 2001 From: aszlig Date: Wed, 13 Sep 2017 06:04:38 +0200 Subject: 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 --- pkgs/games/build-support/build-game.nix | 11 +++++++++-- pkgs/games/build-support/default.nix | 6 ++++-- pkgs/games/build-support/setup-hooks/auto-patchelf.sh | 17 ++++++++++------- 3 files changed, 23 insertions(+), 11 deletions(-) (limited to 'pkgs/games/build-support') 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) -- cgit 1.4.1