minecraft-server: add update script (#88514)

This commit is contained in:
Kloenk 2020-06-02 18:48:53 +02:00 committed by GitHub
parent b846306950
commit 472283589c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View file

@ -4,9 +4,9 @@ stdenv.mkDerivation {
version = "1.15.2";
src = fetchurl {
url =
"https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jar";
sha256 = "12kynrpxgcdg8x12wcvwkxka0fxgm5siqg8qq0nnmv0443f8dkw0";
url = "https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jar";
# sha1 because that comes from mojang via api
sha1 = "bb2b6b1aefcd70dfd1892149ac3a215f6c636b07";
};
preferLocalBuild = true;
@ -25,6 +25,8 @@ stdenv.mkDerivation {
phases = "installPhase";
passthru.updateScript = ./update.sh;
meta = with stdenv.lib; {
description = "Minecraft Server";
homepage = "https://minecraft.net";

View file

@ -0,0 +1,21 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq common-updater-scripts
BASEDIR="$(dirname "$0")"
# get current release version
versions=$(curl -s 'https://launchermeta.mojang.com/mc/game/version_manifest.json')
version=$(echo $versions | jq .latest.release)
url=$(echo $versions | jq -r ".versions[] | select(.id == $version) | .url")
# get current server.jar
versions=$(curl -s $url | jq .downloads.server)
sha1=$(echo $versions | jq .sha1)
url=$(echo $versions | jq .url)
echo $version: $url:$sha1
# change default.nix
sed -i "s/version = \"[0-9.]*\";/version = ${version};/g" "$BASEDIR/default.nix"
sed -i "s+url = \"[a-zA-Z0-9/:.]*/server.jar\";+url = $url;+g" "$BASEDIR/default.nix"
sed -i "s/sha1 = \"[a-zA-Z0-9]*\";/sha1 = ${sha1};/g" "$BASEDIR/default.nix"