2023-12-10 09:44:47 +01:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
2024-06-30 09:16:19 +02:00
|
|
|
, fetchpatch
|
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
|
2024-08-07 08:38:03 +02:00
|
|
|
, zenity
|
2021-01-11 15:55:52 +01:00
|
|
|
|
|
|
|
# for arc
|
|
|
|
, SDL2
|
|
|
|
, pkg-config
|
|
|
|
, ant
|
2023-12-10 09:44:47 +01:00
|
|
|
, curl
|
|
|
|
, wget
|
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
|
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
|
|
|
|
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
|
|
|
};
|
2023-12-10 09:44:47 +01:00
|
|
|
|
|
|
|
desktopItem = makeDesktopItem {
|
|
|
|
name = "Mindustry";
|
|
|
|
desktopName = "Mindustry";
|
|
|
|
exec = "mindustry";
|
|
|
|
icon = "mindustry";
|
|
|
|
categories = [ "Game" ];
|
2021-01-11 15:55:52 +01:00
|
|
|
};
|
|
|
|
|
2023-12-10 09:44:47 +01:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
2021-01-11 15:55:52 +01:00
|
|
|
patches = [
|
|
|
|
./0001-fix-include-path-for-SDL2-on-linux.patch
|
2024-06-30 09:16:19 +02:00
|
|
|
# Fix build with gradle 8.8, remove on next Arc release
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/Anuken/Arc/commit/2a91c51bf45d700091e397fd0b62384763901ae6.patch";
|
|
|
|
hash = "sha256-sSD78GmF14vBvNe+ajUJ4uIc4p857shTP/UkAK6Pyyg=";
|
|
|
|
extraPrefix = "Arc/";
|
|
|
|
stripLen = 1;
|
|
|
|
})
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/Anuken/Arc/commit/d7f8ea858c425410dbd43374271a703d4443b432.patch";
|
|
|
|
hash = "sha256-5LPgBOV0r/dUtpyxitTu3/9tMIqjeIKfGVJi3MEr7fQ=";
|
|
|
|
extraPrefix = "Arc/";
|
|
|
|
stripLen = 1;
|
|
|
|
})
|
2023-12-10 09:44:47 +01:00
|
|
|
(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/";
|
|
|
|
})
|
2021-01-11 15:55:52 +01:00
|
|
|
];
|
|
|
|
|
2023-12-10 09:44:47 +01:00
|
|
|
postPatch = ''
|
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
|
|
|
|
2023-12-10 09:44:47 +01:00
|
|
|
cd Mindustry
|
|
|
|
|
2020-01-13 11:01:29 +01:00
|
|
|
# Remove unbuildable iOS stuff
|
2023-12-10 09:44:47 +01:00
|
|
|
sed -i '/^project(":ios"){/,/^}/d' build.gradle
|
|
|
|
sed -i '/robo(vm|VM)/d' build.gradle
|
|
|
|
rm ios/build.gradle
|
2020-01-13 11:01:29 +01:00
|
|
|
'';
|
|
|
|
|
2023-12-10 09:44:47 +01:00
|
|
|
mitmCache = gradle.fetchDeps {
|
|
|
|
inherit pname;
|
|
|
|
data = ./deps.json;
|
2020-01-13 11:01:29 +01:00
|
|
|
};
|
|
|
|
|
2023-12-10 09:44:47 +01:00
|
|
|
__darwinAllowLocalNetworking = true;
|
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
|
2021-06-10 04:57:09 +02:00
|
|
|
alsa-lib
|
2024-08-10 16:58:39 +02:00
|
|
|
glew
|
2021-01-11 15:55:52 +01:00
|
|
|
];
|
|
|
|
nativeBuildInputs = [
|
|
|
|
pkg-config
|
2023-12-10 09:44:47 +01:00
|
|
|
gradle
|
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
|
2023-12-10 09:44:47 +01:00
|
|
|
curl
|
|
|
|
wget
|
2021-01-11 15:55:52 +01:00
|
|
|
];
|
|
|
|
|
2021-01-12 20:17:11 +01:00
|
|
|
desktopItems = lib.optional enableClient desktopItem;
|
|
|
|
|
2023-12-10 09:44:47 +01:00
|
|
|
gradleFlags = [ "-Pbuildversion=${buildVersion}" "-Dorg.gradle.java.home=${jdk}" ];
|
2021-01-11 15:55:52 +01:00
|
|
|
|
2024-08-16 23:05:34 +02:00
|
|
|
buildPhase = lib.optionalString enableServer ''
|
2023-12-10 09:44:47 +01:00
|
|
|
gradle server:dist
|
2024-08-16 23:05:34 +02:00
|
|
|
'' + lib.optionalString enableClient ''
|
2022-10-28 19:20:33 +02:00
|
|
|
pushd ../Arc
|
2023-12-10 09:44:47 +01:00
|
|
|
gradle jnigenBuild
|
|
|
|
gradle jnigenJarNativesDesktop
|
2024-08-10 16:58:39 +02:00
|
|
|
glewlib=${lib.getLib glew}/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
|
|
|
|
|
2023-12-10 09:44:47 +01:00
|
|
|
gradle desktop:dist
|
2020-01-13 11:01:29 +01:00
|
|
|
'';
|
2021-01-11 15:55:52 +01:00
|
|
|
|
2024-08-16 23:05:34 +02:00
|
|
|
installPhase = let
|
2023-05-24 16:41:40 +02:00
|
|
|
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" \
|
2024-08-07 08:38:03 +02:00
|
|
|
${lib.optionalString stdenv.isLinux "--suffix PATH : ${lib.makeBinPath [zenity]}"} \
|
2023-05-24 16:41:40 +02:00
|
|
|
--suffix LD_LIBRARY_PATH : ${lib.makeLibraryPath [libpulseaudio alsa-lib libjack2]} \
|
2024-08-16 23:05:34 +02:00
|
|
|
--set ALSA_PLUGIN_DIR ${alsa-plugins}/lib/alsa-lib/'' + lib.optionalString enableWayland '' \
|
2023-05-24 16:41:40 +02:00
|
|
|
--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
|
2024-08-10 16:58:39 +02:00
|
|
|
for dep in ${SDL2.out} ${alsa-lib.out} ${glew.out}; do
|
2023-05-24 16:41:40 +02:00
|
|
|
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
|
2024-08-16 23:05:34 +02:00
|
|
|
'' + lib.optionalString enableClient installClient
|
|
|
|
+ lib.optionalString enableServer installServer
|
2023-05-24 16:41:40 +02:00
|
|
|
+ ''
|
2021-01-12 20:17:11 +01:00
|
|
|
runHook postInstall
|
2020-01-26 16:14:02 +01:00
|
|
|
'';
|
|
|
|
|
2023-12-10 09:44:47 +01:00
|
|
|
postGradleUpdate = ''
|
|
|
|
# this fetches non-gradle dependencies
|
|
|
|
cd ../Arc
|
|
|
|
gradle preJni
|
|
|
|
'';
|
|
|
|
|
|
|
|
passthru.tests.nixosTest = nixosTests.mindustry;
|
2023-01-15 00:28:32 +01:00
|
|
|
|
2024-08-16 23:05:34 +02:00
|
|
|
meta = {
|
2020-01-13 11:01:29 +01:00
|
|
|
homepage = "https://mindustrygame.github.io/";
|
|
|
|
downloadPage = "https://github.com/Anuken/Mindustry/releases";
|
|
|
|
description = "Sandbox tower defense game";
|
2024-08-16 23:05:34 +02:00
|
|
|
sourceProvenance = with lib.sourceTypes; [
|
2022-06-04 20:07:20 +02:00
|
|
|
fromSource
|
|
|
|
binaryBytecode # deps
|
|
|
|
];
|
2024-08-16 23:05:34 +02:00
|
|
|
license = lib.licenses.gpl3Plus;
|
|
|
|
maintainers = with lib.maintainers; [ chkno fgaz thekostins ];
|
|
|
|
platforms = lib.platforms.all;
|
2023-12-10 09:44:47 +01:00
|
|
|
# TODO alsa-lib is linux-only, figure out what dependencies are required on Darwin
|
|
|
|
broken = enableClient && stdenv.isDarwin;
|
2020-01-13 11:01:29 +01:00
|
|
|
};
|
|
|
|
}
|