space-cadet-pinball: improve packaging

* Fix the build on Darwin
* Build an app bundle like the upstream releases
* Make the game find its assets without a wrapper and install them in
  the appropriate location
This commit is contained in:
Nadia Holmquist Pedersen 2024-11-08 18:34:08 +01:00
parent eadef8f486
commit 5ebcfc742d
2 changed files with 42 additions and 36 deletions

View File

@ -6,21 +6,19 @@
cmake, cmake,
SDL2, SDL2,
SDL2_mixer, SDL2_mixer,
Cocoa, unrar,
unrar-wrapper,
makeWrapper,
}: }:
let let
assets = assets = fetchzip {
(fetchzip { url = "https://archive.org/download/SpaceCadet_Plus95/Space_Cadet.rar";
url = "https://archive.org/download/SpaceCadet_Plus95/Space_Cadet.rar"; hash = "sha256-fC+zsR8BY6vXpUkVd6i1jF0IZZxVKVvNi6VWCKT+pA4=";
sha256 = "sha256-fC+zsR8BY6vXpUkVd6i1jF0IZZxVKVvNi6VWCKT+pA4="; stripRoot = false;
stripRoot = false; nativeBuildInputs = [ unrar ];
}).overrideAttrs };
(old: { darwinApp = "$out/Applications/SpaceCadetPinball.app/Contents";
nativeBuildInputs = old.nativeBuildInputs ++ [ unrar-wrapper ]; assetsDest =
}); if stdenv.hostPlatform.isDarwin then darwinApp + "/Resources" else "$out/share/SpaceCadetPinball";
in in
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
pname = "SpaceCadetPinball"; pname = "SpaceCadetPinball";
@ -28,49 +26,61 @@ stdenv.mkDerivation rec {
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "k4zmu2a"; owner = "k4zmu2a";
repo = pname; repo = "SpaceCadetPinball";
rev = "Release_${version}"; rev = "Release_${version}";
hash = "sha256-W2P7Txv3RtmKhQ5c0+b4ghf+OMsN+ydUZt+6tB+LClM="; hash = "sha256-W2P7Txv3RtmKhQ5c0+b4ghf+OMsN+ydUZt+6tB+LClM=";
}; };
nativeBuildInputs = [ nativeBuildInputs = [ cmake ];
cmake
makeWrapper
];
buildInputs = [ buildInputs = [
SDL2 SDL2
SDL2_mixer SDL2_mixer
] ++ lib.optional stdenv.hostPlatform.isDarwin Cocoa; ];
# Darwin needs a custom installphase since it is excluded from the cmake install postPatch = ''
# Change the hardcoded FHS assets path
substituteInPlace SpaceCadetPinball/pch.h \
--replace-fail /usr/share ${placeholder "out"}/share
# Disable building a universal binary on Darwin, otherwise the cc wrapper passing -arch breaks the build
substituteInPlace CMakeLists.txt \
--replace-fail "arm64;x86_64" ""
'';
# Darwin needs a custom installPhase since it is excluded from the cmake install
# https://github.com/k4zmu2a/SpaceCadetPinball/blob/0f88e43ba261bc21fa5c3ef9d44969a2a079d0de/CMakeLists.txt#L221 # https://github.com/k4zmu2a/SpaceCadetPinball/blob/0f88e43ba261bc21fa5c3ef9d44969a2a079d0de/CMakeLists.txt#L221
# This builds a bundle similar to what upstream's build script produces
# https://github.com/k4zmu2a/SpaceCadetPinball/blob/cb9b7b886244a27773f66b0b19fdc2998392565e/build-mac-app.sh
installPhase = lib.optionalString stdenv.hostPlatform.isDarwin '' installPhase = lib.optionalString stdenv.hostPlatform.isDarwin ''
runHook preInstall runHook preInstall
mkdir -p $out/bin install -D ../bin/SpaceCadetPinball -t ${darwinApp}/MacOS
install ../bin/SpaceCadetPinball $out/bin install -Dm644 ../Platform/macOS/SpaceCadetPinball.icns -t ${darwinApp}/Resources
substitute ../Platform/macOS/Info.plist ${darwinApp}/Info.plist \
--replace-fail CHANGEME_SW_VERSION ${version}
echo -n "APPL????" > ${darwinApp}/PkgInfo
runHook postInstall runHook postInstall
''; '';
# The game uses SDL_GetBasePath to find the assets directory.
# On Darwin, this will return Resources/ inside the bundle,
# on other platforms, the fallback path the game checks is used instead.
postInstall = '' postInstall = ''
mkdir -p $out/lib/SpaceCadetPinball install -Dm644 ${assets}/*.{DAT,DOC,MID,BMP,INF} \
install ${assets}/*.{DAT,DOC,MID,BMP,INF} ${assets}/Sounds/*.WAV $out/lib/SpaceCadetPinball ${assets}/Sounds/*.WAV -t ${assetsDest}
# Assets are loaded from the directory of the program is stored in
# https://github.com/k4zmu2a/SpaceCadetPinball/blob/de13d4e326b2dfa8e6dfb59815c0a8b9657f942d/SpaceCadetPinball/winmain.cpp#L119
mv $out/bin/SpaceCadetPinball $out/lib/SpaceCadetPinball
makeWrapper $out/lib/SpaceCadetPinball/SpaceCadetPinball $out/bin/SpaceCadetPinball
''; '';
meta = with lib; { meta = {
description = "Reverse engineering of 3D Pinball for Windows Space Cadet, a game bundled with Windows"; description = "Reverse engineering of 3D Pinball for Windows Space Cadet, a game bundled with Windows";
homepage = "https://github.com/k4zmu2a/SpaceCadetPinball"; homepage = "https://github.com/k4zmu2a/SpaceCadetPinball";
# The assets are unfree while the code is labeled as MIT # The assets are unfree while the code is labeled as MIT
license = with licenses; [ license = with lib.licenses; [
unfree unfree
mit mit
]; ];
maintainers = [ maintainers.hqurve ]; maintainers = with lib.maintainers; [
platforms = platforms.all; hqurve
nadiaholmquist
];
platforms = lib.platforms.all;
mainProgram = "SpaceCadetPinball"; mainProgram = "SpaceCadetPinball";
}; };
} }

View File

@ -17347,10 +17347,6 @@ with pkgs;
buildShareware = true; buildShareware = true;
}; };
space-cadet-pinball = callPackage ../by-name/sp/space-cadet-pinball/package.nix {
inherit (darwin.apple_sdk.frameworks) Cocoa;
};
starsector = callPackage ../games/starsector { starsector = callPackage ../games/starsector {
openjdk = openjdk8; openjdk = openjdk8;
}; };