nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 299 lines 8.5 kB view raw
1{ 2 stdenv, 3 cmake, 4 lsb-release, 5 ninja, 6 lib, 7 fetchFromGitHub, 8 fetchurl, 9 copyDesktopItems, 10 makeDesktopItem, 11 python3, 12 glew, 13 boost, 14 SDL2, 15 SDL2_net, 16 pkg-config, 17 libpulseaudio, 18 libpng, 19 imagemagick, 20 zenity, 21 makeWrapper, 22 darwin, 23 libicns, 24 libzip, 25 nlohmann_json, 26 tinyxml-2, 27 spdlog, 28 writeTextFile, 29 fixDarwinDylibNames, 30 applyPatches, 31 shipwright, 32 libopus, 33 opusfile, 34 libogg, 35 libvorbis, 36 bzip2, 37 libX11, 38 sdl_gamecontrollerdb, 39}: 40 41let 42 43 # The following would normally get fetched at build time, or a specific version is required 44 45 dr_libs = fetchFromGitHub { 46 owner = "mackron"; 47 repo = "dr_libs"; 48 rev = "da35f9d6c7374a95353fd1df1d394d44ab66cf01"; 49 hash = "sha256-ydFhQ8LTYDBnRTuETtfWwIHZpRciWfqGsZC6SuViEn0="; 50 }; 51 52 imgui' = applyPatches { 53 src = fetchFromGitHub { 54 owner = "ocornut"; 55 repo = "imgui"; 56 tag = "v1.91.9b-docking"; 57 hash = "sha256-mQOJ6jCN+7VopgZ61yzaCnt4R1QLrW7+47xxMhFRHLQ="; 58 }; 59 patches = [ 60 "${shipwright.src}/libultraship/cmake/dependencies/patches/imgui-fixes-and-config.patch" 61 ]; 62 }; 63 64 libgfxd = fetchFromGitHub { 65 owner = "glankk"; 66 repo = "libgfxd"; 67 rev = "008f73dca8ebc9151b205959b17773a19c5bd0da"; 68 hash = "sha256-AmHAa3/cQdh7KAMFOtz5TQpcM6FqO9SppmDpKPTjTt8="; 69 }; 70 71 prism = fetchFromGitHub { 72 owner = "KiritoDv"; 73 repo = "prism-processor"; 74 rev = "bbcbc7e3f890a5806b579361e7aa0336acd547e7"; 75 hash = "sha256-jRPwO1Vub0cH12YMlME6kd8zGzKmcfIrIJZYpQJeOks="; 76 }; 77 78 stb_impl = writeTextFile { 79 name = "stb_impl.c"; 80 text = '' 81 #define STB_IMAGE_IMPLEMENTATION 82 #include "stb_image.h" 83 ''; 84 }; 85 86 stb' = fetchurl { 87 name = "stb_image.h"; 88 url = "https://raw.githubusercontent.com/nothings/stb/0bc88af4de5fb022db643c2d8e549a0927749354/stb_image.h"; 89 hash = "sha256-xUsVponmofMsdeLsI6+kQuPg436JS3PBl00IZ5sg3Vw="; 90 }; 91 92 stormlib' = applyPatches { 93 src = fetchFromGitHub { 94 owner = "ladislav-zezula"; 95 repo = "StormLib"; 96 tag = "v9.25"; 97 hash = "sha256-HTi2FKzKCbRaP13XERUmHkJgw8IfKaRJvsK3+YxFFdc="; 98 }; 99 patches = [ 100 "${shipwright.src}/libultraship/cmake/dependencies/patches/stormlib-optimizations.patch" 101 ]; 102 }; 103 104 thread_pool = fetchFromGitHub { 105 owner = "bshoshany"; 106 repo = "thread-pool"; 107 tag = "v4.1.0"; 108 hash = "sha256-zhRFEmPYNFLqQCfvdAaG5VBNle9Qm8FepIIIrT9sh88="; 109 }; 110 111 metalcpp = fetchFromGitHub { 112 owner = "briaguya-ai"; 113 repo = "single-header-metal-cpp"; 114 tag = "macOS13_iOS16"; 115 hash = "sha256-CSYIpmq478bla2xoPL/cGYKIWAeiORxyFFZr0+ixd7I"; 116 }; 117in 118stdenv.mkDerivation (finalAttrs: { 119 pname = "shipwright"; 120 version = "9.1.2"; 121 src = fetchFromGitHub { 122 owner = "harbourmasters"; 123 repo = "shipwright"; 124 tag = finalAttrs.version; 125 hash = "sha256-kFi5yo+CGH67NU7haDAbzWCURzsUYMlRzx66XGvh0a0="; 126 fetchSubmodules = true; 127 deepClone = true; 128 postFetch = '' 129 cd $out 130 git branch --show-current > GIT_BRANCH 131 git rev-parse --short=7 HEAD > GIT_COMMIT_HASH 132 (git describe --tags --abbrev=0 --exact-match HEAD 2>/dev/null || echo "") > GIT_COMMIT_TAG 133 rm -rf .git 134 ''; 135 }; 136 137 patches = [ 138 ./darwin-fixes.patch 139 ./disable-downloading-stb_image.patch 140 ]; 141 142 nativeBuildInputs = [ 143 cmake 144 ninja 145 pkg-config 146 python3 147 imagemagick 148 makeWrapper 149 ] 150 ++ lib.optionals stdenv.hostPlatform.isLinux [ 151 lsb-release 152 copyDesktopItems 153 ] 154 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 155 libicns 156 darwin.sigtool 157 fixDarwinDylibNames 158 ]; 159 160 buildInputs = [ 161 boost 162 glew 163 SDL2 164 SDL2_net 165 libpng 166 libzip 167 nlohmann_json 168 tinyxml-2 169 spdlog 170 (lib.getDev libopus) 171 (lib.getDev opusfile) 172 libogg 173 libvorbis 174 bzip2 175 libX11 176 ] 177 ++ lib.optionals stdenv.hostPlatform.isLinux [ 178 libpulseaudio 179 zenity 180 ]; 181 182 cmakeFlags = [ 183 (lib.cmakeBool "BUILD_REMOTE_CONTROL" true) 184 (lib.cmakeBool "NON_PORTABLE" true) 185 (lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}/lib") 186 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_DR_LIBS" "${dr_libs}") 187 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_IMGUI" "${imgui'}") 188 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_LIBGFXD" "${libgfxd}") 189 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_PRISM" "${prism}") 190 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_STORMLIB" "${stormlib'}") 191 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_THREADPOOL" "${thread_pool}") 192 (lib.cmakeFeature "OPUS_INCLUDE_DIR" "${lib.getDev libopus}/include/opus") 193 (lib.cmakeFeature "OPUSFILE_INCLUDE_DIR" "${lib.getDev opusfile}/include/opus") 194 ] 195 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 196 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_METALCPP" "${metalcpp}") 197 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_SPDLOG" "${spdlog}") 198 ]; 199 200 env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-Wno-int-conversion -Wno-implicit-int -Wno-elaborated-enum-base"; 201 202 strictDeps = true; 203 204 dontAddPrefix = true; 205 206 # Linking fails without this 207 hardeningDisable = [ "format" ]; 208 209 preConfigure = '' 210 mkdir stb 211 cp ${stb'} ./stb/${stb'.name} 212 cp ${stb_impl} ./stb/${stb_impl.name} 213 substituteInPlace libultraship/cmake/dependencies/common.cmake \ 214 --replace-fail "\''${STB_DIR}" "$(readlink -f ./stb)" 215 ''; 216 217 postPatch = '' 218 substituteInPlace soh/src/boot/build.c.in \ 219 --replace-fail "@CMAKE_PROJECT_GIT_BRANCH@" "$(cat GIT_BRANCH)" \ 220 --replace-fail "@CMAKE_PROJECT_GIT_COMMIT_HASH@" "$(cat GIT_COMMIT_HASH)" \ 221 --replace-fail "@CMAKE_PROJECT_GIT_COMMIT_TAG@" "$(cat GIT_COMMIT_TAG)" 222 ''; 223 224 postBuild = '' 225 port_ver=$(grep CMAKE_PROJECT_VERSION: "$PWD/CMakeCache.txt" | cut -d= -f2) 226 cp ${sdl_gamecontrollerdb}/share/gamecontrollerdb.txt gamecontrollerdb.txt 227 mv ../libultraship/src/fast/shaders ../soh/assets/custom 228 pushd ../OTRExporter 229 python3 ./extract_assets.py -z ../build/ZAPD/ZAPD.out --norom --xml-root ../soh/assets/xml --custom-assets-path ../soh/assets/custom --custom-otr-file soh.o2r --port-ver $port_ver 230 popd 231 ''; 232 233 preInstall = '' 234 # Cmake likes it here for its install paths 235 cp ../OTRExporter/soh.o2r soh/soh.o2r 236 ''; 237 238 postInstall = 239 lib.optionalString stdenv.hostPlatform.isLinux '' 240 mkdir -p $out/bin 241 ln -s $out/lib/soh.elf $out/bin/soh 242 install -Dm644 ../soh/macosx/sohIcon.png $out/share/pixmaps/soh.png 243 '' 244 + lib.optionalString stdenv.hostPlatform.isDarwin '' 245 # Recreate the macOS bundle (without using cpack) 246 # We mirror the structure of the bundle distributed by the project 247 248 mkdir -p $out/Applications/soh.app/Contents 249 cp $src/soh/macosx/Info.plist.in $out/Applications/soh.app/Contents/Info.plist 250 substituteInPlace $out/Applications/soh.app/Contents/Info.plist \ 251 --replace-fail "@CMAKE_PROJECT_VERSION@" "${finalAttrs.version}" 252 253 mv $out/MacOS $out/Applications/soh.app/Contents/MacOS 254 255 # "lib" contains all resources that are in "Resources" in the official bundle. 256 # We move them to the right place and symlink them back to $out/lib, 257 # as that's where the game expects them. 258 mv $out/Resources $out/Applications/soh.app/Contents/Resources 259 mv $out/lib/** $out/Applications/soh.app/Contents/Resources 260 rm -rf $out/lib 261 ln -s $out/Applications/soh.app/Contents/Resources $out/lib 262 263 # Copy icons 264 cp -r ../build/macosx/soh.icns $out/Applications/soh.app/Contents/Resources/soh.icns 265 266 # Codesign (ad-hoc) 267 codesign -f -s - $out/Applications/soh.app/Contents/MacOS/soh 268 ''; 269 270 fixupPhase = lib.optionalString stdenv.hostPlatform.isLinux '' 271 wrapProgram $out/lib/soh.elf --prefix PATH ":" ${lib.makeBinPath [ zenity ]} 272 ''; 273 274 desktopItems = [ 275 (makeDesktopItem { 276 name = "soh"; 277 icon = "soh"; 278 exec = "soh"; 279 comment = finalAttrs.meta.description; 280 genericName = "Ship of Harkinian"; 281 desktopName = "soh"; 282 categories = [ "Game" ]; 283 }) 284 ]; 285 286 meta = { 287 homepage = "https://github.com/HarbourMasters/Shipwright"; 288 description = "PC port of Ocarina of Time with modern controls, widescreen, high-resolution, and more"; 289 mainProgram = "soh"; 290 platforms = lib.platforms.linux ++ lib.platforms.darwin; 291 maintainers = with lib.maintainers; [ matteopacini ]; 292 license = with lib.licenses; [ 293 # OTRExporter, OTRGui, ZAPDTR, libultraship 294 mit 295 # Ship of Harkinian itself 296 unfree 297 ]; 298 }; 299})