From 06727476d178e2ca79d8ce6f7c6f71be65840015 Mon Sep 17 00:00:00 2001 From: OPNA2608 Date: Tue, 22 Apr 2025 19:56:51 +0200 Subject: [PATCH 1/4] edopro: Fix passthru.updateScript - Error output was not getting printed to stderr, so running it via update.nix wouldn't display the error - Fetched latest irrlicht was getting overridden by fixed irrlicht rev, meaning that irrlicht would never get an update --- pkgs/by-name/ed/edopro/update.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pkgs/by-name/ed/edopro/update.py b/pkgs/by-name/ed/edopro/update.py index c7594b758d21..5e0efed21ddc 100755 --- a/pkgs/by-name/ed/edopro/update.py +++ b/pkgs/by-name/ed/edopro/update.py @@ -2,6 +2,7 @@ #! nix-shell -i python -p nix-prefetch-github python3Packages.githubkit import json import subprocess +import sys from githubkit import GitHub, UnauthAuthStrategy from githubkit.versions.latest.models import ( @@ -15,15 +16,11 @@ DEPS_PATH: str = "./pkgs/by-name/ed/edopro/deps.nix" with GitHub(UnauthAuthStrategy()) as github: edopro: Tag = github.rest.repos.list_tags("edo9300", "edopro").parsed_data[0] - # This dep is not versioned in anyway and is why we check below to see if this is a new version. + # This dep is not versioned in any way and is why we check below to see if this is a new version. irrlicht: Commit = github.rest.repos.list_commits( "edo9300", "irrlicht1-8-4" ).parsed_data[0] - irrlicht: Commit = github.rest.repos.get_commit( - "edo9300", "irrlicht1-8-4", "7edde28d4f8c0c3589934c398a3a441286bb7c22" - ).parsed_data - edopro_working_version: str = "" try: @@ -32,11 +29,11 @@ try: if "edopro-version" in line: edopro_working_version = line.split('"')[1] except FileNotFoundError: - print("Error: Dep file not found.") + print("Error: Dep file not found.", file=sys.stderr) exit(2) if edopro_working_version == "": - print("Working version is unbound") + print("Working version is unbound", file=sys.stderr) exit(5) if edopro_working_version == edopro.name: @@ -98,7 +95,7 @@ with open(DEPS_PATH, "w") as file: edopro-version = "{edopro.name}"; edopro-rev = "{edopro.commit.sha}"; edopro-hash = "{edopro_hash}"; - irrlicht-version = "{"1.9.0-unstable-" + irrlicht.commit.committer.date.split("T")[0]}"; + irrlicht-version = "{"1.9.0-unstable-" + irrlicht.commit.committer.date.strftime("%Y-%m-%d")}"; irrlicht-rev = "{irrlicht.sha}"; irrlicht-hash = "{irrlicht_hash}"; }} From 318c38a04ab476db94904aeb1f8c70afe2410f24 Mon Sep 17 00:00:00 2001 From: OPNA2608 Date: Thu, 24 Apr 2025 19:59:40 +0200 Subject: [PATCH 2/4] edopro: Build & set up ocgcore from src as default core Unlike last time, we still build edopro to look in downloaded script repos for updated ocgcores. We just patch it so it can find & load the ocgcore from its release tag first, in case the scripts download doesn't have a core. --- pkgs/by-name/ed/edopro/deps.nix | 2 +- .../ed/edopro/ocgcore-lua-symbols.patch | 29 +++++++ pkgs/by-name/ed/edopro/package.nix | 77 +++++++++++++++++-- pkgs/by-name/ed/edopro/update.py | 2 +- 4 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 pkgs/by-name/ed/edopro/ocgcore-lua-symbols.patch diff --git a/pkgs/by-name/ed/edopro/deps.nix b/pkgs/by-name/ed/edopro/deps.nix index e45c21c0f662..0a6ac49aca3c 100644 --- a/pkgs/by-name/ed/edopro/deps.nix +++ b/pkgs/by-name/ed/edopro/deps.nix @@ -4,7 +4,7 @@ assets-hash = "sha256-vZhkWJ1ZoNEwdc5kM1S0hyXnWmupiTOanCi9DCuqw/k="; edopro-version = "40.1.4"; edopro-rev = "c713e23491a1e55c9d8e91257e5f2b5873696b9b"; - edopro-hash = "sha256-mj0xEJsFcnY//za0uJosAPOPbU/jlduNX0YSNmvduLE="; + edopro-hash = "sha256-2E1cjG0FONu/fbr67/3qRCKQ1W/wPznClEWsMa1FAzo="; irrlicht-version = "1.9.0-unstable-2023-02-18"; irrlicht-rev = "7edde28d4f8c0c3589934c398a3a441286bb7c22"; irrlicht-hash = "sha256-Q2tNiYE/enZPqA5YhUe+Tkvmqtmmz2E0OqTRUDnt+UA="; diff --git a/pkgs/by-name/ed/edopro/ocgcore-lua-symbols.patch b/pkgs/by-name/ed/edopro/ocgcore-lua-symbols.patch new file mode 100644 index 000000000000..253051ebf0f7 --- /dev/null +++ b/pkgs/by-name/ed/edopro/ocgcore-lua-symbols.patch @@ -0,0 +1,29 @@ +From 41e750142b44465f3af197b7e2f0d6f54fc48c2d Mon Sep 17 00:00:00 2001 +From: OPNA2608 +Date: Mon, 21 Oct 2024 17:42:24 +0200 +Subject: [PATCH] Mark Lua symbols as C symbols + +Otherwise linking against our Lua built by a C-compiler fails due to the symbols being resolved as C++ symbols. +--- + interpreter.h | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/interpreter.h b/interpreter.h +index 6c405a1..c471ecb 100644 +--- a/interpreter.h ++++ b/interpreter.h +@@ -9,9 +9,11 @@ + #define INTERPRETER_H_ + + // Due to longjmp behaviour, we must build Lua as C++ to avoid UB ++extern "C" { + #include + #include + #include ++} + + #include "common.h" + #include +-- +2.44.1 + diff --git a/pkgs/by-name/ed/edopro/package.nix b/pkgs/by-name/ed/edopro/package.nix index ba6cc7c6ae76..b43b9d2d7bf7 100644 --- a/pkgs/by-name/ed/edopro/package.nix +++ b/pkgs/by-name/ed/edopro/package.nix @@ -27,6 +27,7 @@ libX11, libxkbcommon, libXxf86vm, + lua5_3, mono, nlohmann_json, openal, @@ -57,6 +58,14 @@ let ]; deps = import ./deps.nix; + + edopro-src = fetchFromGitHub { + owner = "edo9300"; + repo = "edopro"; + rev = deps.edopro-rev; + fetchSubmodules = true; + hash = deps.edopro-hash; + }; in let assets = fetchzip { @@ -107,16 +116,67 @@ let }; }; + ocgcore = stdenv.mkDerivation { + pname = "ocgcore-edopro"; + version = deps.edopro-version; + + src = edopro-src; + sourceRoot = "${edopro-src.name}/ocgcore"; + + patches = [ + # Fix linking against our Lua (different name mangling, C in Lua vs C++ in ocgcore) + ./ocgcore-lua-symbols.patch + ]; + + nativeBuildInputs = [ + premake5 + ]; + + # Drop when edopro version >= 41 + buildInputs = [ lua5_3 ]; + preBuild = '' + premake5 gmake2 \ + --lua-path="${lua5_3}" + ''; + + enableParallelBuilding = true; + + buildFlags = [ + "verbose=true" + "config=release" + "ocgcoreshared" + ]; + + makeFlags = [ + "-C" + "build" + ]; + + # To make sure linking errors are discovered at build time, not when edopro runs into them during loading + env.NIX_LDFLAGS = "--unresolved-symbols=report-all"; + + installPhase = '' + runHook preInstall + + install -Dm644 -t $out/lib bin/release/libocgcore*${stdenv.hostPlatform.extensions.sharedLibrary} + + runHook postInstall + ''; + + meta = { + description = "YGOPro script engine"; + homepage = "https://github.com/edo9300/ygopro-core"; + license = lib.licenses.agpl3Plus; + inherit maintainers; + platforms = lib.platforms.unix; + }; + }; + edopro = stdenv.mkDerivation { pname = "edopro"; version = deps.edopro-version; - src = fetchFromGitHub { - owner = "edo9300"; - repo = "edopro"; - rev = deps.edopro-rev; - hash = deps.edopro-hash; - }; + src = edopro-src; nativeBuildInputs = [ makeWrapper @@ -150,10 +210,15 @@ let ]; # nixpkgs' gcc stack currently appears to not support LTO + # Override where bundled ocgcore get looked up in, so we can supply ours + # (can't use --prebuilt-core or let it build a core on its own without making core updates impossible) postPatch = '' substituteInPlace premake5.lua \ --replace-fail 'flags "LinkTimeOptimization"' 'removeflags "LinkTimeOptimization"' + substituteInPlace gframe/game.cpp \ + --replace-fail 'ocgcore = LoadOCGcore(Utils::GetWorkingDirectory())' 'ocgcore = LoadOCGcore("${lib.getLib ocgcore}/lib/")' + touch ocgcore/premake5.lua ''; diff --git a/pkgs/by-name/ed/edopro/update.py b/pkgs/by-name/ed/edopro/update.py index 5e0efed21ddc..f582fe6a9d89 100755 --- a/pkgs/by-name/ed/edopro/update.py +++ b/pkgs/by-name/ed/edopro/update.py @@ -53,7 +53,7 @@ def get_hash(owner: str, repo: str, rev: str, submodule: bool = False) -> str: return out_json["hash"] -edopro_hash = get_hash("edo9300", "edopro", edopro.commit.sha) +edopro_hash = get_hash("edo9300", "edopro", edopro.commit.sha, submodule=True) irrlicht_hash = get_hash("edo9300", "irrlicht1-8-4", irrlicht.sha) asset_legacy_hash: str = ( From f93ca760ca989be50e4f9fb89a7f489dc326820d Mon Sep 17 00:00:00 2001 From: OPNA2608 Date: Thu, 24 Apr 2025 17:34:08 +0200 Subject: [PATCH 3/4] edopro: Use writeShellApplication for launcher script, keep assets in subdirs - Use WriteShellApplication for the launcher script, since that provides some good default shell options and runs shellcheck on the code - Fix any issues reported by shellcheck - Keep assets in subdirs with corresponding edopro version Since some of the assets tell the game which game scripts to download, where to look for them, and which servers to look at for online play, and managing this across versions could be messy - Check for multiple subdirs and issue warning about migrating data Let's not try to solve this ourselves, the user will know best if, and what, they care about when switching between versions --- pkgs/by-name/ed/edopro/package.nix | 68 ++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/pkgs/by-name/ed/edopro/package.nix b/pkgs/by-name/ed/edopro/package.nix index b43b9d2d7bf7..7060714e6177 100644 --- a/pkgs/by-name/ed/edopro/package.nix +++ b/pkgs/by-name/ed/edopro/package.nix @@ -6,12 +6,14 @@ fetchzip, makeWrapper, premake5, - writeShellScriptBin, + writeShellApplication, runCommandLocal, symlinkJoin, + writeText, imagemagick, bzip2, curl, + envsubst, flac, # Use fmt 10+ after release 40.1.4+ fmt_9, @@ -35,6 +37,7 @@ sqlite, wayland, egl-wayland, + zenity, covers_url ? "https://pics.projectignis.org:2096/pics/cover/{}.jpg", fields_url ? "https://pics.projectignis.org:2096/pics/field/{}.png", # While ygoprodeck has higher quality images, "spamming" of their api results in a ban. @@ -309,21 +312,62 @@ let "textures" "WindBot" ]; + wrapperZenityMessageTemplate = writeText "edopro-wrapper-multiple-versions-message.txt.in" '' + Nixpkgs' EDOPro wrapper has found more than 1 directory in: ''${EDOPRO_BASE_DIR} + + We expected the only directory to be: ''${EDOPRO_DIR} + + There may have been an update, requiring you to migrate any files you care about from an older version. + + Examples include: + + - decks/* + - config/system.conf - which has your client's settings + - any custom things you may have installed into: fonts, skins, script, sound, ... + - anything you wish to preserve from: replay, screenshots + + Once you have copied over everything important to ''${EDOPRO_DIR}, delete the old version's path. + ''; in - writeShellScriptBin "edopro" '' - set -eu - EDOPRO_DIR="''${XDG_DATA_HOME:-$HOME/.local/share}/edopro" + writeShellApplication { + name = "edopro"; + runtimeInputs = [ + envsubst + zenity + ]; + text = '' + export EDOPRO_VERSION="${deps.edopro-version}" + export EDOPRO_BASE_DIR="''${XDG_DATA_HOME:-$HOME/.local/share}/edopro" + export EDOPRO_DIR="''${EDOPRO_BASE_DIR}/''${EDOPRO_VERSION}" - if [ ! -d $EDOPRO_DIR ]; then - mkdir -p $EDOPRO_DIR - cp -r --no-preserve=all ${assets}/{${assetsToCopy}} $EDOPRO_DIR - chmod -R go-rwx $EDOPRO_DIR + # If versioned directory doesn't exist yet, make it & copy over assets + if [ ! -d "$EDOPRO_DIR" ]; then + mkdir -p "$EDOPRO_DIR" + cp -r --no-preserve=all ${assets}/{${assetsToCopy}} "$EDOPRO_DIR" + chmod -R go-rwx "$EDOPRO_DIR" - rm $EDOPRO_DIR/config/io.github.edo9300.EDOPro.desktop.in - fi + rm "$EDOPRO_DIR"/config/io.github.edo9300.EDOPro.desktop.in + fi - exec ${lib.getExe edopro} -C $EDOPRO_DIR $@ - ''; + # Different versions provide different assets. Some are necessary for the game to run properly (configs for + # where to get incremental updates from, online servers, card scripting, certificates for communication etc), + # and some are optional nice-haves (example decks). It's also possible to override assets with custom skins. + # + # Don't try to manage all of this across versions, just inform the user that they may need to migrate their + # files if it looks like there are multiple versions. + + edoproTopDirs="$(find "$EDOPRO_BASE_DIR" -mindepth 1 -maxdepth 1 -type d | wc -l)" + if [ "$edoproTopDirs" -ne 1 ]; then + zenity \ + --info \ + --title='[NIX] Multiple asset copies found' \ + --text="$(envsubst < ${wrapperZenityMessageTemplate})" \ + --ok-label='Continue to EDOPro' + fi + + exec ${lib.getExe edopro} -C "$EDOPRO_DIR" "$@" + ''; + }; edopro-desktop = runCommandLocal "io.github.edo9300.EDOPro.desktop" { } '' mkdir -p $out/share/applications From 160d74ddfba4ff8f77023f5f10f400174c707b99 Mon Sep 17 00:00:00 2001 From: OPNA2608 Date: Mon, 28 Apr 2025 23:37:46 +0200 Subject: [PATCH 4/4] edopro: 40.1.4 -> 41.0.2 - Rename ocgcore library to match expected platform-specific name --- pkgs/by-name/ed/edopro/deps.nix | 14 ++-- pkgs/by-name/ed/edopro/package.nix | 119 +++++++++++++++-------------- 2 files changed, 69 insertions(+), 64 deletions(-) diff --git a/pkgs/by-name/ed/edopro/deps.nix b/pkgs/by-name/ed/edopro/deps.nix index 0a6ac49aca3c..14535d8f4634 100644 --- a/pkgs/by-name/ed/edopro/deps.nix +++ b/pkgs/by-name/ed/edopro/deps.nix @@ -1,11 +1,11 @@ # This is automatically generated by the update script. # DO NOT MANUALLY EDIT. { - assets-hash = "sha256-vZhkWJ1ZoNEwdc5kM1S0hyXnWmupiTOanCi9DCuqw/k="; - edopro-version = "40.1.4"; - edopro-rev = "c713e23491a1e55c9d8e91257e5f2b5873696b9b"; - edopro-hash = "sha256-2E1cjG0FONu/fbr67/3qRCKQ1W/wPznClEWsMa1FAzo="; - irrlicht-version = "1.9.0-unstable-2023-02-18"; - irrlicht-rev = "7edde28d4f8c0c3589934c398a3a441286bb7c22"; - irrlicht-hash = "sha256-Q2tNiYE/enZPqA5YhUe+Tkvmqtmmz2E0OqTRUDnt+UA="; + assets-hash = "sha256-cta4k6yxrdaFFfum0eshEzLODExBfA+oVPqcOpXG9uk="; + edopro-version = "41.0.2"; + edopro-rev = "e5c0578aa504d0831dcbe29dbacd018f7b885b2c"; + edopro-hash = "sha256-ZkQXWt73S3Nn+RnkG+e91BId7keI5OpM3NSeDMJWlZY="; + irrlicht-version = "1.9.0-unstable-2025-03-30"; + irrlicht-rev = "47264fc2bc3223d110c589c9ffe4339d696a3dd0"; + irrlicht-hash = "sha256-AwUCHQOivNgSnYe8kG6JxDIz7H5PC6RoozGiOGUejTI="; } diff --git a/pkgs/by-name/ed/edopro/package.nix b/pkgs/by-name/ed/edopro/package.nix index 7060714e6177..a19f90aed995 100644 --- a/pkgs/by-name/ed/edopro/package.nix +++ b/pkgs/by-name/ed/edopro/package.nix @@ -2,7 +2,6 @@ lib, stdenv, fetchFromGitHub, - fetchpatch, fetchzip, makeWrapper, premake5, @@ -15,8 +14,7 @@ curl, envsubst, flac, - # Use fmt 10+ after release 40.1.4+ - fmt_9, + fmt, freetype, irrlicht, libevent, @@ -29,7 +27,6 @@ libX11, libxkbcommon, libXxf86vm, - lua5_3, mono, nlohmann_json, openal, @@ -119,61 +116,77 @@ let }; }; - ocgcore = stdenv.mkDerivation { - pname = "ocgcore-edopro"; - version = deps.edopro-version; + ocgcore = + let + # Refer to CORENAME EPRO_TEXT in /gframe/dllinterface.cpp for this + ocgcoreName = lib.strings.concatStrings [ + (lib.optionalString (!stdenv.hostPlatform.isWindows) "lib") + "ocgcore" + ( + if stdenv.hostPlatform.isiOS then + "-ios" + else if stdenv.hostPlatform.isAndroid then + ( + if stdenv.hostPlatform.isx86_64 then + "x64" + else if stdenv.hostPlatform.isx86_32 then + "x86" + else if stdenv.hostPlatform.isAarch64 then + "v8" + else if stdenv.hostPlatform.isAarch32 then + "v7" + else + throw "Don't know what platform suffix edopro expects for ocgcore on: ${stdenv.hostPlatform.system}" + ) + else + lib.optionalString (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) ".aarch64" + ) + stdenv.hostPlatform.extensions.sharedLibrary + ]; + in + stdenv.mkDerivation { + pname = "ocgcore-edopro"; + version = deps.edopro-version; - src = edopro-src; - sourceRoot = "${edopro-src.name}/ocgcore"; + src = edopro-src; + sourceRoot = "${edopro-src.name}/ocgcore"; - patches = [ - # Fix linking against our Lua (different name mangling, C in Lua vs C++ in ocgcore) - ./ocgcore-lua-symbols.patch - ]; + nativeBuildInputs = [ + premake5 + ]; - nativeBuildInputs = [ - premake5 - ]; + enableParallelBuilding = true; - # Drop when edopro version >= 41 - buildInputs = [ lua5_3 ]; - preBuild = '' - premake5 gmake2 \ - --lua-path="${lua5_3}" - ''; + buildFlags = [ + "verbose=true" + "config=release" + "ocgcoreshared" + ]; - enableParallelBuilding = true; + makeFlags = [ + "-C" + "build" + ]; - buildFlags = [ - "verbose=true" - "config=release" - "ocgcoreshared" - ]; + # To make sure linking errors are discovered at build time, not when edopro runs into them during loading + env.NIX_LDFLAGS = "--unresolved-symbols=report-all"; - makeFlags = [ - "-C" - "build" - ]; + installPhase = '' + runHook preInstall - # To make sure linking errors are discovered at build time, not when edopro runs into them during loading - env.NIX_LDFLAGS = "--unresolved-symbols=report-all"; + install -Dm644 bin/release/*ocgcore*${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/${ocgcoreName} - installPhase = '' - runHook preInstall + runHook postInstall + ''; - install -Dm644 -t $out/lib bin/release/libocgcore*${stdenv.hostPlatform.extensions.sharedLibrary} - - runHook postInstall - ''; - - meta = { - description = "YGOPro script engine"; - homepage = "https://github.com/edo9300/ygopro-core"; - license = lib.licenses.agpl3Plus; - inherit maintainers; - platforms = lib.platforms.unix; + meta = { + description = "YGOPro script engine"; + homepage = "https://github.com/edo9300/ygopro-core"; + license = lib.licenses.agpl3Plus; + inherit maintainers; + platforms = lib.platforms.unix; + }; }; - }; edopro = stdenv.mkDerivation { pname = "edopro"; @@ -190,7 +203,7 @@ let bzip2 curl flac - fmt_9 + fmt freetype irrlicht-edopro libevent @@ -204,14 +217,6 @@ let sqlite ]; - patches = [ - (fetchpatch { - name = "libgit2-version.patch"; - url = "https://github.com/edo9300/edopro/commit/f8ddbfff51231827a8dd1dcfcb2dda85f50a56d9.patch"; - hash = "sha256-w9VTmWfw6vEyVvsOH+AK9lAbUOV+MagzGQ3Wa5DCS/U="; - }) - ]; - # nixpkgs' gcc stack currently appears to not support LTO # Override where bundled ocgcore get looked up in, so we can supply ours # (can't use --prebuilt-core or let it build a core on its own without making core updates impossible)