acr-cli: init at 0.14 (#359508)
[NixPkgs.git] / pkgs / games / shattered-pixel-dungeon / generic.nix
blob30d7f3f472601d457f2fd85b9e20b265af515d35
1 # Generic builder for shattered pixel forks/mods
2 { pname
3 , version
4 , src
5 , meta
6 , desktopName
7 , patches ? [ ./disable-beryx.patch ]
8 , depsPath ? null
10 , lib
11 , stdenv
12 , makeWrapper
13 , gradle_8
14 , perl
15 , jre
16 , libGL
17 , libpulseaudio
18 , makeDesktopItem
19 , copyDesktopItems
20 , ...
21 }@attrs:
23 let
24   cleanAttrs = builtins.removeAttrs attrs [
25     "lib"
26     "stdenv"
27     "makeWrapper"
28     "gradle"
29     "perl"
30     "jre"
31     "libpulseaudio"
32     "makeDesktopItem"
33     "copyDesktopItems"
34   ];
36   postPatch = ''
37     # disable gradle plugins with native code and their targets
38     perl -i.bak1 -pe "s#(^\s*id '.+' version '.+'$)#// \1#" build.gradle
39     perl -i.bak2 -pe "s#(.*)#// \1# if /^(buildscript|task portable|task nsis|task proguard|task tgz|task\(afterEclipseImport\)|launch4j|macAppBundle|buildRpm|buildDeb|shadowJar|robovm|git-version)/ ... /^}/" build.gradle
40     # Remove unbuildable Android/iOS stuff
41     rm -f android/build.gradle ios/build.gradle
42     ${attrs.postPatch or ""}
43   '';
45   desktopItem = makeDesktopItem {
46     name = pname;
47     inherit desktopName;
48     comment = meta.description;
49     icon = pname;
50     exec = pname;
51     terminal = false;
52     categories = [ "Game" "AdventureGame" ];
53     keywords = [ "roguelike" "dungeon" "crawler" ];
54   };
56   depsPath' = if depsPath != null then depsPath else ./. + "/${pname}/deps.json";
58   # "Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0."
59   gradle = gradle_8;
61 in stdenv.mkDerivation (cleanAttrs // {
62   inherit pname version src patches postPatch;
64   mitmCache = gradle.fetchDeps {
65     inherit pname;
66     data = depsPath';
67   };
69   __darwinAllowLocalNetworking = true;
71   nativeBuildInputs = [
72     gradle
73     perl
74     makeWrapper
75     copyDesktopItems
76   ] ++ attrs.nativeBuildInputs or [];
78   desktopItems = [ desktopItem ];
80   gradleBuildTask = "desktop:release";
82   installPhase = ''
83     runHook preInstall
85     install -Dm644 desktop/build/libs/desktop-*.jar $out/share/${pname}.jar
86     mkdir $out/bin
87     makeWrapper ${jre}/bin/java $out/bin/${pname} \
88       --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ libGL libpulseaudio ]} \
89       --add-flags "-jar $out/share/${pname}.jar"
91     for s in 16 32 48 64 128 256; do
92       # Some forks only have some icons and/or name them slightly differently
93       if [ -f desktop/src/main/assets/icons/icon_$s.png ]; then
94         install -Dm644 desktop/src/main/assets/icons/icon_$s.png \
95           $out/share/icons/hicolor/''${s}x$s/apps/${pname}.png
96       fi
97       if [ -f desktop/src/main/assets/icons/icon_''${s}x$s.png ]; then
98         install -Dm644 desktop/src/main/assets/icons/icon_''${s}x$s.png \
99           $out/share/icons/hicolor/''${s}x$s/apps/${pname}.png
100       fi
101     done
103     runHook postInstall
104   '';
106   meta = with lib; {
107     sourceProvenance = with sourceTypes; [
108       fromSource
109       binaryBytecode  # deps
110     ];
111     license = licenses.gpl3Plus;
112     maintainers = with maintainers; [ fgaz ];
113     platforms = platforms.all;
114     mainProgram = pname;
115   } // meta;