1# Generic builder for shattered pixel forks/mods
2{
3 pname,
4 version,
5 src,
6 meta,
7 desktopName,
8 patches ? [ ./disable-beryx.patch ],
9 depsPath ? null,
10
11 lib,
12 stdenv,
13 makeWrapper,
14 gradle_8,
15 perl,
16 jre,
17 libGL,
18 libpulseaudio,
19 makeDesktopItem,
20 copyDesktopItems,
21 ...
22}@attrs:
23
24let
25 cleanAttrs = builtins.removeAttrs attrs [
26 "lib"
27 "stdenv"
28 "makeWrapper"
29 "gradle"
30 "perl"
31 "jre"
32 "libpulseaudio"
33 "makeDesktopItem"
34 "copyDesktopItems"
35 ];
36
37 postPatch = ''
38 # disable gradle plugins with native code and their targets
39 perl -i.bak1 -pe "s#(^\s*id '.+' version '.+'$)#// \1#" build.gradle
40 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
41 # Remove unbuildable Android/iOS stuff
42 rm -f android/build.gradle ios/build.gradle
43 ${attrs.postPatch or ""}
44 '';
45
46 desktopItem = makeDesktopItem {
47 name = pname;
48 inherit desktopName;
49 comment = meta.description;
50 icon = pname;
51 exec = pname;
52 terminal = false;
53 categories = [
54 "Game"
55 "AdventureGame"
56 ];
57 keywords = [
58 "roguelike"
59 "dungeon"
60 "crawler"
61 ];
62 };
63
64 depsPath' = if depsPath != null then depsPath else ./. + "/${pname}/deps.json";
65
66 # "Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0."
67 gradle = gradle_8;
68
69in
70stdenv.mkDerivation (
71 cleanAttrs
72 // {
73 inherit
74 pname
75 version
76 src
77 patches
78 postPatch
79 ;
80
81 mitmCache = gradle.fetchDeps {
82 inherit pname;
83 data = depsPath';
84 };
85
86 __darwinAllowLocalNetworking = true;
87
88 nativeBuildInputs = [
89 gradle
90 perl
91 makeWrapper
92 copyDesktopItems
93 ]
94 ++ attrs.nativeBuildInputs or [ ];
95
96 desktopItems = [ desktopItem ];
97
98 gradleBuildTask = "desktop:release";
99
100 installPhase = ''
101 runHook preInstall
102
103 install -Dm644 desktop/build/libs/desktop-*.jar $out/share/${pname}.jar
104 mkdir $out/bin
105 makeWrapper ${jre}/bin/java $out/bin/${pname} \
106 --prefix LD_LIBRARY_PATH : ${
107 lib.makeLibraryPath [
108 libGL
109 libpulseaudio
110 ]
111 } \
112 --add-flags "-jar $out/share/${pname}.jar"
113
114 for s in 16 32 48 64 128 256; do
115 # Some forks only have some icons and/or name them slightly differently
116 if [ -f desktop/src/main/assets/icons/icon_$s.png ]; then
117 install -Dm644 desktop/src/main/assets/icons/icon_$s.png \
118 $out/share/icons/hicolor/''${s}x$s/apps/${pname}.png
119 fi
120 if [ -f desktop/src/main/assets/icons/icon_''${s}x$s.png ]; then
121 install -Dm644 desktop/src/main/assets/icons/icon_''${s}x$s.png \
122 $out/share/icons/hicolor/''${s}x$s/apps/${pname}.png
123 fi
124 done
125
126 runHook postInstall
127 '';
128
129 meta =
130 with lib;
131 {
132 sourceProvenance = with sourceTypes; [
133 fromSource
134 binaryBytecode # deps
135 ];
136 license = licenses.gpl3Plus;
137 maintainers = with maintainers; [ fgaz ];
138 platforms = platforms.all;
139 mainProgram = pname;
140 }
141 // meta;
142 }
143)