dfhack: support 52.03

52.03 uses SDL functions for figuring out the Dwarf Fortress base
directory for storing saves. Make sure it uses one outside the store.

Changed files
+31 -13
pkgs
games
dwarf-fortress
+6 -13
pkgs/games/dwarf-fortress/dfhack/default.nix
···
name = "rename-lerp.patch";
url = "https://github.com/DFHack/dfhack/commit/389dcf5cfcdb8bfb8deeb05fa5756c9f4f5709d1.patch";
hash = "sha256-QuDtGURhP+nM+x+8GIKO5LrMcmBkl9JSHHIeqzqGIPQ=";
-
});
+
})
+
# Newer versions use SDL_GetBasePath and SDL_GetPrefPath with a Windows-esque directory
+
# that mismatches where we have historically stored data in nixpkgs:
+
# https://github.com/libsdl-org/SDL/blob/release-2.24.x/src/filesystem/unix/SDL_sysfilesystem.c#L136
+
# Use SDL_GetPrefPath since this takes XDG_DATA_HOME into account (which is correct).
+
++ optional (versionAtLeast version "52.02-r2") ./use-df-linux-dir.patch;
# gcc 11 fix
CXXFLAGS = optionalString (versionOlder version "0.47.05-r3") "-fpermissive";
-
-
# As of
-
# https://github.com/DFHack/dfhack/commit/56e43a0dde023c5a4595a22b29d800153b31e3c4,
-
# dfhack gets its goodies from the directory above the Dwarf_Fortress
-
# executable, which leads to stock Dwarf Fortress and not the built
-
# environment where all the dfhack resources are symlinked to (typically
-
# ~/.local/share/df_linux). This causes errors like `tweak is not a
-
# recognized command` to be reported and dfhack to lose some of its
-
# functionality.
-
postPatch = ''
-
sed -i 's@cached_path = path_string.*@cached_path = getenv("DF_DIR");@' library/Process-linux.cpp
-
'';
nativeBuildInputs = [
cmake
+25
pkgs/games/dwarf-fortress/dfhack/use-df-linux-dir.patch
···
+
diff --git a/library/modules/Filesystem.cpp b/library/modules/Filesystem.cpp
+
index 7a6b09a50..d5827f016 100644
+
--- a/library/modules/Filesystem.cpp
+
+++ b/library/modules/Filesystem.cpp
+
@@ -232,17 +232,10 @@ std::filesystem::path Filesystem::canonicalize(std::filesystem::path p) noexcept
+
+
std::filesystem::path Filesystem::getInstallDir() noexcept
+
{
+
- return std::filesystem::path{ DFSDL::DFSDL_GetBasePath() };
+
+ return std::filesystem::path{ DFSDL::DFSDL_GetPrefPath("", "df_linux") };
+
}
+
+
std::filesystem::path Filesystem::getBaseDir() noexcept
+
{
+
- auto getsavebase = []() {
+
- // assume portable mode is _on_ if init is missing
+
- if (!df::global::init || df::global::init->media.flag.is_set(df::enums::init_media_flags::PORTABLE_MODE))
+
- return DFSDL::DFSDL_GetBasePath();
+
- else
+
- return DFSDL::DFSDL_GetPrefPath("Bay 12 Games", "Dwarf Fortress");
+
- };
+
- return std::filesystem::path{ getsavebase() };
+
+ return std::filesystem::path{ DFSDL::DFSDL_GetPrefPath("", "df_linux") };
+
}
+