spaghettikart: init at 0-unstable-2025-08-07

qubitnano 210106ef 09906cab

+323
+16
pkgs/by-name/sp/spaghettikart/dont-fetch-stb.patch
···
··· 1 + Submodule libultraship contains modified content 2 + diff --git a/libultraship/cmake/dependencies/common.cmake b/libultraship/cmake/dependencies/common.cmake 3 + index 596158c..c62d7b2 100644 4 + --- a/libultraship/cmake/dependencies/common.cmake 5 + +++ b/libultraship/cmake/dependencies/common.cmake 6 + @@ -47,10 +47,6 @@ set(stormlib_optimizations_patch git apply ${CMAKE_CURRENT_SOURCE_DIR}/cmake/dep 7 + endif() 8 + 9 + #=================== STB =================== 10 + -set(STB_DIR ${CMAKE_BINARY_DIR}/_deps/stb) 11 + -file(DOWNLOAD "https://github.com/nothings/stb/raw/0bc88af4de5fb022db643c2d8e549a0927749354/stb_image.h" "${STB_DIR}/stb_image.h") 12 + -file(WRITE "${STB_DIR}/stb_impl.c" "#define STB_IMAGE_IMPLEMENTATION\n#include \"stb_image.h\"") 13 + - 14 + add_library(stb STATIC) 15 + 16 + target_sources(stb PRIVATE
+44
pkgs/by-name/sp/spaghettikart/git-deps.patch
···
··· 1 + diff --git a/torch/CMakeLists.txt b/torch/CMakeLists.txt 2 + index ba3859a..cf3da99 100644 3 + --- a/torch/CMakeLists.txt 4 + +++ b/torch/CMakeLists.txt 5 + @@ -36,8 +36,7 @@ if(USE_STANDALONE) 6 + # Because libgfxd is not a CMake project, we have to manually fetch it and add it to the build 7 + FetchContent_Declare( 8 + libgfxd 9 + - GIT_REPOSITORY https://github.com/glankk/libgfxd.git 10 + - GIT_TAG 96fd3b849f38b3a7c7b7f3ff03c5921d328e6cdf 11 + + URL @libgfxd_src@ 12 + ) 13 + 14 + FetchContent_GetProperties(libgfxd) 15 + @@ -205,8 +204,7 @@ set(YAML_CPP_BUILD_TESTS OFF) 16 + set(YAML_CPP_DISABLE_UNINSTALL ON) 17 + FetchContent_Declare( 18 + yaml-cpp 19 + - GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git 20 + - GIT_TAG 2f86d13775d119edbb69af52e5f566fd65c6953b 21 + + URL @yaml-cpp_src@ 22 + ) 23 + set(YAML_CPP_BUILD_TESTS OFF) 24 + FetchContent_MakeAvailable(yaml-cpp) 25 + @@ -219,8 +217,7 @@ endif() 26 + if(USE_STANDALONE) 27 + FetchContent_Declare( 28 + spdlog 29 + - GIT_REPOSITORY https://github.com/gabime/spdlog.git 30 + - GIT_TAG 7e635fca68d014934b4af8a1cf874f63989352b7 31 + + URL @spdlog_src@ 32 + ) 33 + 34 + FetchContent_MakeAvailable(spdlog) 35 + @@ -234,8 +231,7 @@ endif() 36 + set(tinyxml2_BUILD_TESTING OFF) 37 + FetchContent_Declare( 38 + tinyxml2 39 + - GIT_REPOSITORY https://github.com/leethomason/tinyxml2.git 40 + - GIT_TAG 10.0.0 41 + + URL @tinyxml2_src@ 42 + OVERRIDE_FIND_PACKAGE 43 + ) 44 + FetchContent_MakeAvailable(tinyxml2)
+263
pkgs/by-name/sp/spaghettikart/package.nix
···
··· 1 + { 2 + lib, 3 + fetchFromGitHub, 4 + applyPatches, 5 + writeTextFile, 6 + fetchurl, 7 + stdenv, 8 + replaceVars, 9 + yaml-cpp, 10 + srcOnly, 11 + cmake, 12 + copyDesktopItems, 13 + installShellFiles, 14 + lsb-release, 15 + makeWrapper, 16 + ninja, 17 + pkg-config, 18 + libGL, 19 + libvorbis, 20 + libX11, 21 + libzip, 22 + nlohmann_json, 23 + SDL2, 24 + SDL2_net, 25 + spdlog, 26 + tinyxml-2, 27 + zenity, 28 + sdl_gamecontrollerdb, 29 + spaghettikart, 30 + makeDesktopItem, 31 + }: 32 + 33 + let 34 + 35 + # The following are either normally fetched during build time or a specific version is required 36 + 37 + dr_libs = fetchFromGitHub { 38 + owner = "mackron"; 39 + repo = "dr_libs"; 40 + rev = "da35f9d6c7374a95353fd1df1d394d44ab66cf01"; 41 + hash = "sha256-ydFhQ8LTYDBnRTuETtfWwIHZpRciWfqGsZC6SuViEn0="; 42 + }; 43 + 44 + imgui' = applyPatches { 45 + src = fetchFromGitHub { 46 + owner = "ocornut"; 47 + repo = "imgui"; 48 + tag = "v1.91.9b-docking"; 49 + hash = "sha256-mQOJ6jCN+7VopgZ61yzaCnt4R1QLrW7+47xxMhFRHLQ="; 50 + }; 51 + patches = [ 52 + "${spaghettikart.src}/libultraship/cmake/dependencies/patches/imgui-fixes-and-config.patch" 53 + ]; 54 + }; 55 + 56 + libgfxd = fetchFromGitHub { 57 + owner = "glankk"; 58 + repo = "libgfxd"; 59 + rev = "008f73dca8ebc9151b205959b17773a19c5bd0da"; 60 + hash = "sha256-AmHAa3/cQdh7KAMFOtz5TQpcM6FqO9SppmDpKPTjTt8="; 61 + }; 62 + 63 + prism = fetchFromGitHub { 64 + owner = "KiritoDv"; 65 + repo = "prism-processor"; 66 + rev = "7ae724a6fb7df8cbf547445214a1a848aefef747"; 67 + hash = "sha256-G7koDUxD6PgZWmoJtKTNubDHg6Eoq8I+AxIJR0h3i+A="; 68 + }; 69 + 70 + stb_impl = writeTextFile { 71 + name = "stb_impl.c"; 72 + text = '' 73 + #define STB_IMAGE_IMPLEMENTATION 74 + #include "stb_image.h" 75 + ''; 76 + }; 77 + 78 + stb' = fetchurl { 79 + name = "stb_image.h"; 80 + url = "https://raw.githubusercontent.com/nothings/stb/0bc88af4de5fb022db643c2d8e549a0927749354/stb_image.h"; 81 + hash = "sha256-xUsVponmofMsdeLsI6+kQuPg436JS3PBl00IZ5sg3Vw="; 82 + }; 83 + 84 + stormlib' = applyPatches { 85 + src = fetchFromGitHub { 86 + owner = "ladislav-zezula"; 87 + repo = "StormLib"; 88 + tag = "v9.25"; 89 + hash = "sha256-HTi2FKzKCbRaP13XERUmHkJgw8IfKaRJvsK3+YxFFdc="; 90 + }; 91 + patches = [ 92 + "${spaghettikart.src}/libultraship/cmake/dependencies/patches/stormlib-optimizations.patch" 93 + ]; 94 + }; 95 + 96 + thread_pool = fetchFromGitHub { 97 + owner = "bshoshany"; 98 + repo = "thread-pool"; 99 + tag = "v4.1.0"; 100 + hash = "sha256-zhRFEmPYNFLqQCfvdAaG5VBNle9Qm8FepIIIrT9sh88="; 101 + }; 102 + 103 + in 104 + stdenv.mkDerivation (finalAttrs: { 105 + pname = "spaghettikart"; 106 + version = "0-unstable-2025-08-07"; 107 + 108 + src = fetchFromGitHub { 109 + owner = "HarbourMasters"; 110 + repo = "SpaghettiKart"; 111 + rev = "334fdeafd26c15e03b4f198002ad86b8422c0e2f"; 112 + hash = "sha256-0nDaX34C7stg7S2mzPChz0fRz/t7yyevKEAPmIR+lak="; 113 + fetchSubmodules = true; 114 + deepClone = true; 115 + postFetch = '' 116 + cd $out 117 + (git describe --tags HEAD 2>/dev/null || echo "") > PROJECT_VERSION 118 + git log --pretty=format:%h -1 > PROJECT_VERSION_PATCH 119 + rm -rf .git 120 + ''; 121 + }; 122 + 123 + patches = [ 124 + # Don't fetch stb as we will patch our own 125 + ./dont-fetch-stb.patch 126 + 127 + # Can't fetch these torch deps in the sandbox 128 + (replaceVars ./git-deps.patch { 129 + libgfxd_src = fetchFromGitHub { 130 + owner = "glankk"; 131 + repo = "libgfxd"; 132 + rev = "96fd3b849f38b3a7c7b7f3ff03c5921d328e6cdf"; 133 + hash = "sha256-dedZuV0BxU6goT+rPvrofYqTz9pTA/f6eQcsvpDWdvQ="; 134 + }; 135 + spdlog_src = fetchFromGitHub { 136 + owner = "gabime"; 137 + repo = "spdlog"; 138 + rev = "7e635fca68d014934b4af8a1cf874f63989352b7"; 139 + hash = "sha256-cxTaOuLXHRU8xMz9gluYz0a93O0ez2xOxbloyc1m1ns="; 140 + }; 141 + yaml-cpp_src = fetchFromGitHub { 142 + owner = "jbeder"; 143 + repo = "yaml-cpp"; 144 + rev = "28f93bdec6387d42332220afa9558060c8016795"; 145 + hash = "sha256-59/s4Rqiiw7LKQw0UwH3vOaT/YsNVcoq3vblK0FiO5c="; 146 + }; 147 + tinyxml2_src = srcOnly tinyxml-2; 148 + }) 149 + ]; 150 + 151 + # Recent builds enabled LTO which won't build with nix 152 + NIX_CFLAGS_COMPILE = "-fno-lto"; 153 + 154 + nativeBuildInputs = [ 155 + cmake 156 + copyDesktopItems 157 + installShellFiles 158 + lsb-release 159 + makeWrapper 160 + ninja 161 + pkg-config 162 + ]; 163 + 164 + buildInputs = [ 165 + libGL 166 + libvorbis 167 + libX11 168 + libzip 169 + nlohmann_json 170 + SDL2 171 + SDL2_net 172 + spdlog 173 + tinyxml-2 174 + zenity 175 + ]; 176 + 177 + cmakeFlags = [ 178 + (lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}") 179 + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_DR_LIBS" "${dr_libs}") 180 + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_IMGUI" "${imgui'}") 181 + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_LIBGFXD" "${libgfxd}") 182 + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_PRISM" "${prism}") 183 + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_STORMLIB" "${stormlib'}") 184 + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_THREADPOOL" "${thread_pool}") 185 + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_TINYXML2" "${tinyxml-2}") 186 + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_YAML-CPP" "${yaml-cpp.src}") 187 + ]; 188 + 189 + strictDeps = true; 190 + 191 + # Linking fails without this 192 + hardeningDisable = [ "format" ]; 193 + 194 + preConfigure = '' 195 + mkdir stb 196 + cp ${stb'} ./stb/${stb'.name} 197 + cp ${stb_impl} ./stb/${stb_impl.name} 198 + substituteInPlace libultraship/cmake/dependencies/common.cmake \ 199 + --replace-fail "\''${STB_DIR}" "$(readlink -f ./stb)" 200 + ''; 201 + 202 + postPatch = '' 203 + substituteInPlace CMakeLists.txt \ 204 + --replace-fail "COMMAND git describe --tags" "COMMAND echo $(cat PROJECT_VERSION)" \ 205 + --replace-fail "COMMAND git log --pretty=format:%h -1" "COMMAND echo $(cat PROJECT_VERSION_PATCH)" 206 + ''; 207 + 208 + postBuild = '' 209 + cp ${sdl_gamecontrollerdb}/share/gamecontrollerdb.txt gamecontrollerdb.txt 210 + ./TorchExternal/src/TorchExternal-build/torch pack ../assets spaghetti.o2r o2r 211 + ''; 212 + 213 + postInstall = '' 214 + installBin Spaghettify 215 + mkdir -p $out/share/spaghettikart 216 + cp -r ../yamls $out/share/spaghettikart/ 217 + install -Dm644 -t $out/share/spaghettikart {spaghetti.o2r,config.yml,gamecontrollerdb.txt} 218 + install -Dm644 ../icon.png $out/share/pixmaps/spaghettikart.png 219 + install -Dm644 -t $out/share/licenses/spaghettikart/libgfxd ${libgfxd}/LICENSE 220 + install -Dm644 -t $out/share/licenses/spaghettikart/libultraship ../libultraship/LICENSE 221 + install -Dm644 -t $out/share/licenses/spaghettikart/thread_pool ${thread_pool}/LICENSE.txt 222 + ''; 223 + 224 + # Unfortunately, spaghettikart really wants a writable working directory 225 + # Create $HOME/.local/share/spaghettikart and symlink required files 226 + 227 + postFixup = '' 228 + wrapProgram $out/bin/Spaghettify \ 229 + --prefix PATH ":" ${lib.makeBinPath [ zenity ]} \ 230 + --run 'mkdir -p ~/.local/share/spaghettikart' \ 231 + --run "ln -sf $out/share/spaghettikart/spaghetti.o2r ~/.local/share/spaghettikart/spaghetti.o2r" \ 232 + --run "ln -sf $out/share/spaghettikart/config.yml ~/.local/share/spaghettikart/config.yml" \ 233 + --run "ln -sfT $out/share/spaghettikart/yamls ~/.local/share/spaghettikart/yamls" \ 234 + --run "ln -sf $out/share/spaghettikart/gamecontrollerdb.txt ~/.local/share/spaghettikart/gamecontrollerdb.txt" \ 235 + --run 'cd ~/.local/share/spaghettikart' 236 + ''; 237 + 238 + desktopItems = [ 239 + (makeDesktopItem { 240 + name = "spaghettikart"; 241 + icon = "spaghettikart"; 242 + exec = "Spaghettify"; 243 + comment = finalAttrs.meta.description; 244 + genericName = "spaghettikart"; 245 + desktopName = "spaghettikart"; 246 + categories = [ "Game" ]; 247 + }) 248 + ]; 249 + 250 + meta = { 251 + homepage = "https://github.com/HarbourMasters/SpaghettiKart"; 252 + description = "Mario Kart 64 PC Port"; 253 + mainProgram = "Spaghettify"; 254 + platforms = [ "x86_64-linux" ]; 255 + maintainers = with lib.maintainers; [ qubitnano ]; 256 + license = with lib.licenses; [ 257 + # libultraship, libgfxd, thread_pool, dr_libs, prism-processor 258 + mit 259 + # Reverse engineering 260 + unfree 261 + ]; 262 + }; 263 + })