Files
nix-everquest/packages/eqlegends/package.nix
T
2026-06-27 14:56:02 -07:00

169 lines
5.4 KiB
Nix

{ lib
, runCommand
, writeShellScriptBin
, makeDesktopItem
, wineWow64Packages
, dxvk
, symlinkJoin
,
}:
let
wine = wineWow64Packages.stableFull;
setupVersion = "nsis-launchpad-v2";
installDirWin = "C:\\Games\\EverQuestLegends";
installDirUnix = "drive_c/Games/EverQuestLegends";
setupDxvk = writeShellScriptBin "eqlegends-setup-dxvk" ''
set -euo pipefail
mkdir -p "$WINEPREFIX/drive_c/windows/system32" "$WINEPREFIX/drive_c/windows/syswow64"
cp -Lf ${dxvk.bin}/x64/d3d8.dll ${dxvk.bin}/x64/d3d9.dll ${dxvk.bin}/x64/d3d10core.dll ${dxvk.bin}/x64/d3d11.dll ${dxvk.bin}/x64/dxgi.dll "$WINEPREFIX/drive_c/windows/system32/"
cp -Lf ${dxvk.bin}/x32/d3d8.dll ${dxvk.bin}/x32/d3d9.dll ${dxvk.bin}/x32/d3d10core.dll ${dxvk.bin}/x32/d3d11.dll ${dxvk.bin}/x32/dxgi.dll "$WINEPREFIX/drive_c/windows/syswow64/"
wine reg add "HKCU\\Software\\Wine\\DllOverrides" /v d3d8 /t REG_SZ /d native /f
wine reg add "HKCU\\Software\\Wine\\DllOverrides" /v d3d9 /t REG_SZ /d native /f
wine reg add "HKCU\\Software\\Wine\\DllOverrides" /v d3d10core /t REG_SZ /d native /f
wine reg add "HKCU\\Software\\Wine\\DllOverrides" /v d3d11 /t REG_SZ /d native /f
wine reg add "HKCU\\Software\\Wine\\DllOverrides" /v dxgi /t REG_SZ /d native /f
'';
launcher = writeShellScriptBin "eqlegends" ''
set -euo pipefail
export WINEARCH=win64
export WINEDEBUG="''${EQL_WINEDEBUG:--all}"
export PATH="${wine}/bin:$PATH"
data_home="''${XDG_DATA_HOME:-$HOME/.local/share}"
export WINEPREFIX="''${EQL_WINEPREFIX:-$data_home/eqlegends/wine}"
version_file="$WINEPREFIX/.eqlegends-nix-version"
launcher_path_file="$WINEPREFIX/.eqlegends-launcher-path"
dxvk_marker="$WINEPREFIX/.eqlegends-dxvk-enabled"
launcher_exe="$WINEPREFIX/${installDirUnix}/LaunchPad.exe"
if [ -f "$launcher_path_file" ]; then
launcher_exe="$(cat "$launcher_path_file")"
fi
find_installer() {
if [ -n "''${EQL_INSTALLER:-}" ]; then
printf '%s\n' "$EQL_INSTALLER"
return
fi
if [ -f "$PWD/EQLegends_setup.exe" ]; then
printf '%s\n' "$PWD/EQLegends_setup.exe"
return
fi
printf '%s\n' ""
}
if [ "''${EQL_RESET_PREFIX:-0}" = "1" ]; then
echo "eqlegends: removing $WINEPREFIX"
rm -rf "$WINEPREFIX"
fi
if [ ! -f "$launcher_exe" ] || [ ! -f "$version_file" ] || [ "$(cat "$version_file" 2>/dev/null || true)" != "${setupVersion}" ]; then
installer="$(find_installer)"
if [ -z "$installer" ] || [ ! -f "$installer" ]; then
cat >&2 <<'EOF'
eqlegends: missing EQLegends_setup.exe
Run from the repository directory containing EQLegends_setup.exe, or set:
EQL_INSTALLER=/path/to/EQLegends_setup.exe nix run .#eqlegends
EOF
exit 1
fi
echo "eqlegends: creating Wine prefix at $WINEPREFIX"
rm -rf "$WINEPREFIX"
mkdir -p "$WINEPREFIX"
wineboot -u
wineserver -w
echo "eqlegends: installing EverQuest Legends LaunchPad with NSIS silent mode..."
wine "$installer" /S "/D=${installDirWin}"
# The NSIS installer starts LaunchPad after extraction even in silent mode.
# Stop that first instance so setup can finish and the wrapper can launch
# the recorded executable itself.
wineserver -k || true
if [ ! -f "$launcher_exe" ]; then
found_launcher="$(find "$WINEPREFIX/drive_c" -type f -iname LaunchPad.exe | head -n 1 || true)"
if [ -n "$found_launcher" ]; then
launcher_exe="$found_launcher"
fi
fi
if [ ! -f "$launcher_exe" ]; then
echo "eqlegends: LaunchPad.exe was not found after install." >&2
echo "eqlegends: inspect $WINEPREFIX/drive_c to see where the installer wrote files." >&2
exit 1
fi
printf '%s\n' "$launcher_exe" > "$launcher_path_file"
echo "${setupVersion}" > "$version_file"
echo "eqlegends: setup complete."
fi
if [ "''${EQL_DXVK:-0}" = "1" ] && [ ! -f "$dxvk_marker" ]; then
echo "eqlegends: installing DXVK into prefix..."
${setupDxvk}/bin/eqlegends-setup-dxvk
wineserver -w
touch "$dxvk_marker"
fi
if [ "''${EQL_DXVK:-0}" != "1" ] && [ -f "$dxvk_marker" ]; then
echo "eqlegends: DXVK was previously installed in this prefix." >&2
echo "eqlegends: run with EQL_DXVK=1 or reset with EQL_RESET_PREFIX=1 to return to WineD3D." >&2
fi
cd "$(dirname "$launcher_exe")"
exec wine "$launcher_exe" "$@"
'';
reset = writeShellScriptBin "eqlegends-reset-prefix" ''
set -euo pipefail
data_home="''${XDG_DATA_HOME:-$HOME/.local/share}"
prefix="''${EQL_WINEPREFIX:-$data_home/eqlegends/wine}"
echo "eqlegends: removing $prefix"
rm -rf "$prefix"
'';
desktopItem = makeDesktopItem {
name = "eqlegends";
desktopName = "EverQuest Legends";
comment = "EverQuest Legends LaunchPad (Wine)";
exec = "eqlegends";
categories = [ "Game" ];
};
desktopFiles = runCommand "eqlegends-desktop" { } ''
mkdir -p $out/share/applications
ln -s ${desktopItem}/share/applications/eqlegends.desktop $out/share/applications/
'';
in
symlinkJoin {
name = "eqlegends-launchpad";
paths = [
launcher
reset
desktopFiles
];
meta = {
description = "EverQuest Legends LaunchPad wrapper for Wine on NixOS";
homepage = "https://www.everquest.com/";
license = lib.licenses.unfree;
platforms = lib.platforms.linux;
mainProgram = "eqlegends";
};
}