2018-10-08 22:21:09 +02:00
|
|
|
{ stdenv, lib, buildEnv, substituteAll, runCommand
|
2018-07-12 10:42:52 +02:00
|
|
|
, dwarf-fortress, dwarf-fortress-unfuck
|
2018-07-15 08:41:27 +02:00
|
|
|
, dwarf-therapist
|
2016-01-12 18:56:59 +01:00
|
|
|
, enableDFHack ? false, dfhack
|
2017-06-19 02:48:02 +02:00
|
|
|
, enableSoundSense ? false, soundSense, jdk
|
2017-10-01 21:26:51 +02:00
|
|
|
, enableStoneSense ? false
|
2018-07-05 17:36:27 +02:00
|
|
|
, enableTWBT ? false, twbt
|
2016-01-19 22:44:33 +01:00
|
|
|
, themes ? {}
|
|
|
|
, theme ? null
|
2018-07-05 21:09:03 +02:00
|
|
|
# General config options:
|
|
|
|
, enableIntro ? true
|
|
|
|
, enableTruetype ? true
|
|
|
|
, enableFPS ? false
|
2016-01-12 18:56:59 +01:00
|
|
|
}:
|
|
|
|
|
2016-01-19 22:44:33 +01:00
|
|
|
let
|
2017-10-01 21:26:51 +02:00
|
|
|
dfhack_ = dfhack.override {
|
|
|
|
inherit enableStoneSense;
|
2018-07-05 17:36:27 +02:00
|
|
|
inherit enableTWBT;
|
2017-10-01 21:26:51 +02:00
|
|
|
};
|
|
|
|
|
2016-01-19 22:44:33 +01:00
|
|
|
ptheme =
|
|
|
|
if builtins.isString theme
|
|
|
|
then builtins.getAttr theme themes
|
|
|
|
else theme;
|
|
|
|
|
2018-07-05 17:36:27 +02:00
|
|
|
unBool = b: if b then "YES" else "NO";
|
|
|
|
|
2016-01-19 22:44:33 +01:00
|
|
|
# These are in inverse order for first packages to override the next ones.
|
2018-07-04 21:18:20 +02:00
|
|
|
themePkg = lib.optional (theme != null) ptheme;
|
|
|
|
pkgs = lib.optional enableDFHack dfhack_
|
2017-06-19 02:48:02 +02:00
|
|
|
++ lib.optional enableSoundSense soundSense
|
2018-07-05 17:36:27 +02:00
|
|
|
++ lib.optional enableTWBT twbt.art
|
2018-07-08 21:44:29 +02:00
|
|
|
++ [ dwarf-fortress ];
|
2016-01-19 22:44:33 +01:00
|
|
|
|
2018-11-05 21:48:42 +01:00
|
|
|
fixup = lib.singleton (runCommand "fixup" {} (''
|
2018-10-08 22:21:09 +02:00
|
|
|
mkdir -p $out/data/init
|
2018-11-07 20:56:32 +01:00
|
|
|
'' + (if (theme != null) then ''
|
|
|
|
cp ${lib.head themePkg}/data/init/init.txt $out/data/init/init.txt
|
|
|
|
'' else ''
|
2018-10-08 22:21:09 +02:00
|
|
|
cp ${dwarf-fortress}/data/init/init.txt $out/data/init/init.txt
|
2018-11-07 20:56:32 +01:00
|
|
|
'') + lib.optionalString enableDFHack ''
|
2018-10-08 22:21:09 +02:00
|
|
|
mkdir -p $out/hack
|
2016-11-24 00:51:51 +01:00
|
|
|
|
2018-10-08 22:21:09 +02:00
|
|
|
# Patch the MD5
|
|
|
|
orig_md5=$(cat "${dwarf-fortress}/hash.md5.orig")
|
|
|
|
patched_md5=$(cat "${dwarf-fortress}/hash.md5")
|
|
|
|
input_file="${dfhack_}/hack/symbols.xml"
|
|
|
|
output_file="$out/hack/symbols.xml"
|
2018-07-15 05:58:37 +02:00
|
|
|
|
2018-10-08 22:21:09 +02:00
|
|
|
echo "[DFHack Wrapper] Fixing Dwarf Fortress MD5:"
|
|
|
|
echo " Input: $input_file"
|
|
|
|
echo " Search: $orig_md5"
|
|
|
|
echo " Output: $output_file"
|
|
|
|
echo " Replace: $patched_md5"
|
2018-07-15 05:58:37 +02:00
|
|
|
|
2018-10-08 22:21:09 +02:00
|
|
|
substitute "$input_file" "$output_file" --replace "$orig_md5" "$patched_md5"
|
|
|
|
'' + lib.optionalString enableTWBT ''
|
|
|
|
substituteInPlace $out/data/init/init.txt \
|
|
|
|
--replace '[PRINT_MODE:2D]' '[PRINT_MODE:TWBT]'
|
|
|
|
'' + ''
|
|
|
|
substituteInPlace $out/data/init/init.txt \
|
|
|
|
--replace '[INTRO:YES]' '[INTRO:${unBool enableIntro}]' \
|
|
|
|
--replace '[TRUETYPE:YES]' '[TRUETYPE:${unBool enableTruetype}]' \
|
|
|
|
--replace '[FPS:NO]' '[FPS:${unBool enableFPS}]'
|
2018-11-05 21:48:42 +01:00
|
|
|
''));
|
2018-07-15 05:58:37 +02:00
|
|
|
|
2018-10-08 22:21:09 +02:00
|
|
|
env = buildEnv {
|
|
|
|
name = "dwarf-fortress-env-${dwarf-fortress.dfVersion}";
|
2018-07-15 05:58:37 +02:00
|
|
|
|
2018-10-08 22:21:09 +02:00
|
|
|
paths = fixup ++ themePkg ++ pkgs;
|
|
|
|
pathsToLink = [ "/" "/hack" "/hack/scripts" ];
|
2018-07-15 05:58:37 +02:00
|
|
|
|
2016-01-19 22:44:33 +01:00
|
|
|
ignoreCollisions = true;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
2016-01-12 18:56:59 +01:00
|
|
|
stdenv.mkDerivation rec {
|
2018-07-08 21:44:29 +02:00
|
|
|
name = "dwarf-fortress-${dwarf-fortress.dfVersion}";
|
2016-01-12 18:56:59 +01:00
|
|
|
|
|
|
|
dfInit = substituteAll {
|
|
|
|
name = "dwarf-fortress-init";
|
|
|
|
src = ./dwarf-fortress-init.in;
|
2016-01-19 22:44:33 +01:00
|
|
|
inherit env;
|
2018-05-11 06:55:06 +02:00
|
|
|
exe = if stdenv.isLinux then "libs/Dwarf_Fortress"
|
2018-07-01 22:28:59 +02:00
|
|
|
else "dwarfort.exe";
|
2016-01-12 18:56:59 +01:00
|
|
|
};
|
2016-01-19 22:44:33 +01:00
|
|
|
|
|
|
|
runDF = ./dwarf-fortress.in;
|
|
|
|
runDFHack = ./dfhack.in;
|
2017-06-19 02:48:02 +02:00
|
|
|
runSoundSense = ./soundSense.in;
|
2016-01-12 18:56:59 +01:00
|
|
|
|
2018-07-15 08:41:27 +02:00
|
|
|
passthru = { inherit dwarf-fortress dwarf-therapist; };
|
2018-07-08 21:44:29 +02:00
|
|
|
|
2016-01-12 18:56:59 +01:00
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
|
|
|
|
substitute $runDF $out/bin/dwarf-fortress \
|
|
|
|
--subst-var-by stdenv_shell ${stdenv.shell} \
|
|
|
|
--subst-var dfInit
|
|
|
|
chmod 755 $out/bin/dwarf-fortress
|
|
|
|
'' + lib.optionalString enableDFHack ''
|
|
|
|
substitute $runDFHack $out/bin/dfhack \
|
|
|
|
--subst-var-by stdenv_shell ${stdenv.shell} \
|
2016-01-19 22:44:33 +01:00
|
|
|
--subst-var dfInit
|
2016-01-12 18:56:59 +01:00
|
|
|
chmod 755 $out/bin/dfhack
|
2017-06-19 02:48:02 +02:00
|
|
|
'' + lib.optionalString enableSoundSense ''
|
|
|
|
substitute $runSoundSense $out/bin/soundsense \
|
|
|
|
--subst-var-by stdenv_shell ${stdenv.shell} \
|
|
|
|
--subst-var-by jre ${jdk.jre} \
|
|
|
|
--subst-var dfInit
|
|
|
|
chmod 755 $out/bin/soundsense
|
2016-01-12 18:56:59 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
preferLocalBuild = true;
|
|
|
|
}
|