@@ -1,57 +1,93 @@
11{ stdenv, lib, fetchurl
22, SDL, dwarf-fortress-unfuck
3+
4+# Our own "unfuck" libs for macOS
5+, ncurses, fmodex, gcc
36}:
47
8+with lib;
9+
510let
611 baseVersion = "44";
7− patchVersion = "09";
12+ patchVersion = "10";
813 dfVersion = "0.${baseVersion}.${patchVersion}";
9− libpath = lib.makeLibraryPath [ stdenv.cc.cc stdenv.glibc dwarf-fortress-unfuck SDL ];
10− platform =
11− if stdenv.system == "x86_64-linux" then "linux"
12− else if stdenv.system == "i686-linux" then "linux32"
13− else throw "Unsupported platform";
14− sha256 =
15− if stdenv.system == "x86_64-linux" then "1haikynkg1pqyrzzqk1qxm19p36ww58qp8brh3fjxssp4x71rcdy"
16− else if stdenv.system == "i686-linux" then "0lmbrdf7wjdwj5yx0khnq871yxvhfwqxjjyfkqcdy5ik18lvlkj8"
17− else throw "Unsupported platform";
14+
15+ libpath = makeLibraryPath [ stdenv.cc.cc stdenv.cc.libc dwarf-fortress-unfuck SDL ];
16+
17+ homepage = http://www.bay12games.com/dwarves/;
18+
19+ # Other srcs are avilable like 32-bit mac & win, but I have only
20+ # included the ones most likely to be needed by Nixpkgs users.
21+ srcs = {
22+ "x86_64-linux" = fetchurl {
23+ url = "${homepage}df_${baseVersion}_${patchVersion}_linux.tar.bz2";
24+ sha256 = "1haikynkg1pqyrzzqk1qxm19p36ww58qp8brh3fjxssp4x71rcdy";
25+ };
26+ "i686-linux" = fetchurl {
27+ url = "${homepage}df_${baseVersion}_${patchVersion}_linux32.tar.bz2";
28+ sha256 = "0lmbrdf7wjdwj5yx0khnq871yxvhfwqxjjyfkqcdy5ik18lvlkj8";
29+ };
30+ "x86_64-darwin" = fetchurl {
31+ url = "${homepage}df_${baseVersion}_${patchVersion}_osx.tar.bz2";
32+ sha256 = "1wpa45d81q8f5mhqmaxvdkz93k6cm3pg7vpsqjjjsp5s961gd74g";
33+ };
34+ };
1835
1936in
2037
21−assert dwarf-fortress-unfuck.dfVersion == dfVersion;
38+assert dwarf-fortress-unfuck != null ->
39+ dwarf-fortress-unfuck.dfVersion == dfVersion;
2240
2341stdenv.mkDerivation {
2442 name = "dwarf-fortress-original-${dfVersion}";
2543
26− src = fetchurl {
27− url = "http://www.bay12games.com/dwarves/df_${baseVersion}_${patchVersion}_${platform}.tar.bz2";
28− inherit sha256;
29− };
44+ src = if builtins.hasAttr stdenv.system srcs
45+ then builtins.getAttr stdenv.system srcs
46+ else throw "Unsupported systems";
3047
3148 installPhase = ''
3249 mkdir -p $out
3350 cp -r * $out
3451 rm $out/libs/lib*
3552
36− # Store the original hash
37− md5sum $out/libs/Dwarf_Fortress | awk '{ print $1 }' > $out/hash.md5.orig
53+ exe=$out/${if stdenv.isLinux then "libs/Dwarf_Fortress"
54+ else "dwarfort.exe"}
3855
56+ # Store the original hash
57+ md5sum $exe | awk '{ print $1 }' > $out/hash.md5.orig
58+ '' + optionalString stdenv.isLinux ''
3959 patchelf \
4060 --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \
4161 --set-rpath "${libpath}" \
42− $out/libs/Dwarf_Fortress
62+ $exe
63+ '' + optionalString stdenv.isDarwin ''
64+ # My custom unfucked dwarfort.exe for macOS. Can't use
65+ # absolute paths because original doesn't have enough
66+ # header space. Someone plz break into Tarn's house & put
67+ # -headerpad_max_install_names into his LDFLAGS.
68+
69+ ln -s ${getLib ncurses}/lib/libncurses.dylib $out/libs
70+ ln -s ${getLib gcc.cc}/lib/libstdc++.6.dylib $out/libs
71+ ln -s ${getLib fmodex}/lib/libfmodex.dylib $out/libs
4372
73+ install_name_tool \
74+ -change /usr/lib/libncurses.5.4.dylib \
75+ @executable_path/libs/libncurses.dylib \
76+ -change /usr/local/lib/x86_64/libstdc++.6.dylib \
77+ @executable_path/libs/libstdc++.6.dylib \
78+ $exe
79+ '' + ''
4480 # Store the new hash
45− md5sum $out/libs/Dwarf_Fortress | awk '{ print $1 }' > $out/hash.md5
81+ md5sum $exe | awk '{ print $1 }' > $out/hash.md5
4682 '';
4783
4884 passthru = { inherit baseVersion patchVersion dfVersion; };
4985
50− meta = with stdenv.lib; {
86+ meta = {
5187 description = "A single-player fantasy game with a randomly generated adventure world";
52− homepage = http://www.bay12games.com/dwarves;
88+ inherit homepage;
5389 license = licenses.unfreeRedistributable;
54− platforms = platforms.linux;
90+ platforms = attrNames srcs;
5591 maintainers = with maintainers; [ a1russell robbinch roconnor the-kenny abbradar ];
5692 };
5793}