diff --git a/pkgs/applications/audio/bitwig-studio/bitwig-studio1.nix b/pkgs/applications/audio/bitwig-studio/bitwig-studio1.nix index 31716fce1c211..b637435cf90d1 100644 --- a/pkgs/applications/audio/bitwig-studio/bitwig-studio1.nix +++ b/pkgs/applications/audio/bitwig-studio/bitwig-studio1.nix @@ -55,6 +55,10 @@ stdenv.mkDerivation rec { substitute usr/share/applications/bitwig-studio.desktop \ $out/share/applications/bitwig-studio.desktop \ --replace /usr/bin/bitwig-studio $out/bin/bitwig-studio + + # We only support x86_64-linux anyway, + # and these files cannot be correctly autoPatchelfHooked + rm -r $out/libexec/bin32 ''; postFixup = '' diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.sh b/pkgs/build-support/setup-hooks/auto-patchelf.sh index 6af8eb1aed994..e7e79f46e8b42 100644 --- a/pkgs/build-support/setup-hooks/auto-patchelf.sh +++ b/pkgs/build-support/setup-hooks/auto-patchelf.sh @@ -1,7 +1,14 @@ declare -a autoPatchelfLibs +declare -a autoPatchelfLinkers gatherLibraries() { autoPatchelfLibs+=("$1/lib") + if [ -f "$1/nix-support/dynamic-linker" ]; then + autoPatchelfLinkers+=("$1/nix-support/dynamic-linker") + fi + if [ -f "$1/nix-support/dynamic-linker-m32" ]; then + autoPatchelfLinkers+=("$1/nix-support/dynamic-linker-m32") + fi } addEnvHooks "$targetOffset" gatherLibraries @@ -98,12 +105,38 @@ findDependency() { return 1 } +patchElfInterpreter() { + local toPatch=$1 + local linkers=( \ + "$NIX_CC/nix-support/dynamic-linker" \ + "$NIX_CC/nix-support/dynamic-linker-m32" \ + "${autoPatchelfLinkers[@]}" \ + ) + + echo "searching an '$(getSoArch "$toPatch")' interpreter for $toPatch" >&2 + for f in "${linkers[@]}"; do + [ -f "$f" -a -r "$f" ] || continue + local interpreter=$(< "$f") + + [ -n "$interpreter" -a -f "$interpreter" ] || continue + [ "$(getSoArch "$toPatch")" = $(getSoArch "$interpreter") ] || continue + + echo "found an '$(getSoArch "$toPatch")' interpreter at '$interpreter'" >&2 + patchelf --set-interpreter "$interpreter" "$toPatch" + return + done + + echo "error: no '$(getSoArch "$toPatch")' interpreter found but one is required for '$toPatch'" >&2 + false +} + autoPatchelfFile() { local dep rpath="" toPatch="$1" - local interpreter="$(< "$NIX_CC/nix-support/dynamic-linker")" if isExecutable "$toPatch"; then - patchelf --set-interpreter "$interpreter" "$toPatch" + # Find a suitable interpreter + patchElfInterpreter "$toPatch" + if [ -n "$runtimeDependencies" ]; then for dep in $runtimeDependencies; do rpath="$rpath${rpath:+:}$dep/lib" diff --git a/pkgs/development/mobile/androidenv/build-tools.nix b/pkgs/development/mobile/androidenv/build-tools.nix index 976ef14162757..1d64fbd1f83b1 100644 --- a/pkgs/development/mobile/androidenv/build-tools.nix +++ b/pkgs/development/mobile/androidenv/build-tools.nix @@ -6,6 +6,8 @@ deployAndroidPackage { lib.optional (os == "linux") [ pkgs.glibc pkgs.zlib pkgs.ncurses5 pkgs_i686.glibc pkgs_i686.zlib pkgs_i686.ncurses5 ]; patchInstructions = '' ${lib.optionalString (os == "linux") '' + rm -r $packageBaseDir/{i686,aarch64,mipsel,arm}-linux* + addAutoPatchelfSearchPath $packageBaseDir/lib addAutoPatchelfSearchPath $packageBaseDir/lib64 autoPatchelf --no-recurse $packageBaseDir/lib64