From 5dd0633d8c5202a93136ae4c107f6735117d6cfd Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Thu, 16 Dec 2021 01:05:41 +0100 Subject: [PATCH] minecraft-fabric-server --- default.nix | 2 +- pkgs/minecraft-fabric/default.nix | 40 ++++++++++++++++++++++ pkgs/minecraft-fabric/generate-loader.nix | 35 +++++++++++++++++++ pkgs/minecraft-fabric/generate-lock-nix.sh | 20 +++++++++++ pkgs/minecraft-fabric/lock.nix | 16 +++++++++ pkgs/minecraft-server-fabric/default.nix | 40 ---------------------- 6 files changed, 112 insertions(+), 41 deletions(-) create mode 100644 pkgs/minecraft-fabric/default.nix create mode 100644 pkgs/minecraft-fabric/generate-loader.nix create mode 100755 pkgs/minecraft-fabric/generate-lock-nix.sh create mode 100644 pkgs/minecraft-fabric/lock.nix delete mode 100644 pkgs/minecraft-server-fabric/default.nix diff --git a/default.nix b/default.nix index 64712d3..14e63e9 100644 --- a/default.nix +++ b/default.nix @@ -46,8 +46,8 @@ rec { wii-u-gc-adapter = pkgs.callPackage ./pkgs/wii-u-gc-adapter { }; - # minecraft-server-fabric = pkgs.callPackage ./pkgs/minecraft-server-fabric { }; mcaselector = pkgs.callPackage ./pkgs/mcaselector { }; + minecraft-fabric = pkgs.callPackage ./pkgs/minecraft-fabric { }; dowlords-faf-client = pkgs.callPackage ./pkgs/downlords { jdk16 = pkgs.jdk; }; diff --git a/pkgs/minecraft-fabric/default.nix b/pkgs/minecraft-fabric/default.nix new file mode 100644 index 0000000..95d4f2d --- /dev/null +++ b/pkgs/minecraft-fabric/default.nix @@ -0,0 +1,40 @@ +{ callPackage, writeTextFile, writeShellScriptBin, minecraft-server, jre_headless }: + +let + loader = callPackage ./generate-loader.nix {}; + log4j = writeTextFile { + name = "log4j.xml"; + text = '' + + + + + + + + + + + + + + + + + + + + + + + + + + + ''; + }; +in +writeShellScriptBin "minecraft-server" '' + echo "serverJar=${minecraft-server}/lib/minecraft/server.jar" >> fabric-server-launcher.properties + exec ${jre_headless}/bin/java -Dlog4j.configurationFile=${log4j} $@ -jar ${loader} nogui +'' diff --git a/pkgs/minecraft-fabric/generate-loader.nix b/pkgs/minecraft-fabric/generate-loader.nix new file mode 100644 index 0000000..a0b69e7 --- /dev/null +++ b/pkgs/minecraft-fabric/generate-loader.nix @@ -0,0 +1,35 @@ +{ lib, fetchurl, stdenv, unzip, zip, jre_headless }: + +let + lock = import ./lock.nix; + libraries = lib.forEach lock.libraries fetchurl; +in +stdenv.mkDerivation { + name = "fabric-server-launch.jar"; + nativeBuildInputs = [ unzip zip jre_headless ]; + + libraries = libraries; + + buildPhase = '' + for i in $libraries; do + unzip -o $i + done + + cat > META-INF/MANIFEST.MF << EOF + Manifest-Version: 1.0 + Main-Class: net.fabricmc.loader.impl.launch.server.FabricServerLauncher + EOF + + cat > fabric-server-launch.properties << EOF + launch.mainClass=net.fabricmc.loader.impl.launch.knot.KnotServer + EOF + ''; + + installPhase = '' + jar cmvf META-INF/MANIFEST.MF "server.jar" . + zip -d server.jar 'META-INF/*.SF' 'META-INF/*.RSA' 'META-INF/*.DSA' + cp server.jar "$out" + ''; + + phases = [ "buildPhase" "installPhase" ]; +} diff --git a/pkgs/minecraft-fabric/generate-lock-nix.sh b/pkgs/minecraft-fabric/generate-lock-nix.sh new file mode 100755 index 0000000..014e9c7 --- /dev/null +++ b/pkgs/minecraft-fabric/generate-lock-nix.sh @@ -0,0 +1,20 @@ +curl https://meta.fabricmc.net/v2/versions/loader/1.18.1/0.12.12/server/json \ +| jq -r ' + .mainClass, + (.libraries[] + | .url as $url + | .name | split(":") as [$dir, $name, $version] + |"\($name)-\($version).zip|\($url)\($dir|sub("\\.";"/";"g"))/\($name)/\($version)/\($name)-\($version).jar" + )' \ +| { + echo '{' + read mainClass; + echo " mainClass = \"$mainClass\";" + echo " libraries = [" + while IFS="|" read name url; do + hash=$(nix-prefetch-url $url); + echo " { name = \"$name\"; sha256 = \"$hash\"; url = \"$url\"; }" + done + echo " ];" + echo '}' +} diff --git a/pkgs/minecraft-fabric/lock.nix b/pkgs/minecraft-fabric/lock.nix new file mode 100644 index 0000000..c625c45 --- /dev/null +++ b/pkgs/minecraft-fabric/lock.nix @@ -0,0 +1,16 @@ +{ + mainClass = "net.fabricmc.loader.impl.launch.knot.KnotServer"; + libraries = [ + { name = "tiny-mappings-parser-0.3.0+build.17.zip"; sha256 = "19kvhxfk5v01f2rvl7j02vqhn3nd2bh5jsgbk44rpzqv9f6074db"; url = "https://maven.fabricmc.net/net/fabricmc/tiny-mappings-parser/0.3.0+build.17/tiny-mappings-parser-0.3.0+build.17.jar"; } + { name = "sponge-mixin-0.10.7+mixin.0.8.4.zip"; sha256 = "18m5wksd9vjp676cxapkggnz8s3f8j89phln8gy5n8vxlrli8n0d"; url = "https://maven.fabricmc.net/net/fabricmc/sponge-mixin/0.10.7+mixin.0.8.4/sponge-mixin-0.10.7+mixin.0.8.4.jar"; } + { name = "tiny-remapper-0.6.0.zip"; sha256 = "1ynjfxg7cj9rd9c4l450w7yp20p2csjdpnk3mcx5bdkjzhbgvgzf"; url = "https://maven.fabricmc.net/net/fabricmc/tiny-remapper/0.6.0/tiny-remapper-0.6.0.jar"; } + { name = "access-widener-2.0.1.zip"; sha256 = "0a7s4x6dbaa9p59ps7pidzwrs0xwy5i17s35xrgh58i26szlsaxm"; url = "https://maven.fabricmc.net/net/fabricmc/access-widener/2.0.1/access-widener-2.0.1.jar"; } + { name = "asm-9.2.zip"; sha256 = "1xa7kccwmcqcdw1xly6n2frzhk56m8ma9v7h764g73ckf56zxm5r"; url = "https://maven.fabricmc.net/org/ow2/asm/asm/9.2/asm-9.2.jar"; } + { name = "asm-analysis-9.2.zip"; sha256 = "1i1kyirizs5sm2v0f06sdz86mbmyn61vjr9d9p8p5h1i2x9bx3w7"; url = "https://maven.fabricmc.net/org/ow2/asm/asm-analysis/9.2/asm-analysis-9.2.jar"; } + { name = "asm-commons-9.2.zip"; sha256 = "19p04mr14ahndba65v4krbvf4p5syf8wz0fp5i9bnf5270qyak5y"; url = "https://maven.fabricmc.net/org/ow2/asm/asm-commons/9.2/asm-commons-9.2.jar"; } + { name = "asm-tree-9.2.zip"; sha256 = "04g0zb7v65iz4k2m2grdpbv8jjryrzkkw7ww23yfp94i6399pgxa"; url = "https://maven.fabricmc.net/org/ow2/asm/asm-tree/9.2/asm-tree-9.2.jar"; } + { name = "asm-util-9.2.zip"; sha256 = "16759v4hh3ijpf4cglrxybz29x2hiylhsa388y09m2mf679kqnzz"; url = "https://maven.fabricmc.net/org/ow2/asm/asm-util/9.2/asm-util-9.2.jar"; } + { name = "intermediary-1.18.1.zip"; sha256 = "1rfz2gazvnivn6hlqiyjpiaycz8va87n5czy1p6w3lnrlfggj2i9"; url = "https://maven.fabricmc.net/net/fabricmc/intermediary/1.18.1/intermediary-1.18.1.jar"; } + { name = "fabric-loader-0.12.12.zip"; sha256 = "070dpcp7kcj4xr75wp1j6pb1bgfzllwg8xmqk3sk79jfqiqwzizw"; url = "https://maven.fabricmc.net/net/fabricmc/fabric-loader/0.12.12/fabric-loader-0.12.12.jar"; } + ]; +} diff --git a/pkgs/minecraft-server-fabric/default.nix b/pkgs/minecraft-server-fabric/default.nix deleted file mode 100644 index 04f4b3d..0000000 --- a/pkgs/minecraft-server-fabric/default.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ lib, stdenv, fetchurl, jre_headless, minecraft-server }: - -stdenv.mkDerivation rec { - pname = "minecraft-server-fabric"; - version = "0.6.1.51"; - - src = fetchurl { - url = "https://maven.fabricmc.net/net/fabricmc/fabric-installer/${version}/fabric-installer-${version}.jar"; - sha256 = "0cima0n3b37qha9a16kcvjnx9mg231v5wdg1063gxnq3vrxlcw23"; - }; - - preferLocalBuild = true; - - nativeBuildInputs = [ jre_headless ]; - - installPhase = '' - mkdir -p $out/bin $out/lib/minecraft-fabric - cp ${minecraft-server}/lib/minecraft/server.jar $out/lib/minecraft-fabric/server.jar - cp -v $src $out/lib/minecraft-fabric/fabric-installer-${version}.jar - pushd $out/lib/minecraft-fabric - ${jre_headless}/bin/java -jar fabric-installer-${version}.jar server - popd - cat > $out/bin/minecraft-server-fabric << EOF - #!/bin/sh - exec ${jre_headless}/bin/java \$@ -jar $out/lib/minecraft-fabric/fabric-server-launch.jar nogui - EOF - chmod +x $out/bin/minecraft-server - ''; - - phases = "installPhase"; - - meta = with lib; { - description = "minecraft with the fabric modloader"; - license = licenses.unfree; - platforms = platforms.all; - - broken = true; - }; - -}