about summary refs log tree commit diff
path: root/pkgs/games/mindustry/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/games/mindustry/default.nix')
-rw-r--r--pkgs/games/mindustry/default.nix196
1 files changed, 86 insertions, 110 deletions
diff --git a/pkgs/games/mindustry/default.nix b/pkgs/games/mindustry/default.nix
index 8489d32a8ed7e..789b2bca65a52 100644
--- a/pkgs/games/mindustry/default.nix
+++ b/pkgs/games/mindustry/default.nix
@@ -1,4 +1,5 @@
-{ lib, stdenv, fetchurl
+{ lib
+, stdenv
 , fetchpatch
 , makeWrapper
 , makeDesktopItem
@@ -6,17 +7,17 @@
 , fetchFromGitHub
 , gradle
 , jdk17
-, perl
+, zenity
 
 # for arc
 , SDL2
 , pkg-config
-, stb
 , ant
+, curl
+, wget
 , alsa-lib
 , alsa-plugins
 , glew
-, glew-egl
 
 # for soloud
 , libpulseaudio ? null
@@ -42,9 +43,6 @@ let
   buildVersion = makeBuildVersion version;
 
   jdk = jdk17;
-  gradleWithJdk = gradle.override { java = jdk; };
-
-  selectedGlew = if enableWayland then glew-egl else glew;
 
   Mindustry = fetchFromGitHub {
     owner = "Anuken";
@@ -65,22 +63,29 @@ let
     rev = "v0.9";
     hash = "sha256-6KlqOtA19MxeqZttNyNrMU7pKqzlNiA4rBZKp9ekanc=";
   };
-  freetypeSource = fetchurl {
-    # This is pinned in Arc's extensions/freetype/build.gradle
-    url = "https://download.savannah.gnu.org/releases/freetype/freetype-2.10.4.tar.gz";
-    hash = "sha256-Xqt5XrsjrHcAHPtot9TVC11sdGkkewsBsslTJp9ljaw=";
-  };
-  glewSource = fetchurl {
-    # This is pinned in Arc's backends/backend-sdl/build.gradle
-    url = "https://github.com/nigels-com/glew/releases/download/glew-2.2.0/glew-2.2.0.zip";
-    hash = "sha256-qQRqkTd0OVoJXtzAsKwtgcOqzKYXh7OYOblB6b4U4NQ=";
-  };
-  SDLmingwSource = fetchurl {
-    # This is pinned in Arc's backends/backend-sdl/build.gradle
-    url = "https://www.libsdl.org/release/SDL2-devel-2.0.20-mingw.tar.gz";
-    hash = "sha256-OAlNgqhX1sYjUuXFzex0lIxbTSXFnL0pjW0jNWiXa9E=";
+
+  desktopItem = makeDesktopItem {
+    name = "Mindustry";
+    desktopName = "Mindustry";
+    exec = "mindustry";
+    icon = "mindustry";
+    categories = [ "Game" ];
   };
 
+in
+assert lib.assertMsg (enableClient || enableServer)
+  "mindustry: at least one of 'enableClient' and 'enableServer' must be true";
+stdenv.mkDerivation {
+  inherit pname version;
+
+  unpackPhase = ''
+    cp -r ${Mindustry} Mindustry
+    cp -r ${Arc} Arc
+    chmod -R u+w -- Mindustry Arc
+    cp -r ${soloud} Arc/arc-core/csrc/soloud
+    chmod -R u+w -- Arc/arc-core/csrc/soloud
+  '';
+
   patches = [
     ./0001-fix-include-path-for-SDL2-on-linux.patch
     # Fix build with gradle 8.8, remove on next Arc release
@@ -96,105 +101,74 @@ let
       extraPrefix = "Arc/";
       stripLen = 1;
     })
+    (fetchpatch {
+      url = "https://github.com/Anuken/Mindustry/commit/695dad201fb4c2b4252f2ee5abde32e968169ba5.patch";
+      hash = "sha256-bbTjyfUl+XFG/dgD1XPddVKD/ImOP5ARAP3q0FPnt58=";
+      name = "always-use-local-arc-1.patch";
+      stripLen = 1; extraPrefix = "Mindustry/";
+    })
+    (fetchpatch {
+      url = "https://github.com/Anuken/Mindustry/commit/f6082225e859c759c8d9c944250b6ecd490151ed.patch";
+      hash = "sha256-xFHdAUTS1EiHNQqw6qfzYk2LMr/DjeHoEzQfcfOUcFs=";
+      name = "always-use-local-arc-2.patch";
+      stripLen = 1; extraPrefix = "Mindustry/";
+    })
+    (fetchpatch {
+      url = "https://github.com/Anuken/Mindustry/commit/e4eadbbb7f35db3093a0a3d13272bdfbedfaead3.patch";
+      hash = "sha256-L/XQAxh6UgKsTVTgQKDXNRIAdtVtaY4ameT/Yb/+1p8=";
+      name = "always-use-local-arc-3.patch";
+      stripLen = 1; extraPrefix = "Mindustry/";
+    })
   ];
 
-  unpackPhase = ''
-    cp -r ${Mindustry} Mindustry
-    cp -r ${Arc} Arc
-    chmod -R u+w -- Mindustry Arc
-    cp ${stb.src}/stb_image.h Arc/arc-core/csrc/
-    cp -r ${soloud} Arc/arc-core/csrc/soloud
-    chmod -R u+w -- Arc
-  '';
-
-  desktopItem = makeDesktopItem {
-    name = "Mindustry";
-    desktopName = "Mindustry";
-    exec = "mindustry";
-    icon = "mindustry";
-    categories = [ "Game" ];
-  };
-
-  cleanupMindustrySrc = ''
+  postPatch = ''
     # Ensure the prebuilt shared objects don't accidentally get shipped
     rm -r Arc/natives/natives-*/libs/*
     rm -r Arc/backends/backend-*/libs/*
 
+    cd Mindustry
+
     # Remove unbuildable iOS stuff
-    sed -i '/^project(":ios"){/,/^}/d' Mindustry/build.gradle
-    sed -i '/robo(vm|VM)/d' Mindustry/build.gradle
-    rm Mindustry/ios/build.gradle
+    sed -i '/^project(":ios"){/,/^}/d' build.gradle
+    sed -i '/robo(vm|VM)/d' build.gradle
+    rm ios/build.gradle
   '';
 
-  # fake build to pre-download deps into fixed-output derivation
-  deps = stdenv.mkDerivation {
-    pname = "${pname}-deps";
-    inherit version unpackPhase patches;
-    postPatch = cleanupMindustrySrc;
-
-    nativeBuildInputs = [ gradleWithJdk perl ];
-    # Here we download dependencies for both the server and the client so
-    # we only have to specify one hash for 'deps'. Deps can be garbage
-    # collected after the build, so this is not really an issue.
-    buildPhase = ''
-      pushd Mindustry
-      export GRADLE_USER_HOME=$(mktemp -d)
-      gradle --no-daemon resolveDependencies
-      popd
-    '';
-    # perl code mavenizes pathes (com.squareup.okio/okio/1.13.0/a9283170b7305c8d92d25aff02a6ab7e45d06cbe/okio-1.13.0.jar -> com/squareup/okio/okio/1.13.0/okio-1.13.0.jar)
-    installPhase = ''
-      find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(jar\|pom\)' \
-        | perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/$x/$3/$4/$5" #e' \
-        | sh
-    '';
-    outputHashMode = "recursive";
-    outputHash = "sha256-hbWLsWorEo+1BBURvrFMXpxvZjJBZ1p7HVlJN5e5JZc=";
+  mitmCache = gradle.fetchDeps {
+    inherit pname;
+    data = ./deps.json;
   };
 
-in
-assert lib.assertMsg (enableClient || enableServer)
-  "mindustry: at least one of 'enableClient' and 'enableServer' must be true";
-stdenv.mkDerivation rec {
-  inherit pname version unpackPhase patches;
-
-  postPatch = cleanupMindustrySrc;
+  __darwinAllowLocalNetworking = true;
 
   buildInputs = lib.optionals enableClient [
     SDL2
-    selectedGlew
     alsa-lib
+    glew
   ];
   nativeBuildInputs = [
     pkg-config
-    gradleWithJdk
+    gradle
     makeWrapper
     jdk
   ] ++ lib.optionals enableClient [
     ant
     copyDesktopItems
+    curl
+    wget
   ];
 
   desktopItems = lib.optional enableClient desktopItem;
 
-  buildPhase = with lib; ''
-    export GRADLE_USER_HOME=$(mktemp -d)
-
-    # point to offline repo
-    sed -ie "1ipluginManagement { repositories { maven { url '${deps}' } } }; " Mindustry/settings.gradle
-    sed -ie "s#mavenLocal()#mavenLocal(); maven { url '${deps}' }#g" Mindustry/build.gradle
-    sed -ie "s#mavenCentral()#mavenCentral(); maven { url '${deps}' }#g" Arc/build.gradle
-    sed -ie "s#wget.*freetype.* -O #cp ${freetypeSource} #" Arc/extensions/freetype/build.gradle
-    sed -ie "/curl.*glew/{;s#curl -o #cp ${glewSource} #;s# -L http.*\.zip##;}" Arc/backends/backend-sdl/build.gradle
-    sed -ie "/curl.*sdlmingw/{;s#curl -o #cp ${SDLmingwSource} #;s# -L http.*\.tar.gz##;}" Arc/backends/backend-sdl/build.gradle
-
-    pushd Mindustry
-  '' + optionalString enableClient ''
+  gradleFlags = [ "-Pbuildversion=${buildVersion}" "-Dorg.gradle.java.home=${jdk}" ];
 
+  buildPhase = lib.optionalString enableServer ''
+    gradle server:dist
+  '' + lib.optionalString enableClient ''
     pushd ../Arc
-    gradle --offline --no-daemon jnigenBuild -Pbuildversion=${buildVersion}
-    gradle --offline --no-daemon jnigenJarNativesDesktop -Pbuildversion=${buildVersion}
-    glewlib=${lib.getLib selectedGlew}/lib/libGLEW.so
+    gradle jnigenBuild
+    gradle jnigenJarNativesDesktop
+    glewlib=${lib.getLib glew}/lib/libGLEW.so
     sdllib=${lib.getLib SDL2}/lib/libSDL2.so
     patchelf backends/backend-sdl/libs/linux64/libsdl-arc*.so \
       --add-needed $glewlib \
@@ -204,19 +178,18 @@ stdenv.mkDerivation rec {
     cp extensions/freetype/libs/*/* natives/natives-freetype-desktop/libs/
     popd
 
-    gradle --offline --no-daemon desktop:dist -Pbuildversion=${buildVersion}
-  '' + optionalString enableServer ''
-    gradle --offline --no-daemon server:dist -Pbuildversion=${buildVersion}
+    gradle desktop:dist
   '';
 
-  installPhase = with lib; let
+  installPhase = let
     installClient = ''
       install -Dm644 desktop/build/libs/Mindustry.jar $out/share/mindustry.jar
       mkdir -p $out/bin
       makeWrapper ${jdk}/bin/java $out/bin/mindustry \
         --add-flags "-jar $out/share/mindustry.jar" \
+        ${lib.optionalString stdenv.isLinux "--suffix PATH : ${lib.makeBinPath [zenity]}"} \
         --suffix LD_LIBRARY_PATH : ${lib.makeLibraryPath [libpulseaudio alsa-lib libjack2]} \
-        --set ALSA_PLUGIN_DIR ${alsa-plugins}/lib/alsa-lib/'' + optionalString enableWayland '' \
+        --set ALSA_PLUGIN_DIR ${alsa-plugins}/lib/alsa-lib/'' + lib.optionalString enableWayland '' \
         --set SDL_VIDEODRIVER wayland \
         --set SDL_VIDEO_WAYLAND_WMCLASS Mindustry
       '' + ''
@@ -227,7 +200,7 @@ stdenv.mkDerivation rec {
       # This can cause issues.
       # See https://github.com/NixOS/nixpkgs/issues/109798.
       echo "# Retained runtime dependencies: " >> $out/bin/mindustry
-      for dep in ${SDL2.out} ${alsa-lib.out} ${selectedGlew.out}; do
+      for dep in ${SDL2.out} ${alsa-lib.out} ${glew.out}; do
         echo "# $dep" >> $out/bin/mindustry
       done
 
@@ -241,29 +214,32 @@ stdenv.mkDerivation rec {
     '';
   in ''
     runHook preInstall
-  '' + optionalString enableClient installClient
-     + optionalString enableServer installServer
+  '' + lib.optionalString enableClient installClient
+     + lib.optionalString enableServer installServer
      + ''
     runHook postInstall
   '';
 
-  passthru.tests = {
-    nixosTest = nixosTests.mindustry;
-  };
+  postGradleUpdate = ''
+    # this fetches non-gradle dependencies
+    cd ../Arc
+    gradle preJni
+  '';
+
+  passthru.tests.nixosTest = nixosTests.mindustry;
 
-  meta = with lib; {
+  meta = {
     homepage = "https://mindustrygame.github.io/";
     downloadPage = "https://github.com/Anuken/Mindustry/releases";
     description = "Sandbox tower defense game";
-    sourceProvenance = with sourceTypes; [
+    sourceProvenance = with lib.sourceTypes; [
       fromSource
       binaryBytecode  # deps
     ];
-    license = licenses.gpl3Plus;
-    maintainers = with maintainers; [ chkno fgaz thekostins ];
-    platforms = if enableClient then platforms.x86_64 else platforms.linux;
-    # Hash mismatch on darwin:
-    # https://github.com/NixOS/nixpkgs/pull/105590#issuecomment-737120293
-    broken = stdenv.isDarwin;
+    license = lib.licenses.gpl3Plus;
+    maintainers = with lib.maintainers; [ chkno fgaz thekostins ];
+    platforms = lib.platforms.all;
+    # TODO alsa-lib is linux-only, figure out what dependencies are required on Darwin
+    broken = enableClient && stdenv.isDarwin;
   };
 }