From 2a395d5dd51674f0af5f8bde487a8d73d789fa07 Mon Sep 17 00:00:00 2001 From: Morgan Jones Date: Sat, 19 Apr 2025 22:13:48 -0700 Subject: [PATCH] dwarf-fortress: fix audio on v50 --- pkgs/games/dwarf-fortress/wrapper/default.nix | 4 +- .../wrapper/dwarf-fortress-init.in | 40 +++++++++++++------ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/pkgs/games/dwarf-fortress/wrapper/default.nix b/pkgs/games/dwarf-fortress/wrapper/default.nix index 372467475321..4c7b1c286800 100644 --- a/pkgs/games/dwarf-fortress/wrapper/default.nix +++ b/pkgs/games/dwarf-fortress/wrapper/default.nix @@ -9,6 +9,7 @@ gawk, dwarf-fortress, dwarf-therapist, + SDL2_mixer, enableDFHack ? false, dfhack, enableSoundSense ? false, @@ -181,7 +182,7 @@ lib.throwIf (enableTWBT' && !enableDFHack) "dwarf-fortress: TWBT requires DFHack "dwarf-fortress: text mode and TWBT are mutually exclusive" stdenv.mkDerivation - rec { + { pname = "dwarf-fortress"; version = dwarf-fortress.dfVersion; @@ -195,6 +196,7 @@ lib.throwIf (enableTWBT' && !enableDFHack) "dwarf-fortress: TWBT requires DFHack mkdir = "${coreutils}/bin/mkdir"; printf = "${coreutils}/bin/printf"; uname = "${coreutils}/bin/uname"; + SDL2_mixer = "${SDL2_mixer}/lib/libSDL2_mixer.so"; }; runDF = ./dwarf-fortress.in; diff --git a/pkgs/games/dwarf-fortress/wrapper/dwarf-fortress-init.in b/pkgs/games/dwarf-fortress/wrapper/dwarf-fortress-init.in index 363585fac293..4aaa0dc684a4 100644 --- a/pkgs/games/dwarf-fortress/wrapper/dwarf-fortress-init.in +++ b/pkgs/games/dwarf-fortress/wrapper/dwarf-fortress-init.in @@ -112,6 +112,27 @@ go() { cd "$NIXPKGS_DF_HOME" debug "Executing: $NIXPKGS_DF_HOME/$NIXPKGS_DF_EXE" + # Handle library paths on Darwin. + if [ "$os_name" == Darwin ]; then + if [ "${os_rev%%.*}" -ge 11 ]; then + export DYLD_LIBRARY_PATH="$NIXPKGS_DF_ENV/libs" + export DYLD_FRAMEWORK_PATH="$NIXPKGS_DF_ENV/libs" + else + export DYLD_FALLBACK_LIBRARY_PATH="$NIXPKGS_DF_ENV/libs" + export DYLD_FALLBACK_FRAMEWORK_PATH="$NIXPKGS_DF_ENV/libs" + fi + fi + + if [ "$os_name" == Linux ]; then + # We have to preload the audio plugin for audio to work. See Nix Pill #12 for this pattern: + # https://nixos.org/guides/nix-pills/12-inputs-design-pattern.html + if [ "${_NIXPKGS_DF_OPTS[fmod]}" -eq 0 ] && [ -f "$NIXPKGS_DF_HOME/libfmod.so.13" ]; then + export LD_PRELOAD="$NIXPKGS_DF_HOME/libfmod.so.13${LD_PRELOAD:+:}${LD_PRELOAD:-}" + else + export LD_PRELOAD="@SDL2_mixer@${LD_PRELOAD:+:}${LD_PRELOAD:-}" + fi + fi + # If we make it past here, we want to log. # shellcheck disable=SC2093 exec -a "$NIXPKGS_DF_EXE" "$NIXPKGS_DF_HOME/$NIXPKGS_DF_EXE" "$@" @@ -168,9 +189,13 @@ EOF cd "$NIXPKGS_DF_ENV" # All potential important files in DF 50 and below. -for path in dwarfort dwarfort.exe df *.so libs raw data/init/* data/!(init|index|announcement); do +for path in dwarfort dwarfort.exe df *.so* libs raw data/init/* data/!(init|index|announcement); do force_delete=0 - if [[ "$path" == libfmod*.so* ]] && [ "${_NIXPKGS_DF_OPTS[fmod]}" -eq 0 ]; then + if [[ "$path" == *fmod*.so* ]] && [ "${_NIXPKGS_DF_OPTS[fmod]}" -eq 0 ]; then + # Delete fmod plugins if we're using SDL_mixer. + force_delete=1 + elif [[ "$path" == *mixer*.so* ]] && [ "${_NIXPKGS_DF_OPTS[fmod]}" -ne 0 ]; then + # Delete SDL_mixer plugins if we're using fmod. force_delete=1 fi @@ -185,14 +210,3 @@ done for path in index announcement help dipscript; do forcecopy_path "data/$path" done - -# Handle library paths on Darwin. -if [ "$os_name" == Darwin ]; then - if [ "${os_rev%%.*}" -ge 11 ]; then - export DYLD_LIBRARY_PATH="$NIXPKGS_DF_ENV/libs" - export DYLD_FRAMEWORK_PATH="$NIXPKGS_DF_ENV/libs" - else - export DYLD_FALLBACK_LIBRARY_PATH="$NIXPKGS_DF_ENV/libs" - export DYLD_FALLBACK_FRAMEWORK_PATH="$NIXPKGS_DF_ENV/libs" - fi -fi