nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 fetchFromGitHub,
4 applyPatches,
5 _2ship2harkinian,
6 fetchurl,
7 writeTextFile,
8 stdenv,
9 cmake,
10 copyDesktopItems,
11 imagemagick,
12 lsb-release,
13 makeWrapper,
14 ninja,
15 pkg-config,
16 python3,
17 libGL,
18 libpng,
19 libpulseaudio,
20 libzip,
21 nlohmann_json,
22 SDL2,
23 spdlog,
24 tinyxml-2,
25 zenity,
26 bzip2,
27 libogg,
28 libopus,
29 libvorbis,
30 libX11,
31 opusfile,
32 sdl_gamecontrollerdb,
33 makeDesktopItem,
34}:
35
36let
37
38 # The following are either normally fetched during build time or a specific version is required
39
40 dr_libs = fetchFromGitHub {
41 owner = "mackron";
42 repo = "dr_libs";
43 rev = "da35f9d6c7374a95353fd1df1d394d44ab66cf01";
44 hash = "sha256-ydFhQ8LTYDBnRTuETtfWwIHZpRciWfqGsZC6SuViEn0=";
45 };
46
47 imgui' = applyPatches {
48 src = fetchFromGitHub {
49 owner = "ocornut";
50 repo = "imgui";
51 tag = "v1.91.9b-docking";
52 hash = "sha256-mQOJ6jCN+7VopgZ61yzaCnt4R1QLrW7+47xxMhFRHLQ=";
53 };
54 patches = [
55 "${_2ship2harkinian.src}/libultraship/cmake/dependencies/patches/imgui-fixes-and-config.patch"
56 ];
57 };
58
59 libgfxd = fetchFromGitHub {
60 owner = "glankk";
61 repo = "libgfxd";
62 rev = "008f73dca8ebc9151b205959b17773a19c5bd0da";
63 hash = "sha256-AmHAa3/cQdh7KAMFOtz5TQpcM6FqO9SppmDpKPTjTt8=";
64 };
65
66 prism = fetchFromGitHub {
67 owner = "KiritoDv";
68 repo = "prism-processor";
69 rev = "bbcbc7e3f890a5806b579361e7aa0336acd547e7";
70 hash = "sha256-jRPwO1Vub0cH12YMlME6kd8zGzKmcfIrIJZYpQJeOks=";
71 };
72
73 stb_impl = writeTextFile {
74 name = "stb_impl.c";
75 text = ''
76 #define STB_IMAGE_IMPLEMENTATION
77 #include "stb_image.h"
78 '';
79 };
80
81 stb' = fetchurl {
82 name = "stb_image.h";
83 url = "https://raw.githubusercontent.com/nothings/stb/0bc88af4de5fb022db643c2d8e549a0927749354/stb_image.h";
84 hash = "sha256-xUsVponmofMsdeLsI6+kQuPg436JS3PBl00IZ5sg3Vw=";
85 };
86
87 stormlib' = applyPatches {
88 src = fetchFromGitHub {
89 owner = "ladislav-zezula";
90 repo = "StormLib";
91 tag = "v9.25";
92 hash = "sha256-HTi2FKzKCbRaP13XERUmHkJgw8IfKaRJvsK3+YxFFdc=";
93 };
94 patches = [
95 "${_2ship2harkinian.src}/libultraship/cmake/dependencies/patches/stormlib-optimizations.patch"
96 ];
97 };
98
99 thread_pool = fetchFromGitHub {
100 owner = "bshoshany";
101 repo = "thread-pool";
102 tag = "v4.1.0";
103 hash = "sha256-zhRFEmPYNFLqQCfvdAaG5VBNle9Qm8FepIIIrT9sh88=";
104 };
105
106in
107stdenv.mkDerivation (finalAttrs: {
108 pname = "2ship2harkinian";
109 version = "4.0.0";
110
111 src = fetchFromGitHub {
112 owner = "HarbourMasters";
113 repo = "2ship2harkinian";
114 tag = finalAttrs.version;
115 hash = "sha256-fG9HIJChPGngb8vouLsQTo9xQXBq6qIZn7oyYssvNhI=";
116 fetchSubmodules = true;
117 deepClone = true;
118 postFetch = ''
119 cd $out
120 git branch --show-current > GIT_BRANCH
121 git rev-parse --short=7 HEAD > GIT_COMMIT_HASH
122 (git describe --tags --abbrev=0 --exact-match HEAD 2>/dev/null || echo "") > GIT_COMMIT_TAG
123 rm -rf .git
124 '';
125 };
126
127 patches = [
128 # remove fetching stb as we will patch our own
129 ./dont-fetch-stb.patch
130 ];
131
132 nativeBuildInputs = [
133 cmake
134 copyDesktopItems
135 imagemagick
136 lsb-release
137 makeWrapper
138 ninja
139 pkg-config
140 python3
141 ];
142
143 buildInputs = [
144 bzip2
145 libGL
146 libogg
147 (lib.getDev libopus)
148 libpng
149 libpulseaudio
150 libvorbis
151 libX11
152 libzip
153 nlohmann_json
154 (lib.getDev opusfile)
155 SDL2
156 spdlog
157 tinyxml-2
158 zenity
159 ];
160
161 cmakeFlags = [
162 (lib.cmakeBool "NON_PORTABLE" true)
163 (lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}/2s2h")
164 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_DR_LIBS" "${dr_libs}")
165 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_IMGUI" "${imgui'}")
166 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_LIBGFXD" "${libgfxd}")
167 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_PRISM" "${prism}")
168 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_STORMLIB" "${stormlib'}")
169 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_THREADPOOL" "${thread_pool}")
170 (lib.cmakeFeature "OPUS_INCLUDE_DIR" "${lib.getDev libopus}/include/opus")
171 (lib.cmakeFeature "OPUSFILE_INCLUDE_DIR" "${lib.getDev opusfile}/include/opus")
172 ];
173
174 strictDeps = true;
175 __structuredAttrs = true;
176 enableParallelBuilding = true;
177
178 dontAddPrefix = true;
179
180 # Linking fails without this
181 hardeningDisable = [ "format" ];
182
183 preConfigure = ''
184 # mirror 2ship's stb
185 mkdir stb
186 cp ${stb'} ./stb/${stb'.name}
187 cp ${stb_impl} ./stb/${stb_impl.name}
188 substituteInPlace libultraship/cmake/dependencies/common.cmake \
189 --replace-fail "\''${STB_DIR}" "$(readlink -f ./stb)"
190 '';
191
192 postPatch = ''
193 substituteInPlace mm/src/boot/build.c.in \
194 --replace-fail "@CMAKE_PROJECT_GIT_BRANCH@" "$(cat GIT_BRANCH)" \
195 --replace-fail "@CMAKE_PROJECT_GIT_COMMIT_HASH@" "$(cat GIT_COMMIT_HASH)" \
196 --replace-fail "@CMAKE_PROJECT_GIT_COMMIT_TAG@" "$(cat GIT_COMMIT_TAG)"
197 '';
198
199 postBuild = ''
200 port_ver=$(grep CMAKE_PROJECT_VERSION: "$PWD/CMakeCache.txt" | cut -d= -f2)
201 cp ${sdl_gamecontrollerdb}/share/gamecontrollerdb.txt gamecontrollerdb.txt
202 pushd ../OTRExporter
203 python3 ./extract_assets.py -z ../build/ZAPD/ZAPD.out --norom --xml-root ../mm/assets/xml --custom-assets-path ../mm/assets/custom --custom-otr-file 2ship.o2r --port-ver $port_ver
204 popd
205 '';
206
207 preInstall = ''
208 # Cmake likes it here for its install paths
209 cp ../OTRExporter/2ship.o2r mm/
210 '';
211
212 postInstall = ''
213 mkdir -p $out/bin
214 ln -s $out/2s2h/2s2h.elf $out/bin/2s2h
215 install -Dm644 ../mm/linux/2s2hIcon.png $out/share/pixmaps/2s2h.png
216
217 install -Dm644 -t $out/share/licenses/2ship2harkinian ../LICENSE
218 install -Dm644 -t $out/share/licenses/2ship2harkinian/OTRExporter ../OTRExporter/LICENSE
219 install -Dm644 -t $out/share/licenses/2ship2harkinian/ZAPDTR ../ZAPDTR/LICENSE
220 install -Dm644 -t $out/share/licenses/2ship2harkinian/libgfxd ${libgfxd}/LICENSE
221 install -Dm644 -t $out/share/licenses/2ship2harkinian/libultraship ../libultraship/LICENSE
222 install -Dm644 -t $out/share/licenses/2ship2harkinian/thread_pool ${thread_pool}/LICENSE.txt
223 '';
224
225 postFixup = ''
226 wrapProgram $out/2s2h/2s2h.elf --prefix PATH ":" ${lib.makeBinPath [ zenity ]}
227 '';
228
229 desktopItems = [
230 (makeDesktopItem {
231 name = "2s2h";
232 icon = "2s2h";
233 exec = "2s2h";
234 comment = finalAttrs.meta.description;
235 genericName = "2 Ship 2 Harkinian";
236 desktopName = "2s2h";
237 categories = [ "Game" ];
238 })
239 ];
240
241 meta = {
242 homepage = "https://github.com/HarbourMasters/2ship2harkinian";
243 description = "PC port of Majora's Mask with modern controls, widescreen, high-resolution, and more";
244 mainProgram = "2s2h";
245 platforms = [ "x86_64-linux" ];
246 maintainers = with lib.maintainers; [ qubitnano ];
247 license = with lib.licenses; [
248 # OTRExporter, ZAPDTR, libultraship, libgfxd, thread_pool
249 mit
250 # 2 Ship 2 Harkinian
251 cc0
252 # Reverse engineering
253 unfree
254 ];
255 };
256})