Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / games / starsector / default.nix
blobe1bc4a8dbbcfec5d443b46ab9f915e117f482157
1 { lib
2 , fetchzip
3 , libXxf86vm
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.96a-RC10";
18   src = fetchzip {
19     url = "https://f005.backblazeb2.com/file/fractalsoftworks/release/starsector_linux-${version}.zip";
20     sha256 = "sha256-RBSnms+QlKgTOhm3t2hDfv7OcMrQCk1rfkz9GaM74WM=";
21   };
23   nativeBuildInputs = [ copyDesktopItems makeWrapper ];
24   buildInputs = [ xorg.libXxf86vm openal ];
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/graphics/ui/s_icon64.png $out/share/icons/hicolor/64x64/apps/starsector.png
52     wrapProgram $out/share/starsector/starsector.sh \
53       --prefix PATH : ${lib.makeBinPath [ openjdk ]} \
54       --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath buildInputs} \
55       --run 'mkdir -p ''${XDG_DATA_HOME:-~/.local/share}/starsector' \
56       --chdir "$out/share/starsector"
57     ln -s $out/share/starsector/starsector.sh $out/bin/starsector
59     runHook postInstall
60   '';
62   # it tries to run everything with relative paths, which makes it CWD dependent
63   # also point mod, screenshot, and save directory to $XDG_DATA_HOME
64   # additionally, add some GC options to improve performance of the game
65   postPatch = ''
66     substituteInPlace starsector.sh \
67       --replace "./jre_linux/bin/java" "${openjdk}/bin/java" \
68       --replace "./native/linux" "$out/share/starsector/native/linux" \
69       --replace "=." "=\''${XDG_DATA_HOME:-\$HOME/.local/share}/starsector" \
70       --replace "-XX:+CompilerThreadHintNoPreempt" "-XX:+UnlockDiagnosticVMOptions -XX:-BytecodeVerificationRemote -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSConcurrentMTEnabled -XX:+DisableExplicitGC"
71   '';
73   meta = with lib; {
74     description = "Open-world single-player space-combat, roleplaying, exploration, and economic game";
75     homepage = "https://fractalsoftworks.com";
76     sourceProvenance = with sourceTypes; [ binaryBytecode ];
77     license = licenses.unfree;
78     maintainers = with maintainers; [ bbigras ];
79   };
81   passthru.updateScript = writeScript "starsector-update-script" ''
82     #!/usr/bin/env nix-shell
83     #!nix-shell -i bash -p curl gnugrep common-updater-scripts
84     set -eou pipefail;
85     version=$(curl -s https://fractalsoftworks.com/preorder/ | grep -oP "https://f005.backblazeb2.com/file/fractalsoftworks/release/starsector_linux-\K.*?(?=\.zip)" | head -1)
86     update-source-version ${pname} "$version" --file=./pkgs/games/starsector/default.nix
87   '';