push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,305 @@
{
stdenv,
lib,
buildEnv,
replaceVars,
makeWrapper,
runCommand,
coreutils,
gawk,
dwarf-fortress,
dwarf-therapist,
SDL2_mixer,
enableDFHack ? false,
dfhack,
enableSoundSense ? false,
soundSense,
jre,
expect,
xvfb-run,
writeText,
enableStoneSense ? false,
enableTWBT ? false,
twbt,
themes ? { },
theme ? null,
extraPackages ? [ ],
# General config options:
enableIntro ? true,
enableTruetype ? null, # defaults to 24, see init.txt
enableFPS ? false,
enableTextMode ? false,
enableSound ? true,
# An attribute set of settings to override in data/init/*.txt.
# For example, `init.FOO = true;` is translated to `[FOO:YES]` in init.txt
settings ? { },
# TODO world-gen.txt, interface.txt require special logic
}:
let
dfhack' = dfhack.override {
inherit enableStoneSense;
};
isAtLeast50 = dwarf-fortress.baseVersion >= 50;
# If TWBT is null or the dfVersion is wrong, it isn't supported (for example, on version 50).
enableTWBT' = enableTWBT && twbt != null && (twbt.dfVersion or null) == dwarf-fortress.version;
ptheme = if builtins.isString theme then builtins.getAttr theme themes else theme;
baseEnv = buildEnv {
name = "dwarf-fortress-base-env-${dwarf-fortress.dfVersion}";
# These are in inverse order for first packages to override the next ones.
paths =
extraPackages
++ lib.optional (theme != null) ptheme
++ lib.optional enableDFHack dfhack'
++ lib.optional enableSoundSense soundSense
++ lib.optionals enableTWBT' [
twbt.lib
twbt.art
]
++ [ dwarf-fortress ];
ignoreCollisions = true;
};
settings' = lib.recursiveUpdate {
init = {
PRINT_MODE =
if enableTextMode then
"TEXT"
else if enableTWBT' then
"TWBT"
else if stdenv.hostPlatform.isDarwin then
"STANDARD" # https://www.bay12games.com/dwarves/mantisbt/view.php?id=11680
else
null;
INTRO = enableIntro;
TRUETYPE = enableTruetype;
FPS = enableFPS;
SOUND = enableSound;
};
} settings;
forEach = attrs: f: lib.concatStrings (lib.mapAttrsToList f attrs);
toTxt =
v:
if lib.isBool v then
if v then "YES" else "NO"
else if lib.isInt v then
toString v
else if lib.isString v then
v
else
throw "dwarf-fortress: unsupported configuration value ${toString v}";
config =
runCommand "dwarf-fortress-config"
{
nativeBuildInputs = [
gawk
makeWrapper
];
}
(
''
mkdir -p $out/data/init
edit_setting() {
v=''${v//'&'/'\&'}
if [ -f "$out/$file" ]; then
if ! gawk -i inplace -v RS='\r?\n' '
{ n += sub("\\[" ENVIRON["k"] ":[^]]*\\]", "[" ENVIRON["k"] ":" ENVIRON["v"] "]"); print }
END { exit(!n) }
' "$out/$file"; then
echo "error: no setting named '$k' in $out/$file" >&2
exit 1
fi
else
echo "warning: no file $out/$file; cannot edit" >&2
fi
}
''
+ forEach settings' (
file: kv:
''
file=data/init/${lib.escapeShellArg file}.txt
if [ -f "${baseEnv}/$file" ]; then
cp "${baseEnv}/$file" "$out/$file"
else
echo "warning: no file ${baseEnv}/$file; cannot copy" >&2
fi
''
+ forEach kv (
k: v:
lib.optionalString (v != null) ''
export k=${lib.escapeShellArg k} v=${lib.escapeShellArg (toTxt v)}
edit_setting
''
)
)
+ lib.optionalString enableDFHack ''
mkdir -p $out/hack
# Patch the MD5
orig_md5=$(< "${dwarf-fortress}/hash.md5.orig")
patched_md5=$(< "${dwarf-fortress}/hash.md5")
input_file="${dfhack'}/hack/symbols.xml"
output_file="$out/hack/symbols.xml"
echo "[DFHack Wrapper] Fixing Dwarf Fortress MD5:"
echo " Input: $input_file"
echo " Search: $orig_md5"
echo " Output: $output_file"
echo " Replace: $patched_md5"
substitute "$input_file" "$output_file" --replace-fail "$orig_md5" "$patched_md5"
''
);
# This is a separate environment because the config files to modify may come
# from any of the paths in baseEnv.
env = buildEnv {
name = "dwarf-fortress-env-${dwarf-fortress.dfVersion}";
paths = [
config
baseEnv
];
ignoreCollisions = true;
};
in
lib.throwIf (enableTWBT' && !enableDFHack) "dwarf-fortress: TWBT requires DFHack to be enabled"
lib.throwIf
(enableStoneSense && !enableDFHack)
"dwarf-fortress: StoneSense requires DFHack to be enabled"
lib.throwIf
(enableTextMode && enableTWBT')
"dwarf-fortress: text mode and TWBT are mutually exclusive"
stdenv.mkDerivation
{
pname = "dwarf-fortress";
version = dwarf-fortress.dfVersion;
dfInit = replaceVars ./dwarf-fortress-init.in {
inherit env;
stdenv_shell = "${stdenv.shell}";
cp = "${coreutils}/bin/cp";
rm = "${coreutils}/bin/rm";
ln = "${coreutils}/bin/ln";
cat = "${coreutils}/bin/cat";
mkdir = "${coreutils}/bin/mkdir";
printf = "${coreutils}/bin/printf";
uname = "${coreutils}/bin/uname";
SDL2_mixer = "${SDL2_mixer}/lib/libSDL2_mixer.so";
};
runDF = ./dwarf-fortress.in;
runSoundSense = ./soundSense.in;
passthru = {
inherit
dwarf-fortress
dwarf-therapist
twbt
env
;
dfhack = dfhack';
};
dontUnpack = true;
dontBuild = true;
preferLocalBuild = true;
installPhase = ''
mkdir -p $out/bin
substitute $runDF $out/bin/dwarf-fortress \
--subst-var-by stdenv_shell ${stdenv.shell} \
--subst-var-by dfExe ${dwarf-fortress.exe} \
--subst-var dfInit
chmod 755 $out/bin/dwarf-fortress
''
+ lib.optionalString enableDFHack ''
substitute $runDF $out/bin/dfhack \
--subst-var-by stdenv_shell ${stdenv.shell} \
--subst-var-by dfExe dfhack \
--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 ${jre} \
--subst-var dfInit
chmod 755 $out/bin/soundsense
'';
doInstallCheck = stdenv.hostPlatform.isLinux;
nativeInstallCheckInputs = lib.optionals stdenv.hostPlatform.isLinux [
expect
xvfb-run
];
installCheckPhase =
let
commonExpectStatements = ''
expect "Loading bindings from data/init/interface.txt"
'';
dfHackExpectScript = writeText "dfhack-test.exp" (
''
spawn env NIXPKGS_DF_OPTS=debug xvfb-run $env(out)/bin/dfhack
''
+ commonExpectStatements
+ ''
expect "DFHack is ready. Have a nice day!"
expect "DFHack version ${dfhack'.version}"
expect "\[DFHack\]#"
send -- "lua print(os.getenv('out'))\r"
expect "$env(out)"
# Don't send 'die' here; just exit. Some versions of dfhack crash on exit.
exit 0
''
);
vanillaExpectScript =
fmod:
writeText "vanilla-test.exp" (
''
spawn env NIXPKGS_DF_OPTS=debug,${lib.optionalString fmod "fmod"} xvfb-run $env(out)/bin/dwarf-fortress
''
+ commonExpectStatements
+ ''
exit 0
''
);
in
''
export HOME="$(mktemp -dt dwarf-fortress.XXXXXX)"
''
+ lib.optionalString enableDFHack ''
expect ${dfHackExpectScript}
df_home="$(find ~ -name "df_*" | head -n1)"
test -f "$df_home/dfhack"
''
+ lib.optionalString isAtLeast50 ''
expect ${vanillaExpectScript true}
df_home="$(find ~ -name "df_*" | head -n1)"
test ! -f "$df_home/dfhack"
test -f "$df_home/libfmod_plugin.so"
''
+ ''
expect ${vanillaExpectScript false}
df_home="$(find ~ -name "df_*" | head -n1)"
test ! -f "$df_home/dfhack"
test ! -f "$df_home/libfmod_plugin.so"
''
+ ''
test -d "$df_home/data"
'';
inherit (dwarf-fortress) meta;
}

View File

@@ -0,0 +1,192 @@
#!@stdenv_shell@ -e
set -euo pipefail
shopt -s extglob
export NIXPKGS_DF_ENV="@env@"
### BEGIN: Default DF options
declare -A _NIXPKGS_DF_OPTS
_NIXPKGS_DF_OPTS[fmod]=0 # Don't use fmod by default.
_NIXPKGS_DF_OPTS[debug]=0 # No debugging output by default.
### END: Default DF options
# Read NIXPKGS_DF_OPTS.
if [[ ! -v NIXPKGS_DF_OPTS ]]; then
NIXPKGS_DF_OPTS=''
fi
IFS=',' read -ra options <<< "$NIXPKGS_DF_OPTS"
for option in ${options[@]+"${options[@]}"}; do
key="${option%=*}"
value="${option##*=}"
if [ -n "$key" ]; then
if [ -z "$value" ] || [ "$key" == "$value" ]; then
value=1
fi
_NIXPKGS_DF_OPTS["$key"]="$value"
fi
done
# Rebuild the canonical option string from the read options.
NIXPKGS_DF_OPTS=''
for key in "${!_NIXPKGS_DF_OPTS[@]}"; do
value="${_NIXPKGS_DF_OPTS["${key}"]}"
NIXPKGS_DF_OPTS="$NIXPKGS_DF_OPTS$key=$value,"
done
NIXPKGS_DF_OPTS="${NIXPKGS_DF_OPTS%,}"
# Echoes a log.
# $@: log messages
log() {
for msg in "$@"; do
echo "[nixpkgs] $msg" >&2
done
}
# Echoes a log if NIXPKGS_DF_OPTS includes debug.
# $@: log messages
debug() {
if [ "${_NIXPKGS_DF_OPTS[debug]}" -ne 0 ]; then
log "$@"
fi
}
# Updates a path in $NIXPKGS_DF_HOME from $NIXPKGS_DF_ENV.
# $1: The environment path.
update_path() {
local path="$1"
local orig="$NIXPKGS_DF_ENV/$path"
local final="$NIXPKGS_DF_HOME/$path"
# If user has replaced these data directories, let them stay.
@mkdir@ -p "$(dirname -- "$final")"
if [ ! -e "$final" ] || [ -L "$final" ]; then
debug "Linking: $final -> $orig"
@rm@ -f "$final"
@ln@ -s "$orig" "$final"
else
debug "Not updating: $final"
fi
}
# Cleans up a path in $NIXPKGS_DF_HOME that may or may not be in $NIXPKGS_DF_ENV.
# $1: The environment path.
cleanup_path() {
local path="$1"
local final="$NIXPKGS_DF_HOME/$path"
# Let them stay if not a link.
if [ ! -e "$final" ] || [ -L "$final" ]; then
debug "Cleaning up: $final"
@rm@ -f "$final"
else
debug "Not cleaning: $final"
fi
}
# Force copies a path in $NIXPKGS_DF_HOME that may or may not be in $NIXPKGS_DF_ENV.
# $1: The environment path.
forcecopy_path() {
local path="$1"
if [ -z "$NIXPKGS_DF_ENV" ] || [ -z "$path" ]; then
# Avoid producing "/" for any `rm -rf`
return
fi
local orig="$NIXPKGS_DF_ENV/$path"
local final="$NIXPKGS_DF_HOME/$path"
if [ -e "$orig" ]; then
debug "Force copying: $orig -> $final"
@mkdir@ -p "$(dirname -- "$final")"
@rm@ -rf "$final"
@cp@ -rL --no-preserve=all "$orig" "$final"
else
debug "Removing: $final"
@rm@ -rf "$final"
fi
}
# Runs the final executable. Expects NIXPKGS_DF_HOME and NIXPKGS_DF_EXE to be set.
go() {
cd "$NIXPKGS_DF_HOME"
debug "Executing: $NIXPKGS_DF_HOME/$NIXPKGS_DF_EXE"
# Only mess with the library paths if we're starting Dwarf Fortress (not Soundsense).
if [ "$NIXPKGS_DF_GAME" -eq 1 ]; then
# Handle library paths on Darwin.
if [ "$NIXPKGS_DF_PLATFORM" == df_osx ]; then
if [ "${NIXPKGS_DF_PLATFORM_REV%%.*}" -ge 11 ]; then
export DYLD_LIBRARY_PATH="$NIXPKGS_DF_ENV/libs"
export DYLD_FRAMEWORK_PATH="$NIXPKGS_DF_ENV/libs"
else
export DYLD_FALLBACK_LIBRARY_PATH="$NIXPKGS_DF_ENV/libs"
export DYLD_FALLBACK_FRAMEWORK_PATH="$NIXPKGS_DF_ENV/libs"
fi
fi
if [ "$NIXPKGS_DF_PLATFORM" == df_linux ]; then
# We have to preload the audio plugin for audio to work. See Nix Pill #12 for this pattern:
# https://nixos.org/guides/nix-pills/12-inputs-design-pattern.html
if [ "${_NIXPKGS_DF_OPTS[fmod]}" -eq 0 ] && [ -f "$NIXPKGS_DF_HOME/libfmod.so.13" ]; then
export LD_PRELOAD="$NIXPKGS_DF_HOME/libfmod.so.13${LD_PRELOAD:+:}${LD_PRELOAD:-}"
else
export LD_PRELOAD="@SDL2_mixer@${LD_PRELOAD:+:}${LD_PRELOAD:-}"
fi
fi
fi
# If we make it past here, we want to log.
# shellcheck disable=SC2093
exec -a "$NIXPKGS_DF_EXE" "$NIXPKGS_DF_HOME/$NIXPKGS_DF_EXE" "$@"
log "Execution of $NIXPKGS_DF_HOME/$NIXPKGS_DF_EXE failed!"
exit 1
}
# Figure out the Dwarf Fortress directory (df_linux or df_osx).
os_name="$(@uname@)"
if [ "$os_name" == Linux ]; then
export NIXPKGS_DF_PLATFORM="df_linux"
elif [ "$os_name" == Darwin ]; then
export NIXPKGS_DF_PLATFORM="df_osx"
else
log "Unknown platform: $os_name"
exit 1
fi
export NIXPKGS_DF_PLATFORM_REV="$(@uname@ -r)"
if [[ -v DF_DIR ]] && [ -n "$DF_DIR" ] && { [[ ! -v NIXPKGS_DF_HOME ]] || [ -z "$NIXPKGS_DF_HOME" ]; }; then
# Compatibility for users that were using DF_DIR, since the dfhack script clobbers this variable.
export NIXPKGS_DF_HOME="$DF_DIR"
fi
if [[ ! -v NIXPKGS_DF_HOME ]] || [ -z "$NIXPKGS_DF_HOME" ]; then
export NIXPKGS_DF_HOME="${XDG_DATA_HOME:-$HOME/.local/share}/$NIXPKGS_DF_PLATFORM"
fi
# Compatibility.
export DF_DIR="$NIXPKGS_DF_HOME"
@mkdir@ -p "$NIXPKGS_DF_HOME"
@cat@ <<EOF >&2
/------------------------------------------------------------------------------\\
| Hello from the nixpkgs Dwarf Fortress wrapper! |
| |
| Using the following Dwarf Fortress overlay directory as NIXPKGS_DF_HOME: |
| $(@printf@ '% -76s' "$NIXPKGS_DF_HOME") |
| |
| If you make any changes in it, don't forget to clean it when updating the |
| game version! We detect changes if data directories are symbolic links. |
| |
| Even though we do our best on our own, this script may miss some. Submit a |
| pull request if there are any that become a problem. |
| |
| We started with the following nixpkgs launch options as NIXPKGS_DF_OPTS: |
| $(@printf@ '% -76s' "$NIXPKGS_DF_OPTS") |
| |
| If you want to try fmod over SDL_mixer, set NIXPKGS_DF_OPTS=fmod. |
\\------------------------------------------------------------------------------/
EOF
cd "$NIXPKGS_DF_ENV"

View File

@@ -0,0 +1,59 @@
#!@stdenv_shell@ -e
export NIXPKGS_DF_EXE="@dfExe@"
export NIXPKGS_DF_GAME=1
source @dfInit@
# All potential important files in DF 50 and below.
for path in dwarfort dwarfort.exe df *.so* libs raw data/init/* data/!(init|index|announcement); do
force_delete=0
if [[ "$path" == *fmod*.so* ]] && [ "${_NIXPKGS_DF_OPTS[fmod]}" -eq 0 ]; then
# Delete fmod plugins if we're using SDL_mixer.
force_delete=1
elif [[ "$path" == *mixer*.so* ]] && [ "${_NIXPKGS_DF_OPTS[fmod]}" -ne 0 ]; then
# Delete SDL_mixer plugins if we're using fmod.
force_delete=1
fi
if [ -e "$path" ] && [ "$force_delete" -eq 0 ]; then
update_path "$path"
else
cleanup_path "$path"
fi
done
# These need to be copied due to read only flags on older versions of DF.
for path in index announcement help dipscript; do
forcecopy_path "data/$path"
done
# If we're switching back from dfhack to vanilla, cleanup all dfhack
# links so Dwarf Fortress doesn't autoload its leftover libdfhooks.so.
# Otherwise, populate them.
dfhack_files=(
dfhack
dfhack-run
.dfhackrc
libdfhooks.so
dfhack-config/default
dfhack-config/init
hack/*
stonesense/*
*.init *.init-example
)
if [ "${NIXPKGS_DF_EXE##*/}" == dfhack ]; then
for i in "${dfhack_files[@]}"; do
if [ -e "$i" ]; then
update_path "$i"
else
cleanup_path "$i"
fi
done
else
for i in "${dfhack_files[@]}"; do
cleanup_path "$i"
done
fi
go "$@"

View File

@@ -0,0 +1,11 @@
#!@stdenv_shell@ -e
export NIXPKGS_DF_EXE="soundsense/soundSense.sh"
export NIXPKGS_DF_GAME=0
source @dfInit@
for path in soundsense/*; do
update_path "$path"
done
JDK_JAVA_OPTIONS='--add-opens=java.xml/com.sun.org.apache.xerces.internal.parsers=ALL-UNNAMED' PATH="@jre@/bin:$PATH" go "$@"