3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/games/dwarf-fortress/wrapper/default.nix

140 lines
3.8 KiB
Nix
Raw Normal View History

2021-06-29 03:42:37 +01:00
{ stdenv
, lib
, buildEnv
, substituteAll
, runCommand
, coreutils
, dwarf-fortress
, dwarf-therapist
2021-06-29 03:42:37 +01:00
, enableDFHack ? false
, dfhack
, enableSoundSense ? false
, soundSense
, jdk
, enableStoneSense ? false
2021-06-29 03:42:37 +01:00
, enableTWBT ? false
, twbt
, themes ? { }
, theme ? null
2021-06-29 03:42:37 +01:00
# General config options:
, enableIntro ? true
, enableTruetype ? true
, enableFPS ? false
, enableTextMode ? false
, enableSound ? true
}:
let
dfhack_ = dfhack.override {
inherit enableStoneSense;
2018-07-05 16:36:27 +01:00
inherit enableTWBT;
};
ptheme =
if builtins.isString theme
then builtins.getAttr theme themes
else theme;
2018-07-05 16:36:27 +01:00
unBool = b: if b then "YES" else "NO";
# These are in inverse order for first packages to override the next ones.
themePkg = lib.optional (theme != null) ptheme;
pkgs = lib.optional enableDFHack dfhack_
2021-06-29 03:42:37 +01:00
++ lib.optional enableSoundSense soundSense
++ lib.optional enableTWBT twbt.art
++ [ dwarf-fortress ];
2021-06-29 03:42:37 +01:00
fixup = lib.singleton (runCommand "fixup" { } (''
2018-10-08 21:21:09 +01:00
mkdir -p $out/data/init
2018-11-07 19:56:32 +00:00
'' + (if (theme != null) then ''
cp ${lib.head themePkg}/data/init/init.txt $out/data/init/init.txt
'' else ''
2018-10-08 21:21:09 +01:00
cp ${dwarf-fortress}/data/init/init.txt $out/data/init/init.txt
2018-11-07 19:56:32 +00:00
'') + lib.optionalString enableDFHack ''
2018-10-08 21:21:09 +01:00
mkdir -p $out/hack
2018-10-08 21:21:09 +01: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-10-08 21:21:09 +01: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-10-08 21:21:09 +01: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]'
'' +
2021-06-29 03:42:37 +01:00
lib.optionalString enableTextMode ''
substituteInPlace $out/data/init/init.txt \
--replace '[PRINT_MODE:2D]' '[PRINT_MODE:TEXT]'
2018-10-08 21:21:09 +01:00
'' + ''
substituteInPlace $out/data/init/init.txt \
--replace '[INTRO:YES]' '[INTRO:${unBool enableIntro}]' \
--replace '[TRUETYPE:YES]' '[TRUETYPE:${unBool enableTruetype}]' \
--replace '[FPS:NO]' '[FPS:${unBool enableFPS}]' \
--replace '[SOUND:YES]' '[SOUND:${unBool enableSound}]'
''));
2018-10-08 21:21:09 +01:00
env = buildEnv {
name = "dwarf-fortress-env-${dwarf-fortress.dfVersion}";
2018-10-08 21:21:09 +01:00
paths = fixup ++ themePkg ++ pkgs;
pathsToLink = [ "/" "/hack" "/hack/scripts" ];
ignoreCollisions = true;
};
in
2019-08-13 22:52:01 +01:00
stdenv.mkDerivation {
name = "dwarf-fortress-${dwarf-fortress.dfVersion}";
dfInit = substituteAll {
name = "dwarf-fortress-init";
src = ./dwarf-fortress-init.in;
inherit env;
2021-06-29 03:42:37 +01:00
exe =
if stdenv.isLinux then "libs/Dwarf_Fortress"
else "dwarfort.exe";
stdenv_shell = "${stdenv.shell}";
cp = "${coreutils}/bin/cp";
rm = "${coreutils}/bin/rm";
ln = "${coreutils}/bin/ln";
cat = "${coreutils}/bin/cat";
mkdir = "${coreutils}/bin/mkdir";
};
runDF = ./dwarf-fortress.in;
runDFHack = ./dfhack.in;
runSoundSense = ./soundSense.in;
passthru = { inherit dwarf-fortress dwarf-therapist; };
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} \
--subst-var dfInit
chmod 755 $out/bin/dfhack
'' + 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
'';
preferLocalBuild = true;
}