{ lib , fetchurl , runCommand , writeShellScriptBin , makeDesktopItem , imagemagick , p7zip , wineWow64Packages , dxvk , symlinkJoin , }: let wine = wineWow64Packages.stableFull; setupVersion = "nsis-launchpad-v2"; installDirWin = "C:\\Games\\EverQuestLegends"; installDirUnix = "drive_c/Games/EverQuestLegends"; installer = fetchurl { name = "EQLegends_setup.exe"; url = "https://launch.daybreakgames.com/installer/EQLegends_setup.exe"; hash = "sha256-MFuIuPt/MlVzlCwiIGjjKkYT0Sm7ov5wm5Mrd1zfzx4="; }; iconFiles = runCommand "eqlegends-icon" { nativeBuildInputs = [ imagemagick p7zip ]; } '' mkdir -p $out/share/icons/hicolor/256x256/apps tmpdir="$(mktemp -d)" 7z e -y -o"$tmpdir" ${installer} LaunchPad.ico >/dev/null magick "$tmpdir/LaunchPad.ico[0]" "$out/share/icons/hicolor/256x256/apps/eqlegends.png" ''; 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 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_path="''${EQL_INSTALLER:-${installer}}" if [ ! -f "$installer_path" ]; then cat >&2 <<'EOF' eqlegends: EQL_INSTALLER does not point to an existing file. Leave EQL_INSTALLER unset to use the pinned Daybreak installer, 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_path" /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)"; icon = "eqlegends"; exec = "eqlegends"; terminal = false; categories = [ "Game" "RolePlaying" ]; keywords = [ "EverQuest" "EverQuest Legends" "Daybreak" "Game" ]; startupNotify = true; }; 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 iconFiles 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"; }; }