13 , enableStoneSense ? false
26 dfHackRelease = "0.44.10-r2";
27 sha256 = "19bxsghxzw3bilhr8sm4axz7p7z8lrvbdsd1vdjf5zbg04rs866i";
28 xmlRev = "321bd48b10c4c3f694cc801a7dee6be392c09b7b";
32 dfHackRelease = "0.44.11-beta2.1";
33 sha256 = "1jgwcqg9m1ybv3szgnklp6zfpiw5mswla464dlj2gfi5v82zqbv2";
34 xmlRev = "f27ebae6aa8fb12c46217adec5a812cd49a905c8";
38 dfHackRelease = "0.44.12-r1";
39 sha256 = "0j03lq6j6w378z6cvm7jspxc7hhrqm8jaszlq0mzfvap0k13fgyy";
40 xmlRev = "23500e4e9bd1885365d0a2ef1746c321c1dd5094";
44 dfHackRelease = "0.47.02-alpha0";
45 sha256 = "19lgykgqm0si9vd9hx4zw8b5m9188gg8r1a6h25np2m2ziqwbjj9";
46 xmlRev = "23500e4e9bd1885365d0a2ef1746c321c1dd509a";
50 dfHackRelease = "0.47.04-r5";
51 sha256 = "sha256-0s+/LKbqsS/mrxKPDeniqykE5+Gy3ZzCa8yEDzMyssY=";
52 xmlRev = "be0444cc165a1abff053d5893dc1f780f06526b7";
56 dfHackRelease = "0.47.05-r7";
57 sha256 = "sha256-vBKUTSjfCnalkBzfjaIKcxUuqsGGOTtoJC1RHJIDlNc=";
58 xmlRev = "f5019a5c6f19ef05a28bd974c3e8668b78e6e2a4";
65 if lib.isAttrs dfVersion
67 else if hasAttr dfVersion dfhack-releases
68 then getAttr dfVersion dfhack-releases
69 else throw "[DFHack] Unsupported Dwarf Fortress version: ${dfVersion}";
71 version = release.dfHackRelease;
73 # revision of library/xml submodule
74 xmlRev = release.xmlRev;
77 if stdenv.hostPlatform.system == "x86_64-linux" then "64"
78 else if stdenv.hostPlatform.system == "i686-linux" then "32"
79 else throw "Unsupported architecture";
81 fakegit = writeScriptBin "git" ''
83 if [ "$*" = "describe --tags --long" ]; then
84 echo "${version}-unknown"
85 elif [ "$*" = "describe --tags --abbrev=8 --long" ]; then
86 echo "${version}-unknown"
87 elif [ "$*" = "describe --tags --abbrev=8 --exact-match" ]; then
89 elif [ "$*" = "rev-parse HEAD" ]; then
90 if [ "$(dirname "$(pwd)")" = "xml" ]; then
93 echo "refs/tags/${version}"
95 elif [ "$*" = "rev-parse HEAD:library/xml" ]; then
102 stdenv.mkDerivation {
106 # Beware of submodules
107 src = fetchFromGitHub {
110 rev = release.dfHackRelease;
111 sha256 = release.sha256;
112 fetchSubmodules = true;
115 patches = lib.optional (lib.versionOlder version "0.44.12-r3") (fetchpatch {
116 name = "fix-stonesense.patch";
117 url = "https://github.com/DFHack/stonesense/commit/f5be6fe5fb192f01ae4551ed9217e97fd7f6a0ae.patch";
118 extraPrefix = "plugins/stonesense/";
120 hash = "sha256-wje6Mkct29eyMOcJnbdefwBOLJko/s4JcJe52ojuW+8=";
121 }) ++ lib.optional (lib.versionOlder version "0.47.04-r1") (fetchpatch {
122 name = "fix-protobuf.patch";
123 url = "https://github.com/DFHack/dfhack/commit/7bdf958518d2892ee89a7173224a069c4a2190d8.patch";
124 hash = "sha256-p+mKhmYbnhWKNiGPMjbYO505Gcg634n0nudqH0NX3KY=";
128 CXXFLAGS = lib.optionalString (lib.versionOlder version "0.47.05-r3") "-fpermissive";
131 # https://github.com/DFHack/dfhack/commit/56e43a0dde023c5a4595a22b29d800153b31e3c4,
132 # dfhack gets its goodies from the directory above the Dwarf_Fortress
133 # executable, which leads to stock Dwarf Fortress and not the built
134 # environment where all the dfhack resources are symlinked to (typically
135 # ~/.local/share/df_linux). This causes errors like `tweak is not a
136 # recognized command` to be reported and dfhack to lose some of its
139 sed -i 's@cached_path = path_string.*@cached_path = getenv("DF_DIR");@' library/Process-linux.cpp
142 nativeBuildInputs = [ cmake perl XMLLibXML XMLLibXSLT fakegit ];
143 # We don't use system libraries because dfhack needs old C++ ABI.
144 buildInputs = [ zlib SDL ]
145 ++ lib.optionals enableStoneSense [ allegro5 libGLU libGL ];
148 # Trick build system into believing we have .git
149 mkdir -p .git/modules/library/xml
150 touch .git/index .git/modules/library/xml/index
153 cmakeFlags = [ "-DDFHACK_BUILD_ARCH=${arch}" "-DDOWNLOAD_RUBY=OFF" ]
154 ++ lib.optionals enableStoneSense [ "-DBUILD_STONESENSE=ON" "-DSTONESENSE_INTERNAL_SO=OFF" ];
156 # dfhack expects an unversioned libruby.so to be present in the hack
157 # subdirectory for ruby plugins to function.
159 ln -s ${ruby}/lib/libruby-*.so $out/hack/libruby.so
162 passthru = { inherit dfVersion; };
165 description = "Memory hacking library for Dwarf Fortress and a set of tools that use it";
166 homepage = "https://github.com/DFHack/dfhack/";
167 license = licenses.zlib;
168 platforms = [ "x86_64-linux" "i686-linux" ];
169 maintainers = with maintainers; [ robbinch a1russell abbradar numinit ncfavier ];