2021-04-25 04:50:30 +01:00
|
|
|
{ lib, stdenv, fetchurl, busybox, coreutils, jre_headless, runtimeShell
|
2021-04-25 21:05:47 +01:00
|
|
|
, mods ? null, modConfig ? null, defaultconfigs ? null }:
|
2021-04-22 22:32:54 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
name = "forge-server";
|
2021-07-26 00:26:42 +01:00
|
|
|
version = "1.16.5-36.2.2";
|
2021-04-22 22:32:54 +01:00
|
|
|
mirror = "https://files.minecraftforge.net/maven/net/minecraftforge/forge";
|
|
|
|
src = fetchurl {
|
|
|
|
url = "${mirror}/${version}/forge-${version}-installer.jar";
|
|
|
|
# Forge doesn't seem to like newer shas
|
2021-07-26 00:26:42 +01:00
|
|
|
sha1 = "e97821e5431bdcaa46e12048769922e2cdb5e2e1";
|
2021-04-22 22:32:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
unpackCmd = "mkdir -p src; cp $curSrc src/forge-${version}-installer.jar";
|
|
|
|
|
2021-04-25 21:06:07 +01:00
|
|
|
nativeBuildInputs = [ jre_headless ];
|
|
|
|
|
2021-04-22 22:32:54 +01:00
|
|
|
# Somewhat evil pre-install step to run through the network
|
|
|
|
# dependency resolution forge needs. This is also common for gradle
|
|
|
|
# projects, so I think this is ok-ish here, though ideally I'd
|
|
|
|
# identify all the dependencies and package them as well.
|
|
|
|
deps = stdenv.mkDerivation {
|
|
|
|
name = "${name}-deps";
|
2021-04-25 21:06:07 +01:00
|
|
|
inherit src unpackCmd nativeBuildInputs;
|
2021-04-22 22:32:54 +01:00
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
java -jar forge-${version}-installer.jar --installServer installation
|
|
|
|
'';
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
2021-04-25 21:06:07 +01:00
|
|
|
|
|
|
|
# The installer will patch the Minecraft server jar in some
|
|
|
|
# fashion, and include it in "libraries". This'd be fine, if the
|
|
|
|
# patch was bit-for-bit reproducible. Sadly it is not, so we
|
|
|
|
# defer this to the *real* package build.
|
|
|
|
rm -r installation/libraries/net/minecraft/
|
|
|
|
|
|
|
|
cp -r installation/* $out
|
2021-04-22 22:32:54 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
outputHashMode = "recursive";
|
2021-07-26 00:26:42 +01:00
|
|
|
outputHash = "VuUGc5JnzcRhDt9aaGrU+yUrJILVdU2vzv1PxLwdAig=";
|
2021-04-22 22:32:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
in stdenv.mkDerivation rec {
|
2021-04-25 21:06:07 +01:00
|
|
|
inherit name version src unpackCmd nativeBuildInputs;
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
mkdir -p installation
|
|
|
|
|
|
|
|
# Take the input deps and patch the Minecraft server jar into our
|
|
|
|
# libraries to create the package.
|
|
|
|
cp -rv ${deps}/* installation/
|
2021-04-25 22:37:33 +01:00
|
|
|
chmod -R +w installation/
|
2021-04-25 21:06:07 +01:00
|
|
|
java -jar forge-${version}-installer.jar --offline --installServer installation/
|
|
|
|
'';
|
2021-04-22 22:32:54 +01:00
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/{bin,lib/forge}
|
2021-04-25 21:06:07 +01:00
|
|
|
|
|
|
|
cp -r installation/{forge-${version}.jar,libraries} $out/lib/forge/
|
2021-04-22 22:32:54 +01:00
|
|
|
|
|
|
|
cat > $out/bin/forge-server << EOF
|
|
|
|
#!${runtimeShell}
|
|
|
|
set -eu
|
|
|
|
|
2021-04-25 04:50:30 +01:00
|
|
|
# Delete any previous mods directory so that it can be updated
|
|
|
|
${busybox}/bin/rm -fr mods
|
|
|
|
|
|
|
|
${lib.optionalString (mods != null) ''
|
|
|
|
# Copy the specified mods into the directory. Note that, sadly,
|
|
|
|
# forge doesn't support symlinks here.
|
|
|
|
${busybox}/bin/mkdir -p mods
|
|
|
|
${busybox}/bin/cp -r '${mods}/mods/'*.jar mods
|
|
|
|
''}
|
|
|
|
|
|
|
|
# Delete any previous config directories so that they can be updated
|
|
|
|
${busybox}/bin/rm -fr config defaultconfigs
|
|
|
|
|
2021-04-25 21:05:47 +01:00
|
|
|
${lib.optionalString (modConfig != null) ''
|
2021-04-25 04:50:30 +01:00
|
|
|
# Copy the specified configs into the directory. Forge (and
|
|
|
|
# mods) will try to write here, so we cannot symlink.
|
|
|
|
${busybox}/bin/mkdir -p config
|
2021-04-25 21:05:47 +01:00
|
|
|
${busybox}/bin/cp -r '${modConfig}'/* config
|
2021-04-25 04:50:30 +01:00
|
|
|
${busybox}/bin/chmod -R u+w config
|
|
|
|
''}
|
|
|
|
|
|
|
|
${lib.optionalString (defaultconfigs != null) ''
|
|
|
|
# Copy the specified configs into the directory. Forge (and
|
|
|
|
# mods) will try to write here, so we cannot symlink.
|
|
|
|
${busybox}/bin/mkdir -p defaultconfigs
|
|
|
|
${busybox}/bin/cp -r '${defaultconfigs}'/* defaultconfigs
|
|
|
|
${busybox}/bin/chmod -R u+w defaultconfigs
|
|
|
|
''}
|
|
|
|
|
2021-04-22 22:32:54 +01:00
|
|
|
exec ${jre_headless}/bin/java \$@ -jar $out'/lib/forge/forge-${version}.jar' nogui
|
|
|
|
EOF
|
|
|
|
|
|
|
|
chmod +x $out/bin/forge-server
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "Forge Minecraft Server";
|
|
|
|
homepage = "https://files.minecraftforge.net/";
|
|
|
|
# Forge itself is open source, but this package pulls in
|
|
|
|
# minecraft.
|
|
|
|
license = licenses.unfreeRedistributable;
|
|
|
|
platforms = platforms.unix;
|
|
|
|
};
|
|
|
|
}
|