tlaternet-server/pkgs/minecraft/forge-server.nix

65 lines
1.8 KiB
Nix

{ lib, stdenv, fetchurl, jre_headless, runtimeShell }:
let
name = "forge-server";
version = "1.16.5-36.1.1";
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
sha1 = "78e5bd0b19f05136bb25bf3c5be9b64a1d0e850e";
};
unpackCmd = "mkdir -p src; cp $curSrc src/forge-${version}-installer.jar";
# 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";
inherit src unpackCmd;
nativeBuildInputs = [ jre_headless ];
buildPhase = ''
java -jar forge-${version}-installer.jar --installServer installation
'';
installPhase = ''
mkdir -p $out
cp -r installation/forge-${version}.jar installation/libraries $out
'';
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = "lV4UxmSdv/I+HwvnT8CLcHpSKyDvKnldA5/Lw1GsJ/M=";
};
in stdenv.mkDerivation rec {
inherit name version src unpackCmd;
installPhase = ''
mkdir -p $out/{bin,lib/forge}
cp -rv ${deps}/* $out/lib/forge/
cat > $out/bin/forge-server << EOF
#!${runtimeShell}
set -eu
exec ${jre_headless}/bin/java \$@ -jar $out'/lib/forge/forge-${version}.jar' nogui
EOF
chmod +x $out/bin/forge-server
'';
phases = "installPhase";
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;
};
}