2022-10-28 19:20:33 +02:00
|
|
|
{ lib, stdenv, fetchurl
|
2020-01-13 11:01:29 +01:00
|
|
|
, makeWrapper
|
|
|
|
, makeDesktopItem
|
2021-01-11 15:55:52 +01:00
|
|
|
, copyDesktopItems
|
2020-01-13 11:01:29 +01:00
|
|
|
, fetchFromGitHub
|
2022-10-28 19:20:33 +02:00
|
|
|
, gradle
|
2024-03-20 00:13:51 +01:00
|
|
|
, jdk17
|
2020-01-13 11:01:29 +01:00
|
|
|
, perl
|
2021-01-11 15:55:52 +01:00
|
|
|
|
|
|
|
# for arc
|
|
|
|
, SDL2
|
|
|
|
, pkg-config
|
|
|
|
, stb
|
|
|
|
, ant
|
2021-06-10 04:57:09 +02:00
|
|
|
, alsa-lib
|
2022-04-09 16:20:43 +02:00
|
|
|
, alsa-plugins
|
2021-01-11 15:55:52 +01:00
|
|
|
, glew
|
2023-04-21 10:23:40 +02:00
|
|
|
, glew-egl
|
2020-01-13 11:01:29 +01:00
|
|
|
|
2022-10-28 19:20:33 +02:00
|
|
|
# for soloud
|
|
|
|
, libpulseaudio ? null
|
|
|
|
, libjack2 ? null
|
|
|
|
|
2023-01-15 00:28:32 +01:00
|
|
|
, nixosTests
|
|
|
|
|
2022-10-28 19:20:33 +02:00
|
|
|
|
2020-01-13 11:01:29 +01:00
|
|
|
# Make the build version easily overridable.
|
|
|
|
# Server and client build versions must match, and an empty build version means
|
|
|
|
# any build is allowed, so this parameter acts as a simple whitelist.
|
|
|
|
# Takes the package version and returns the build version.
|
|
|
|
, makeBuildVersion ? (v: v)
|
2020-01-26 16:14:02 +01:00
|
|
|
, enableClient ? true
|
|
|
|
, enableServer ? true
|
2023-04-21 10:23:40 +02:00
|
|
|
|
|
|
|
, enableWayland ? false
|
2020-01-13 11:01:29 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
pname = "mindustry";
|
2023-09-05 20:09:04 +02:00
|
|
|
version = "146";
|
2020-01-13 11:01:29 +01:00
|
|
|
buildVersion = makeBuildVersion version;
|
|
|
|
|
2024-03-20 00:13:51 +01:00
|
|
|
jdk = jdk17;
|
2023-11-30 15:00:51 +01:00
|
|
|
gradleWithJdk = gradle.override { java = jdk; };
|
|
|
|
|
2023-04-21 10:23:40 +02:00
|
|
|
selectedGlew = if enableWayland then glew-egl else glew;
|
|
|
|
|
2021-01-11 15:55:52 +01:00
|
|
|
Mindustry = fetchFromGitHub {
|
2020-01-13 11:01:29 +01:00
|
|
|
owner = "Anuken";
|
|
|
|
repo = "Mindustry";
|
|
|
|
rev = "v${version}";
|
2023-09-05 20:09:04 +02:00
|
|
|
hash = "sha256-pJAJjb8rgDL5q2hfuXH2Cyb1Szu4GixeXoLMdnIAlno=";
|
2020-01-13 11:01:29 +01:00
|
|
|
};
|
2021-01-11 15:55:52 +01:00
|
|
|
Arc = fetchFromGitHub {
|
|
|
|
owner = "Anuken";
|
|
|
|
repo = "Arc";
|
|
|
|
rev = "v${version}";
|
2023-09-05 20:09:04 +02:00
|
|
|
hash = "sha256-L+5fshI1oo1lVdTMTBuPzqtEeR2dq1NORP84rZ83rT0=";
|
2021-01-11 15:55:52 +01:00
|
|
|
};
|
|
|
|
soloud = fetchFromGitHub {
|
|
|
|
owner = "Anuken";
|
|
|
|
repo = "soloud";
|
2022-10-28 19:20:33 +02:00
|
|
|
# This is pinned in Arc's arc-core/build.gradle
|
|
|
|
rev = "v0.9";
|
2023-01-15 00:33:16 +01:00
|
|
|
hash = "sha256-6KlqOtA19MxeqZttNyNrMU7pKqzlNiA4rBZKp9ekanc=";
|
2022-10-28 19:20:33 +02:00
|
|
|
};
|
|
|
|
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";
|
2023-01-15 00:33:16 +01:00
|
|
|
hash = "sha256-Xqt5XrsjrHcAHPtot9TVC11sdGkkewsBsslTJp9ljaw=";
|
2022-10-28 19:20:33 +02:00
|
|
|
};
|
|
|
|
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";
|
2023-01-15 00:33:16 +01:00
|
|
|
hash = "sha256-qQRqkTd0OVoJXtzAsKwtgcOqzKYXh7OYOblB6b4U4NQ=";
|
2022-10-28 19:20:33 +02:00
|
|
|
};
|
|
|
|
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";
|
2023-01-15 00:33:16 +01:00
|
|
|
hash = "sha256-OAlNgqhX1sYjUuXFzex0lIxbTSXFnL0pjW0jNWiXa9E=";
|
2021-01-11 15:55:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
patches = [
|
|
|
|
./0001-fix-include-path-for-SDL2-on-linux.patch
|
|
|
|
];
|
|
|
|
|
|
|
|
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
|
|
|
|
'';
|
2020-01-13 11:01:29 +01:00
|
|
|
|
|
|
|
desktopItem = makeDesktopItem {
|
|
|
|
name = "Mindustry";
|
|
|
|
desktopName = "Mindustry";
|
|
|
|
exec = "mindustry";
|
|
|
|
icon = "mindustry";
|
|
|
|
};
|
|
|
|
|
2021-01-11 15:55:52 +01:00
|
|
|
cleanupMindustrySrc = ''
|
2022-10-28 20:03:25 +02:00
|
|
|
# Ensure the prebuilt shared objects don't accidentally get shipped
|
|
|
|
rm -r Arc/natives/natives-*/libs/*
|
|
|
|
rm -r Arc/backends/backend-*/libs/*
|
2021-01-11 15:55:52 +01:00
|
|
|
|
2020-01-13 11:01:29 +01:00
|
|
|
# Remove unbuildable iOS stuff
|
2022-10-28 20:03:25 +02:00
|
|
|
sed -i '/^project(":ios"){/,/^}/d' Mindustry/build.gradle
|
|
|
|
sed -i '/robo(vm|VM)/d' Mindustry/build.gradle
|
|
|
|
rm Mindustry/ios/build.gradle
|
2020-01-13 11:01:29 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
# fake build to pre-download deps into fixed-output derivation
|
|
|
|
deps = stdenv.mkDerivation {
|
|
|
|
pname = "${pname}-deps";
|
2021-01-11 15:55:52 +01:00
|
|
|
inherit version unpackPhase patches;
|
|
|
|
postPatch = cleanupMindustrySrc;
|
|
|
|
|
2023-11-30 15:00:51 +01:00
|
|
|
nativeBuildInputs = [ gradleWithJdk perl ];
|
2021-01-11 15:55:52 +01:00
|
|
|
# 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.
|
2021-01-12 20:17:11 +01:00
|
|
|
buildPhase = ''
|
2021-01-11 15:55:52 +01:00
|
|
|
pushd Mindustry
|
2021-01-12 20:17:11 +01:00
|
|
|
export GRADLE_USER_HOME=$(mktemp -d)
|
2021-01-11 15:55:52 +01:00
|
|
|
gradle --no-daemon resolveDependencies
|
|
|
|
popd
|
2020-01-13 11:01:29 +01:00
|
|
|
'';
|
|
|
|
# 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";
|
2023-09-05 20:09:04 +02:00
|
|
|
outputHash = "sha256-hbWLsWorEo+1BBURvrFMXpxvZjJBZ1p7HVlJN5e5JZc=";
|
2020-01-13 11:01:29 +01:00
|
|
|
};
|
|
|
|
|
2021-01-11 15:55:52 +01:00
|
|
|
in
|
2021-01-12 20:17:11 +01:00
|
|
|
assert lib.assertMsg (enableClient || enableServer)
|
2021-01-11 15:55:52 +01:00
|
|
|
"mindustry: at least one of 'enableClient' and 'enableServer' must be true";
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
inherit pname version unpackPhase patches;
|
|
|
|
|
2022-10-28 20:03:25 +02:00
|
|
|
postPatch = cleanupMindustrySrc;
|
2021-01-11 15:55:52 +01:00
|
|
|
|
2021-01-12 20:17:11 +01:00
|
|
|
buildInputs = lib.optionals enableClient [
|
2021-01-11 15:55:52 +01:00
|
|
|
SDL2
|
2023-04-21 10:23:40 +02:00
|
|
|
selectedGlew
|
2021-06-10 04:57:09 +02:00
|
|
|
alsa-lib
|
2021-01-11 15:55:52 +01:00
|
|
|
];
|
|
|
|
nativeBuildInputs = [
|
|
|
|
pkg-config
|
2023-11-30 15:00:51 +01:00
|
|
|
gradleWithJdk
|
2021-01-11 15:55:52 +01:00
|
|
|
makeWrapper
|
|
|
|
jdk
|
2021-01-12 20:17:11 +01:00
|
|
|
] ++ lib.optionals enableClient [
|
2021-01-11 15:55:52 +01:00
|
|
|
ant
|
|
|
|
copyDesktopItems
|
|
|
|
];
|
|
|
|
|
2021-01-12 20:17:11 +01:00
|
|
|
desktopItems = lib.optional enableClient desktopItem;
|
|
|
|
|
|
|
|
buildPhase = with lib; ''
|
|
|
|
export GRADLE_USER_HOME=$(mktemp -d)
|
2021-01-11 15:55:52 +01:00
|
|
|
|
|
|
|
# point to offline repo
|
2022-10-28 19:20:33 +02:00
|
|
|
sed -ie "1ipluginManagement { repositories { maven { url '${deps}' } } }; " Mindustry/settings.gradle
|
2021-01-11 15:55:52 +01:00
|
|
|
sed -ie "s#mavenLocal()#mavenLocal(); maven { url '${deps}' }#g" Mindustry/build.gradle
|
|
|
|
sed -ie "s#mavenCentral()#mavenCentral(); maven { url '${deps}' }#g" Arc/build.gradle
|
2022-10-28 19:20:33 +02:00
|
|
|
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
|
2021-01-11 15:55:52 +01:00
|
|
|
|
|
|
|
pushd Mindustry
|
|
|
|
'' + optionalString enableClient ''
|
2022-10-28 19:20:33 +02:00
|
|
|
|
|
|
|
pushd ../Arc
|
2021-01-11 15:55:52 +01:00
|
|
|
gradle --offline --no-daemon jnigenBuild -Pbuildversion=${buildVersion}
|
2022-10-28 19:20:33 +02:00
|
|
|
gradle --offline --no-daemon jnigenJarNativesDesktop -Pbuildversion=${buildVersion}
|
2023-04-21 10:23:40 +02:00
|
|
|
glewlib=${lib.getLib selectedGlew}/lib/libGLEW.so
|
2021-11-18 23:05:38 +01:00
|
|
|
sdllib=${lib.getLib SDL2}/lib/libSDL2.so
|
2022-10-28 19:20:33 +02:00
|
|
|
patchelf backends/backend-sdl/libs/linux64/libsdl-arc*.so \
|
2021-11-18 23:05:38 +01:00
|
|
|
--add-needed $glewlib \
|
|
|
|
--add-needed $sdllib
|
2022-10-28 19:20:33 +02:00
|
|
|
# Put the freshly-built libraries where the pre-built libraries used to be:
|
|
|
|
cp arc-core/libs/*/* natives/natives-desktop/libs/
|
|
|
|
cp extensions/freetype/libs/*/* natives/natives-freetype-desktop/libs/
|
|
|
|
popd
|
|
|
|
|
2020-01-13 11:01:29 +01:00
|
|
|
gradle --offline --no-daemon desktop:dist -Pbuildversion=${buildVersion}
|
2021-01-11 15:55:52 +01:00
|
|
|
'' + optionalString enableServer ''
|
2020-01-13 11:01:29 +01:00
|
|
|
gradle --offline --no-daemon server:dist -Pbuildversion=${buildVersion}
|
|
|
|
'';
|
2021-01-11 15:55:52 +01:00
|
|
|
|
2023-05-24 16:41:40 +02:00
|
|
|
installPhase = with lib; 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" \
|
|
|
|
--suffix LD_LIBRARY_PATH : ${lib.makeLibraryPath [libpulseaudio alsa-lib libjack2]} \
|
|
|
|
--set ALSA_PLUGIN_DIR ${alsa-plugins}/lib/alsa-lib/'' + optionalString enableWayland '' \
|
|
|
|
--set SDL_VIDEODRIVER wayland \
|
|
|
|
--set SDL_VIDEO_WAYLAND_WMCLASS Mindustry
|
|
|
|
'' + ''
|
|
|
|
|
|
|
|
# Retain runtime depends to prevent them from being cleaned up.
|
|
|
|
# Since a jar is a compressed archive, nix can't figure out that the dependency is actually in there,
|
|
|
|
# and will assume that it's not actually needed.
|
|
|
|
# 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
|
|
|
|
echo "# $dep" >> $out/bin/mindustry
|
|
|
|
done
|
|
|
|
|
|
|
|
install -Dm644 core/assets/icons/icon_64.png $out/share/icons/hicolor/64x64/apps/mindustry.png
|
|
|
|
'';
|
|
|
|
installServer = ''
|
|
|
|
install -Dm644 server/build/libs/server-release.jar $out/share/mindustry-server.jar
|
|
|
|
mkdir -p $out/bin
|
|
|
|
makeWrapper ${jdk}/bin/java $out/bin/mindustry-server \
|
|
|
|
--add-flags "-jar $out/share/mindustry-server.jar"
|
|
|
|
'';
|
|
|
|
in ''
|
2021-01-12 20:17:11 +01:00
|
|
|
runHook preInstall
|
2023-05-24 16:41:40 +02:00
|
|
|
'' + optionalString enableClient installClient
|
|
|
|
+ optionalString enableServer installServer
|
|
|
|
+ ''
|
2021-01-12 20:17:11 +01:00
|
|
|
runHook postInstall
|
2020-01-26 16:14:02 +01:00
|
|
|
'';
|
|
|
|
|
2023-01-15 00:28:32 +01:00
|
|
|
passthru.tests = {
|
|
|
|
nixosTest = nixosTests.mindustry;
|
|
|
|
};
|
|
|
|
|
2021-01-11 08:54:33 +01:00
|
|
|
meta = with lib; {
|
2020-01-13 11:01:29 +01:00
|
|
|
homepage = "https://mindustrygame.github.io/";
|
|
|
|
downloadPage = "https://github.com/Anuken/Mindustry/releases";
|
|
|
|
description = "A sandbox tower defense game";
|
2022-06-04 20:07:20 +02:00
|
|
|
sourceProvenance = with sourceTypes; [
|
|
|
|
fromSource
|
|
|
|
binaryBytecode # deps
|
|
|
|
];
|
2020-12-28 17:03:31 +01:00
|
|
|
license = licenses.gpl3Plus;
|
2023-02-25 07:41:49 +01:00
|
|
|
maintainers = with maintainers; [ chkno fgaz thekostins ];
|
2023-06-04 06:45:43 +02:00
|
|
|
platforms = if enableClient then platforms.x86_64 else platforms.linux;
|
2020-12-02 13:52:19 +01:00
|
|
|
# Hash mismatch on darwin:
|
|
|
|
# https://github.com/NixOS/nixpkgs/pull/105590#issuecomment-737120293
|
2021-11-18 23:04:17 +01:00
|
|
|
broken = stdenv.isDarwin;
|
2020-01-13 11:01:29 +01:00
|
|
|
};
|
|
|
|
}
|