Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mindustry,mindustry-server: make it possible to choose what to build (server and/or client) #78558

Merged
1 commit merged into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions pkgs/games/mindustry/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# any build is allowed, so this parameter acts as a simple whitelist.
# Takes the package version and returns the build version.
, makeBuildVersion ? (v: v)
, enableClient ? true
, enableServer ? true
}:

let
Expand Down Expand Up @@ -52,6 +54,9 @@ let
pname = "${pname}-deps";
inherit version src postPatch;
nativeBuildInputs = [ gradle_5 perl ];
# Here we build 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 = ''
export GRADLE_USER_HOME=$(mktemp -d)
gradle --no-daemon desktop:dist -Pbuildversion=${buildVersion}
Expand All @@ -68,31 +73,49 @@ let
outputHash = "16k058fw9yk89adx8j1708ynfri5yizmmvh49prls9slw4hipffb";
};

in stdenv.mkDerivation rec {
inherit pname version src postPatch;

nativeBuildInputs = [ gradle_5 makeWrapper ];

buildPhase = ''
export GRADLE_USER_HOME=$(mktemp -d)
# point to offline repo
sed -ie "s#mavenLocal()#mavenLocal(); maven { url '${deps}' }#g" build.gradle
# Separate commands for building and installing the server and the client
buildClient = ''
gradle --offline --no-daemon desktop:dist -Pbuildversion=${buildVersion}
'';
buildServer = ''
gradle --offline --no-daemon server:dist -Pbuildversion=${buildVersion}
'';

installPhase = ''
installClient = ''
install -Dm644 desktop/build/libs/Mindustry.jar $out/share/mindustry.jar
install -Dm644 server/build/libs/server-release.jar $out/share/mindustry-server.jar
mkdir $out/bin
mkdir -p $out/bin
makeWrapper ${jre}/bin/java $out/bin/mindustry \
--prefix LD_LIBRARY_PATH : ${libpulseaudio}/lib \
--add-flags "-jar $out/share/mindustry.jar"
makeWrapper ${jre}/bin/java $out/bin/mindustry-server \
--add-flags "-jar $out/share/mindustry-server.jar"
install -Dm644 core/assets/icons/icon_64.png $out/share/icons/hicolor/64x64/apps/mindustry.png
install -Dm644 ${desktopItem}/share/applications/Mindustry.desktop $out/share/applications/Mindustry.desktop
'';
installServer = ''
install -Dm644 server/build/libs/server-release.jar $out/share/mindustry-server.jar
mkdir -p $out/bin
makeWrapper ${jre}/bin/java $out/bin/mindustry-server \
--add-flags "-jar $out/share/mindustry-server.jar"
'';

in
assert stdenv.lib.assertMsg (enableClient || enableServer)
"mindustry: at least one of 'enableClient' and 'enableServer' must be true";
stdenv.mkDerivation rec {
inherit pname version src postPatch;

nativeBuildInputs = [ gradle_5 makeWrapper ];

buildPhase = with stdenv.lib; ''
export GRADLE_USER_HOME=$(mktemp -d)
# point to offline repo
sed -ie "s#mavenLocal()#mavenLocal(); maven { url '${deps}' }#g" build.gradle
${optionalString enableClient buildClient}
${optionalString enableServer buildServer}
'';

installPhase = with stdenv.lib; ''
${optionalString enableClient installClient}
${optionalString enableServer installServer}
'';

meta = with stdenv.lib; {
homepage = "https://mindustrygame.github.io/";
Expand Down
5 changes: 5 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23151,6 +23151,11 @@ in

mindustry = callPackage ../games/mindustry { };

mindustry-server = callPackage ../games/mindustry {
enableClient = false;
enableServer = true;
};

minecraft = callPackage ../games/minecraft { };

minecraft-server = callPackage ../games/minecraft-server { };
Expand Down