nixos/modules/tibia.nix

120 lines
2.8 KiB
Nix

{ config, pkgs, lib, ... }:
let
# Legacy libxml2 (2.9.x) — required by Tibia
libxml2_2_9 = pkgs.stdenv.mkDerivation {
pname = "libxml2-2.9";
version = "2.9.14";
src = pkgs.fetchurl {
url = "https://download.gnome.org/sources/libxml2/2.9/libxml2-2.9.14.tar.xz";
sha256 = "sha256-YNdKJX0czsBHXnScui8hVZ5IE577pv8oIkNXx8eY3+4=";
};
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.zlib pkgs.xz ];
configureFlags = [
"--disable-static"
"--without-python"
];
enableParallelBuilding = true;
};
# Centralized runtime library path for Tibia
tibiaLibPath =
lib.makeLibraryPath [
pkgs.nss
pkgs.nspr
pkgs.libxkbfile
libxml2_2_9
];
# Helper: LD_LIBRARY_PATH export line
exportLibs = ''
export LD_LIBRARY_PATH="${tibiaLibPath}:$LD_LIBRARY_PATH"
'';
# Wrapper for the real client (system-wide)
tibiaClientWrapper = pkgs.writeShellScriptBin "tibia-client" ''
#!/usr/bin/env bash
${exportLibs}
exec steam-run "$HOME/.local/share/CipSoft GmbH/Tibia/packages/Tibia/bin/client" "$@"
'';
# Patcher for Tibia's package.json
tibiaPatcher = pkgs.writeShellScriptBin "tibia-patch" ''
#!/usr/bin/env bash
set -e
PKGDIR="$HOME/.local/share/CipSoft GmbH/Tibia/packages/Tibia"
PKGJSON="$PKGDIR/package.json"
LOCALWRAPPER="$PKGDIR/tibia-client-wrapper"
if [ ! -f "$PKGJSON" ]; then
echo "package.json not found run the launcher once first."
exit 0
fi
# Create wrapper inside Tibia package directory
cat > "$LOCALWRAPPER" <<EOF
#!/usr/bin/env bash
${exportLibs}
exec /run/current-system/sw/bin/tibia-client "\$@"
EOF
chmod +x "$LOCALWRAPPER"
# Patch JSON to use the local wrapper
sed -i 's#"executable": "bin/client"#"executable": "tibia-client-wrapper"#' "$PKGJSON"
echo "Tibia client patched to use tibia-client-wrapper."
'';
# Wrapper for the Tibia launcher
tibiaLauncherWrapper = pkgs.writeShellScriptBin "tibia" ''
#!/usr/bin/env bash
set -e
LAUNCHER="$HOME/Gry/Tibia/Tibia"
if [ ! -x "$LAUNCHER" ]; then
echo "Tibia launcher not found at:"
echo " $LAUNCHER"
exit 1
fi
tibia-patch
${exportLibs}
exec steam-run "$LAUNCHER"
'';
# Direct client launcher (bypasses Tibia's launcher entirely)
tibiaDirect = pkgs.writeShellScriptBin "tibia-direct" ''
#!/usr/bin/env bash
CLIENT="$HOME/.local/share/CipSoft GmbH/Tibia/packages/Tibia/bin/client"
if [ ! -x "$CLIENT" ]; then
echo "Tibia client not found."
echo "Run the official launcher once so it downloads the client."
exit 1
fi
${exportLibs}
exec steam-run "$CLIENT"
'';
in
{
environment.systemPackages = [
pkgs.steam-run
libxml2_2_9
tibiaClientWrapper
tibiaPatcher
tibiaLauncherWrapper
tibiaDirect
];
}