pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / games / starsector / default.nix
blob8e38f232f21e9f0e4bb97b116c39049c9bf4f9fb
1 { lib
2 , fetchzip
3 , libGL
4 , makeWrapper
5 , openal
6 , openjdk
7 , stdenv
8 , xorg
9 , copyDesktopItems
10 , makeDesktopItem
11 , writeScript
14 stdenv.mkDerivation rec {
15   pname = "starsector";
16   version = "0.97a-RC11";
18   src = fetchzip {
19     url = "https://f005.backblazeb2.com/file/fractalsoftworks/release/starsector_linux-${version}.zip";
20     sha256 = "sha256-KT4n0kBocaljD6dTbpr6xcwy6rBBZTFjov9m+jizDW4=";
21   };
23   nativeBuildInputs = [ copyDesktopItems makeWrapper ];
24   buildInputs = [ xorg.libXxf86vm openal libGL ];
26   dontBuild = true;
28   desktopItems = [
29     (makeDesktopItem {
30       name = "starsector";
31       exec = "starsector";
32       icon = "starsector";
33       comment = meta.description;
34       genericName = "starsector";
35       desktopName = "Starsector";
36       categories = [ "Game" ];
37     })
38   ];
40   # need to cd into $out in order for classpath to pick up correct jar files
41   installPhase = ''
42     runHook preInstall
44     mkdir -p $out/bin $out/share/starsector
45     rm -r jre_linux # remove bundled jre7
46     rm starfarer.api.zip
47     cp -r ./* $out/share/starsector
49     mkdir -p $out/share/icons/hicolor/64x64/apps
50     ln -s $out/share/starsector/graphics/ui/s_icon64.png \
51       $out/share/icons/hicolor/64x64/apps/starsector.png
53     wrapProgram $out/share/starsector/starsector.sh \
54       --prefix PATH : ${lib.makeBinPath [ openjdk xorg.xrandr ]} \
55       --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath buildInputs} \
56       --run 'mkdir -p ''${XDG_DATA_HOME:-~/.local/share}/starsector' \
57       --chdir "$out/share/starsector"
58     ln -s $out/share/starsector/starsector.sh $out/bin/starsector
60     runHook postInstall
61   '';
63   # it tries to run everything with relative paths, which makes it CWD dependent
64   # also point mod, screenshot, and save directory to $XDG_DATA_HOME
65   # additionally, add some GC options to improve performance of the game,
66   # remove flags "PermSize" and "MaxPermSize" that were removed with Java 8 and
67   # pass-through CLI args ($@) to the JVM.
68   postPatch = ''
69     substituteInPlace starsector.sh \
70       --replace-fail "./jre_linux/bin/java" "${openjdk}/bin/java" \
71       --replace-fail "./native/linux" "$out/share/starsector/native/linux" \
72       --replace-fail "=." "=\''${XDG_DATA_HOME:-\$HOME/.local/share}/starsector" \
73       --replace-fail "-XX:+CompilerThreadHintNoPreempt" "-XX:+UnlockDiagnosticVMOptions -XX:-BytecodeVerificationRemote -XX:+CMSConcurrentMTEnabled -XX:+DisableExplicitGC" \
74       --replace-quiet " -XX:PermSize=192m -XX:MaxPermSize=192m" "" \
75       --replace-fail "com.fs.starfarer.StarfarerLauncher" "\"\$@\" com.fs.starfarer.StarfarerLauncher"
76   '';
78   passthru.updateScript = writeScript "starsector-update-script" ''
79     #!/usr/bin/env nix-shell
80     #!nix-shell -i bash -p curl gnugrep common-updater-scripts
81     set -eou pipefail;
82     version=$(curl -s https://fractalsoftworks.com/preorder/ | grep -oP "https://f005.backblazeb2.com/file/fractalsoftworks/release/starsector_linux-\K.*?(?=\.zip)" | head -1)
83     update-source-version ${pname} "$version" --file=./pkgs/games/starsector/default.nix
84   '';
86   meta = with lib; {
87     description = "Open-world single-player space-combat, roleplaying, exploration, and economic game";
88     homepage = "https://fractalsoftworks.com";
89     sourceProvenance = with sourceTypes; [ binaryBytecode ];
90     license = licenses.unfree;
91     maintainers = with maintainers; [ bbigras rafaelrc ];
92   };