From 71d783ec11d1e87f39a15adac4269b517b986093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= Date: Sun, 25 Apr 2021 21:05:47 +0100 Subject: [PATCH 1/2] forge-server: Fix potential duplicate definition of `config` --- configuration/services/minecraft.nix | 2 +- pkgs/minecraft/forge-server.nix | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configuration/services/minecraft.nix b/configuration/services/minecraft.nix index a524313..c3831aa 100644 --- a/configuration/services/minecraft.nix +++ b/configuration/services/minecraft.nix @@ -67,7 +67,7 @@ in { (pkgs.local.forge-server.override { jre_headless = pkgs.jdk11_headless; mods = pkgs.local.voor-kia; - config = ./configs/minecraft/voor-kia/config; + modConfig = ./configs/minecraft/voor-kia/config; defaultconfigs = ./configs/minecraft/voor-kia/defaultconfigs; }) ]; diff --git a/pkgs/minecraft/forge-server.nix b/pkgs/minecraft/forge-server.nix index a01367e..9bb2cdd 100644 --- a/pkgs/minecraft/forge-server.nix +++ b/pkgs/minecraft/forge-server.nix @@ -1,5 +1,5 @@ { lib, stdenv, fetchurl, busybox, coreutils, jre_headless, runtimeShell -, mods ? null, config ? null, defaultconfigs ? null }: +, mods ? null, modConfig ? null, defaultconfigs ? null }: let name = "forge-server"; @@ -59,11 +59,11 @@ in stdenv.mkDerivation rec { # Delete any previous config directories so that they can be updated ${busybox}/bin/rm -fr config defaultconfigs - ${lib.optionalString (config != null) '' + ${lib.optionalString (modConfig != null) '' # Copy the specified configs into the directory. Forge (and # mods) will try to write here, so we cannot symlink. ${busybox}/bin/mkdir -p config - ${busybox}/bin/cp -r '${config}'/* config + ${busybox}/bin/cp -r '${modConfig}'/* config ${busybox}/bin/chmod -R u+w config ''} -- 2.44.1 From c3aea6e305d1f0125d2f22d4500c2f9b0c124a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= Date: Sun, 25 Apr 2021 21:06:07 +0100 Subject: [PATCH 2/2] forge-server: Fix issues caused by the installer's reproducibility This seems to mostly be due to mcpatcher patches being not quite bit-for-bit reproducible. Oh well, at least this derivation should work now. --- pkgs/minecraft/forge-server.nix | 35 +++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/pkgs/minecraft/forge-server.nix b/pkgs/minecraft/forge-server.nix index 9bb2cdd..f94515a 100644 --- a/pkgs/minecraft/forge-server.nix +++ b/pkgs/minecraft/forge-server.nix @@ -13,34 +13,55 @@ let unpackCmd = "mkdir -p src; cp $curSrc src/forge-${version}-installer.jar"; + nativeBuildInputs = [ jre_headless ]; + # 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; + inherit src unpackCmd nativeBuildInputs; - 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 + + # 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/ + + # The forge installer also insists on re-creating this file. + rm installation/libraries/de/oceanlabs/mcp/mcp_config/*/mcp_config-*-mappings.txt + + cp -r installation/* $out ''; outputHashAlgo = "sha256"; outputHashMode = "recursive"; - outputHash = "lV4UxmSdv/I+HwvnT8CLcHpSKyDvKnldA5/Lw1GsJ/M="; + outputHash = "ZRU9ytoF1BXRQ4hx2ehPgqan6vX4l2yomzNDOOWdm0Q="; }; in stdenv.mkDerivation rec { - inherit name version src unpackCmd; + 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/ + java -jar forge-${version}-installer.jar --offline --installServer installation/ + ''; installPhase = '' mkdir -p $out/{bin,lib/forge} - cp -rv ${deps}/* $out/lib/forge/ + + cp -r installation/{forge-${version}.jar,libraries} $out/lib/forge/ cat > $out/bin/forge-server << EOF #!${runtimeShell} @@ -81,8 +102,6 @@ in stdenv.mkDerivation rec { chmod +x $out/bin/forge-server ''; - phases = "installPhase"; - meta = with lib; { description = "Forge Minecraft Server"; homepage = "https://files.minecraftforge.net/"; -- 2.44.1