|
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + fetchFromGitHub, |
| 5 | + fetchzip, |
| 6 | + cmake, |
| 7 | + SDL2, |
| 8 | + SDL2_mixer, |
| 9 | + unrar, |
| 10 | +}: |
| 11 | + |
| 12 | +let |
| 13 | + assets = fetchzip { |
| 14 | + url = "https://archive.org/download/SpaceCadet_Plus95/Space_Cadet.rar"; |
| 15 | + hash = "sha256-fC+zsR8BY6vXpUkVd6i1jF0IZZxVKVvNi6VWCKT+pA4="; |
| 16 | + stripRoot = false; |
| 17 | + nativeBuildInputs = [ unrar ]; |
| 18 | + }; |
| 19 | + darwinApp = "$out/Applications/SpaceCadetPinball.app/Contents"; |
| 20 | + assetsDest = |
| 21 | + if stdenv.hostPlatform.isDarwin then darwinApp + "/Resources" else "$out/share/SpaceCadetPinball"; |
| 22 | +in |
| 23 | +stdenv.mkDerivation rec { |
| 24 | + pname = "SpaceCadetPinball"; |
| 25 | + version = "2.1.0"; |
| 26 | + |
| 27 | + src = fetchFromGitHub { |
| 28 | + owner = "k4zmu2a"; |
| 29 | + repo = "SpaceCadetPinball"; |
| 30 | + rev = "Release_${version}"; |
| 31 | + hash = "sha256-W2P7Txv3RtmKhQ5c0+b4ghf+OMsN+ydUZt+6tB+LClM="; |
| 32 | + }; |
| 33 | + |
| 34 | + nativeBuildInputs = [ cmake ]; |
| 35 | + buildInputs = [ |
| 36 | + SDL2 |
| 37 | + SDL2_mixer |
| 38 | + ]; |
| 39 | + |
| 40 | + postPatch = '' |
| 41 | + # Change the hardcoded FHS assets path |
| 42 | + substituteInPlace SpaceCadetPinball/pch.h \ |
| 43 | + --replace-fail /usr/share ${placeholder "out"}/share |
| 44 | + # Disable building a universal binary on Darwin, otherwise the cc wrapper passing -arch breaks the build |
| 45 | + substituteInPlace CMakeLists.txt \ |
| 46 | + --replace-fail "arm64;x86_64" "" |
| 47 | + ''; |
| 48 | + |
| 49 | + # Darwin needs a custom installPhase since it is excluded from the cmake install |
| 50 | + # https://github.com/k4zmu2a/SpaceCadetPinball/blob/0f88e43ba261bc21fa5c3ef9d44969a2a079d0de/CMakeLists.txt#L221 |
| 51 | + # This builds a bundle similar to what upstream's build script produces |
| 52 | + # https://github.com/k4zmu2a/SpaceCadetPinball/blob/cb9b7b886244a27773f66b0b19fdc2998392565e/build-mac-app.sh |
| 53 | + installPhase = lib.optionalString stdenv.hostPlatform.isDarwin '' |
| 54 | + runHook preInstall |
| 55 | + install -D ../bin/SpaceCadetPinball -t ${darwinApp}/MacOS |
| 56 | + install -Dm644 ../Platform/macOS/SpaceCadetPinball.icns -t ${darwinApp}/Resources |
| 57 | + substitute ../Platform/macOS/Info.plist ${darwinApp}/Info.plist \ |
| 58 | + --replace-fail CHANGEME_SW_VERSION ${version} |
| 59 | + echo -n "APPL????" > ${darwinApp}/PkgInfo |
| 60 | + runHook postInstall |
| 61 | + ''; |
| 62 | + |
| 63 | + # The game uses SDL_GetBasePath to find the assets directory. |
| 64 | + # On Darwin, this will return Resources/ inside the bundle, |
| 65 | + # on other platforms, the fallback path the game checks is used instead. |
| 66 | + postInstall = '' |
| 67 | + install -Dm644 ${assets}/*.{DAT,DOC,MID,BMP,INF} \ |
| 68 | + ${assets}/Sounds/*.WAV -t ${assetsDest} |
| 69 | + ''; |
| 70 | + |
| 71 | + meta = { |
| 72 | + description = "Reverse engineering of 3D Pinball for Windows – Space Cadet, a game bundled with Windows"; |
| 73 | + homepage = "https://github.com/k4zmu2a/SpaceCadetPinball"; |
| 74 | + # The assets are unfree while the code is labeled as MIT |
| 75 | + license = with lib.licenses; [ |
| 76 | + unfree |
| 77 | + mit |
| 78 | + ]; |
| 79 | + maintainers = with lib.maintainers; [ |
| 80 | + hqurve |
| 81 | + nadiaholmquist |
| 82 | + ]; |
| 83 | + platforms = lib.platforms.all; |
| 84 | + mainProgram = "SpaceCadetPinball"; |
| 85 | + }; |
| 86 | +} |
0 commit comments