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,
SDL2,
SDL2_mixer,
Cocoa,
unrar-wrapper,
makeWrapper,
unrar,
}:
let
assets =
(fetchzip {
assets = fetchzip {
url = "https://archive.org/download/SpaceCadet_Plus95/Space_Cadet.rar";
sha256 = "sha256-fC+zsR8BY6vXpUkVd6i1jF0IZZxVKVvNi6VWCKT+pA4=";
hash = "sha256-fC+zsR8BY6vXpUkVd6i1jF0IZZxVKVvNi6VWCKT+pA4=";
stripRoot = false;
}).overrideAttrs
(old: {
nativeBuildInputs = old.nativeBuildInputs ++ [ unrar-wrapper ];
});
nativeBuildInputs = [ unrar ];
};
darwinApp = "$out/Applications/SpaceCadetPinball.app/Contents";
assetsDest =
if stdenv.hostPlatform.isDarwin then darwinApp + "/Resources" else "$out/share/SpaceCadetPinball";
in
stdenv.mkDerivation rec {
pname = "SpaceCadetPinball";
@ -28,49 +26,61 @@ stdenv.mkDerivation rec {
src = fetchFromGitHub {
owner = "k4zmu2a";
repo = pname;
repo = "SpaceCadetPinball";
rev = "Release_${version}";
hash = "sha256-W2P7Txv3RtmKhQ5c0+b4ghf+OMsN+ydUZt+6tB+LClM=";
};
nativeBuildInputs = [
cmake
makeWrapper
];
nativeBuildInputs = [ cmake ];
buildInputs = [
SDL2
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
# 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 ''
runHook preInstall
mkdir -p $out/bin
install ../bin/SpaceCadetPinball $out/bin
install -D ../bin/SpaceCadetPinball -t ${darwinApp}/MacOS
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
'';
# 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 = ''
mkdir -p $out/lib/SpaceCadetPinball
install ${assets}/*.{DAT,DOC,MID,BMP,INF} ${assets}/Sounds/*.WAV $out/lib/SpaceCadetPinball
# 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
install -Dm644 ${assets}/*.{DAT,DOC,MID,BMP,INF} \
${assets}/Sounds/*.WAV -t ${assetsDest}
'';
meta = with lib; {
meta = {
description = "Reverse engineering of 3D Pinball for Windows Space Cadet, a game bundled with Windows";
homepage = "https://github.com/k4zmu2a/SpaceCadetPinball";
# The assets are unfree while the code is labeled as MIT
license = with licenses; [
license = with lib.licenses; [
unfree
mit
];
maintainers = [ maintainers.hqurve ];
platforms = platforms.all;
maintainers = with lib.maintainers; [
hqurve
nadiaholmquist
];
platforms = lib.platforms.all;
mainProgram = "SpaceCadetPinball";
};
}

View File

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