From a0891b0b7680f1d3741209848388a07ef70dd073 Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Sun, 27 Apr 2025 12:35:03 +0200 Subject: [PATCH] wesnoth: add darwin app bundle --- pkgs/games/wesnoth/default.nix | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/pkgs/games/wesnoth/default.nix b/pkgs/games/wesnoth/default.nix index 6f894432e572..80c16f190da7 100644 --- a/pkgs/games/wesnoth/default.nix +++ b/pkgs/games/wesnoth/default.nix @@ -1,6 +1,7 @@ { lib, stdenv, + stdenvNoCC, fetchFromGitHub, cmake, pkg-config, @@ -91,7 +92,34 @@ stdenv.mkDerivation rec { "-DENABLE_SYSTEM_LUA=ON" ]; - NIX_LDFLAGS = lib.optionalString stdenv.hostPlatform.isDarwin "-framework AppKit"; + postInstall = lib.optionalString stdenv.hostPlatform.isDarwin '' + app_name="The Battle for Wesnoth" + app_bundle="$out/Applications/$app_name.app" + app_contents="$app_bundle/Contents" + mkdir -p "$app_contents" + echo "APPL????" > "$app_contents/PkgInfo" + mv $out/bin "$app_contents/MacOS" + mv $out/share/wesnoth "$app_contents/Resources" + pushd ../projectfiles/Xcode + substitute Info.plist "$app_contents/Info.plist" \ + --replace-fail ''\'''${EXECUTABLE_NAME}' wesnoth \ + --replace-fail '$(PRODUCT_BUNDLE_IDENTIFIER)' org.wesnoth.Wesnoth \ + --replace-fail ''\'''${PRODUCT_NAME}' "$app_name" + cp -r Resources/SDLMain.nib "$app_contents/Resources/" + install -m0644 Resources/{container-migration.plist,icon.icns} "$app_contents/Resources" + popd + + # Make the game and dedicated server binary available for shell users + mkdir -p "$out/bin" + ln -s "$app_contents/MacOS/wesnothd" "$out/bin/wesnothd" + # Symlinking the game binary is unsifficient as it would be unable to + # find the bundle resources + cat << EOF > "$out/bin/wesnoth" + #!${stdenvNoCC.shell} + open -na "$app_bundle" --args "\$@" + EOF + chmod +x "$out/bin/wesnoth" + ''; meta = with lib; { description = "Battle for Wesnoth, a free, turn-based strategy game with a fantasy theme"; @@ -107,5 +135,6 @@ stdenv.mkDerivation rec { license = licenses.gpl2Plus; maintainers = with maintainers; [ abbradar ]; platforms = platforms.unix; + mainProgram = "wesnoth"; }; }