2021-06-29 02:42:37 +00:00
|
|
|
{ stdenv
|
|
|
|
, lib
|
|
|
|
, fetchurl
|
|
|
|
, SDL
|
2024-03-31 03:36:51 +00:00
|
|
|
, SDL2
|
|
|
|
, SDL2_image
|
|
|
|
, SDL2_mixer
|
|
|
|
, fmodex
|
2021-06-29 02:42:37 +00:00
|
|
|
, dwarf-fortress-unfuck
|
2024-03-31 03:36:51 +00:00
|
|
|
, autoPatchelfHook
|
2018-05-11 04:55:06 +00:00
|
|
|
|
2021-06-29 02:42:37 +00:00
|
|
|
# Our own "unfuck" libs for macOS
|
|
|
|
, ncurses
|
|
|
|
, gcc
|
2018-07-05 21:21:24 +00:00
|
|
|
|
2021-06-29 02:42:37 +00:00
|
|
|
, dfVersion
|
|
|
|
, df-hashes
|
2016-01-12 17:56:59 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2024-03-14 18:35:25 +00:00
|
|
|
inherit (lib)
|
|
|
|
attrNames
|
|
|
|
elemAt
|
|
|
|
getAttr
|
|
|
|
getLib
|
|
|
|
hasAttr
|
|
|
|
licenses
|
|
|
|
maintainers
|
|
|
|
makeLibraryPath
|
2024-03-31 03:36:51 +00:00
|
|
|
optional
|
|
|
|
optionals
|
2024-03-14 18:35:25 +00:00
|
|
|
optionalString
|
|
|
|
splitVersion
|
2024-03-31 03:36:51 +00:00
|
|
|
toInt
|
2024-03-14 18:35:25 +00:00
|
|
|
;
|
|
|
|
|
2018-07-05 21:21:24 +00:00
|
|
|
# Map Dwarf Fortress platform names to Nixpkgs platform names.
|
2018-05-11 04:55:06 +00:00
|
|
|
# Other srcs are avilable like 32-bit mac & win, but I have only
|
|
|
|
# included the ones most likely to be needed by Nixpkgs users.
|
2018-07-05 21:21:24 +00:00
|
|
|
platforms = {
|
2019-08-13 21:52:01 +00:00
|
|
|
x86_64-linux = "linux";
|
|
|
|
i686-linux = "linux32";
|
|
|
|
x86_64-darwin = "osx";
|
|
|
|
i686-darwin = "osx32";
|
|
|
|
x86_64-cygwin = "win";
|
|
|
|
i686-cygwin = "win32";
|
2018-05-11 04:55:06 +00:00
|
|
|
};
|
2016-01-12 17:56:59 +00:00
|
|
|
|
2024-03-31 03:36:51 +00:00
|
|
|
dfVersionTuple = splitVersion dfVersion;
|
|
|
|
dfVersionBaseIndex = let
|
|
|
|
x = (builtins.length dfVersionTuple) - 2;
|
|
|
|
in if x >= 0 then x else 0;
|
|
|
|
baseVersion = toInt (elemAt dfVersionTuple dfVersionBaseIndex);
|
|
|
|
patchVersion = elemAt dfVersionTuple (dfVersionBaseIndex + 1);
|
|
|
|
|
|
|
|
isV50 = baseVersion >= 50;
|
|
|
|
enableUnfuck = !isV50 && dwarf-fortress-unfuck != null;
|
|
|
|
|
|
|
|
libpath = makeLibraryPath (
|
|
|
|
[ stdenv.cc.cc stdenv.cc.libc ]
|
|
|
|
++ optional (!isV50) SDL
|
|
|
|
++ optional enableUnfuck dwarf-fortress-unfuck
|
|
|
|
);
|
2018-07-05 21:21:24 +00:00
|
|
|
|
2021-06-29 02:42:37 +00:00
|
|
|
game =
|
|
|
|
if hasAttr dfVersion df-hashes
|
|
|
|
then getAttr dfVersion df-hashes
|
|
|
|
else throw "Unknown Dwarf Fortress version: ${dfVersion}";
|
|
|
|
dfPlatform =
|
|
|
|
if hasAttr stdenv.hostPlatform.system platforms
|
|
|
|
then getAttr stdenv.hostPlatform.system platforms
|
|
|
|
else throw "Unsupported system: ${stdenv.hostPlatform.system}";
|
|
|
|
sha256 =
|
|
|
|
if hasAttr dfPlatform game
|
|
|
|
then getAttr dfPlatform game
|
|
|
|
else throw "Unsupported dfPlatform: ${dfPlatform}";
|
2024-03-31 03:36:51 +00:00
|
|
|
exe = if stdenv.isLinux then
|
|
|
|
if baseVersion >= 50 then "dwarfort" else "libs/Dwarf_Fortress"
|
|
|
|
else
|
|
|
|
"dwarfort.exe";
|
2016-01-12 17:56:59 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
2021-02-28 22:36:24 +00:00
|
|
|
pname = "dwarf-fortress";
|
|
|
|
version = dfVersion;
|
2016-01-12 17:56:59 +00:00
|
|
|
|
2018-07-05 21:21:24 +00:00
|
|
|
src = fetchurl {
|
2024-03-31 03:36:51 +00:00
|
|
|
url = "https://www.bay12games.com/dwarves/df_${toString baseVersion}_${toString patchVersion}_${dfPlatform}.tar.bz2";
|
2018-07-05 21:21:24 +00:00
|
|
|
inherit sha256;
|
|
|
|
};
|
2016-01-12 17:56:59 +00:00
|
|
|
|
2024-03-31 03:36:51 +00:00
|
|
|
sourceRoot = ".";
|
|
|
|
|
|
|
|
postUnpack = optionalString stdenv.isLinux ''
|
|
|
|
if [ -d df_linux ]; then
|
|
|
|
mv df_linux/* .
|
|
|
|
fi
|
|
|
|
'' + optionalString stdenv.isDarwin ''
|
|
|
|
if [ -d df_osx ]; then
|
|
|
|
mv df_osx/* .
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
nativeBuildInputs = optional isV50 autoPatchelfHook;
|
|
|
|
buildInputs = optionals isV50 [ SDL2 SDL2_image SDL2_mixer stdenv.cc.cc.lib ];
|
|
|
|
|
2016-01-12 17:56:59 +00:00
|
|
|
installPhase = ''
|
2024-03-31 03:36:51 +00:00
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
exe=$out/${exe}
|
2016-01-12 17:56:59 +00:00
|
|
|
mkdir -p $out
|
|
|
|
cp -r * $out
|
|
|
|
|
2024-03-31 03:36:51 +00:00
|
|
|
# Lots of files are +x in the newer releases...
|
|
|
|
find $out -type d -exec chmod 0755 {} \;
|
|
|
|
find $out -type f -exec chmod 0644 {} \;
|
|
|
|
chmod +x $exe
|
|
|
|
[ -f $out/df ] && chmod +x $out/df
|
|
|
|
[ -f $out/run_df ] && chmod +x $out/run_df
|
2016-01-12 17:56:59 +00:00
|
|
|
|
2018-05-11 04:55:06 +00:00
|
|
|
# Store the original hash
|
|
|
|
md5sum $exe | awk '{ print $1 }' > $out/hash.md5.orig
|
2024-03-31 03:36:51 +00:00
|
|
|
echo "Original MD5: $(<$out/hash.md5.orig)" >&2
|
|
|
|
'' + optionalString (!isV50 && stdenv.isLinux) ''
|
|
|
|
rm -f $out/libs/*.so
|
2016-01-12 17:56:59 +00:00
|
|
|
patchelf \
|
|
|
|
--set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \
|
|
|
|
--set-rpath "${libpath}" \
|
2018-05-11 04:55:06 +00:00
|
|
|
$exe
|
|
|
|
'' + optionalString stdenv.isDarwin ''
|
|
|
|
# My custom unfucked dwarfort.exe for macOS. Can't use
|
|
|
|
# absolute paths because original doesn't have enough
|
|
|
|
# header space. Someone plz break into Tarn's house & put
|
|
|
|
# -headerpad_max_install_names into his LDFLAGS.
|
|
|
|
|
|
|
|
ln -s ${getLib ncurses}/lib/libncurses.dylib $out/libs
|
|
|
|
ln -s ${getLib gcc.cc}/lib/libstdc++.6.dylib $out/libs
|
|
|
|
ln -s ${getLib fmodex}/lib/libfmodex.dylib $out/libs
|
2016-01-12 17:56:59 +00:00
|
|
|
|
2018-05-11 04:55:06 +00:00
|
|
|
install_name_tool \
|
|
|
|
-change /usr/lib/libncurses.5.4.dylib \
|
|
|
|
@executable_path/libs/libncurses.dylib \
|
|
|
|
-change /usr/local/lib/x86_64/libstdc++.6.dylib \
|
|
|
|
@executable_path/libs/libstdc++.6.dylib \
|
|
|
|
$exe
|
|
|
|
'' + ''
|
2024-03-31 03:36:51 +00:00
|
|
|
ls -al $out
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
fixupPhase = ''
|
|
|
|
runHook preFixup
|
|
|
|
runHook postFixup
|
|
|
|
|
|
|
|
# Store the new hash as the very last step.
|
|
|
|
exe=$out/${exe}
|
2018-05-11 04:55:06 +00:00
|
|
|
md5sum $exe | awk '{ print $1 }' > $out/hash.md5
|
2024-03-31 03:36:51 +00:00
|
|
|
echo "Patched MD5: $(<$out/hash.md5)" >&2
|
2016-01-12 17:56:59 +00:00
|
|
|
'';
|
|
|
|
|
2018-07-05 21:21:24 +00:00
|
|
|
passthru = {
|
2024-03-31 03:36:51 +00:00
|
|
|
inherit baseVersion patchVersion dfVersion exe;
|
2018-07-05 21:21:24 +00:00
|
|
|
updateScript = ./update.sh;
|
|
|
|
};
|
2016-01-12 17:56:59 +00:00
|
|
|
|
2018-05-11 04:55:06 +00:00
|
|
|
meta = {
|
2016-01-12 17:56:59 +00:00
|
|
|
description = "A single-player fantasy game with a randomly generated adventure world";
|
2022-10-27 16:55:36 +00:00
|
|
|
homepage = "https://www.bay12games.com/dwarves/";
|
2016-08-13 00:10:46 +00:00
|
|
|
license = licenses.unfreeRedistributable;
|
2018-07-05 21:21:24 +00:00
|
|
|
platforms = attrNames platforms;
|
2022-11-16 22:58:36 +00:00
|
|
|
maintainers = with maintainers; [ a1russell robbinch roconnor abbradar numinit shazow ncfavier ];
|
2016-01-12 17:56:59 +00:00
|
|
|
};
|
|
|
|
}
|