add papermc
This commit is contained in:
parent
180c3293ef
commit
080f3d1e77
16 changed files with 202 additions and 40 deletions
|
@ -37,4 +37,5 @@
|
|||
mautrix-telegram = pkgs.callPackage ./matrix/mautrix-telegram {};
|
||||
python-mautrix = pkgs.python3Packages.callPackage ./python/mautrix.nix {};
|
||||
python-tulir-telethon = pkgs.python3Packages.callPackage ./python/tulir-telethon.nix {};
|
||||
papermc = pkgs.callPackage ./minecraft/papermc {};
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{pkgs, ...}: {
|
||||
mkPleromaEmoji = pkgs.callPackage ./mkPleromaEmoji.nix {};
|
||||
gradleDeps = pkgs.callPackage ./gradleDeps.nix {};
|
||||
}
|
||||
|
|
27
lib/gradleDeps.nix
Normal file
27
lib/gradleDeps.nix
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
stdenv,
|
||||
gradle,
|
||||
openjdk_headless,
|
||||
perl,
|
||||
git,
|
||||
}: {
|
||||
src,
|
||||
sha256,
|
||||
...
|
||||
} @ args:
|
||||
stdenv.mkDerivation ({
|
||||
nativeBuildInputs = [gradle openjdk_headless perl git];
|
||||
buildPhase = ''
|
||||
export GRADLE_USER_HOME=$(mktemp -d)
|
||||
gradle --no-daemon --info -Dorg.gradle.java.home=${openjdk_headless} --write-verification-metadata sha256
|
||||
'';
|
||||
installPhase = ''
|
||||
find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(aar\|jar\|pom\|module\)$' \
|
||||
| perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/maven/$x/$3/$4/$5" #e' \
|
||||
| sh
|
||||
'';
|
||||
outputHashAlgo = "sha256";
|
||||
outputHashMode = "recursive";
|
||||
outputHash = sha256;
|
||||
}
|
||||
// args)
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"version": "1.19.2",
|
||||
"build": 173,
|
||||
"name": "paper-1.19.2-173.jar",
|
||||
"sha256": "533c31763ae447dcd01123bc076869e68fd89b354c65aae0a9b2d128eb84e46f"
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
{pkgs, ...}: let
|
||||
version-info = builtins.fromJSON (builtins.readFile ./paper.json);
|
||||
pname = "paper";
|
||||
mcVersion = version-info.version;
|
||||
buildNum = toString version-info.build;
|
||||
in rec {
|
||||
paper-jar = pkgs.fetchurl {
|
||||
url = "https://papermc.io/api/v2/projects/paper/versions/${mcVersion}/builds/${buildNum}/downloads/${version-info.name}";
|
||||
inherit (version-info) sha256;
|
||||
};
|
||||
papermc = pkgs.stdenvNoCC.mkDerivation {
|
||||
pname = "papermc";
|
||||
version = "${mcVersion}-${buildNum}";
|
||||
|
||||
dontUnpack = true;
|
||||
dontConfigure = true;
|
||||
|
||||
buildPhase = ''
|
||||
cat > minecraft-server << EOF
|
||||
#!${pkgs.bash}/bin/sh
|
||||
exec ${pkgs.openjdk17_headless}/bin/java \$@ -jar $out/share/papermc/papermc.jar nogui
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/share/papermc
|
||||
ln -s ${paper-jar} $out/share/papermc/papermc.jar
|
||||
install -Dm555 -t $out/bin minecraft-server
|
||||
'';
|
||||
};
|
||||
}
|
35
minecraft/papermc-from-source/build.patch
Normal file
35
minecraft/papermc-from-source/build.patch
Normal file
|
@ -0,0 +1,35 @@
|
|||
diff --git a/build.gradle.kts b/build.gradle.kts
|
||||
index 5341c25fb..7450bb8f8 100644
|
||||
--- a/build.gradle.kts
|
||||
+++ b/build.gradle.kts
|
||||
@@ -4,7 +4,6 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent
|
||||
plugins {
|
||||
java
|
||||
`maven-publish`
|
||||
- id("com.github.johnrengelman.shadow") version "7.1.2" apply false
|
||||
id("io.papermc.paperweight.core") version "1.3.8"
|
||||
}
|
||||
|
||||
diff --git a/settings.gradle.kts b/settings.gradle.kts
|
||||
index 18cf95a32..91037a630 100644
|
||||
--- a/settings.gradle.kts
|
||||
+++ b/settings.gradle.kts
|
||||
@@ -7,6 +7,18 @@ pluginManagement {
|
||||
}
|
||||
}
|
||||
|
||||
+buildscript {
|
||||
+ repositories {
|
||||
+ gradlePluginPortal()
|
||||
+ maven {
|
||||
+ url = uri("https://plugins.gradle.org/m2/")
|
||||
+ }
|
||||
+ }
|
||||
+ dependencies {
|
||||
+ classpath("gradle.plugin.com.github.johnrengelman:shadow:7.1.2")
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
rootProject.name = "paper"
|
||||
|
||||
for (name in listOf("Paper-API", "Paper-Server", "Paper-MojangAPI")) {
|
32
minecraft/papermc-from-source/default.nix
Normal file
32
minecraft/papermc-from-source/default.nix
Normal file
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
stdenv,
|
||||
callPackage,
|
||||
gradle,
|
||||
openjdk_headless,
|
||||
git,
|
||||
}: let
|
||||
src = callPackage ./source.nix {};
|
||||
deps = callPackage ./deps.nix {};
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
pname = "papermc";
|
||||
version = src.passthru.source.date;
|
||||
inherit src;
|
||||
nativeBuildInputs = [
|
||||
gradle
|
||||
openjdk_headless
|
||||
git
|
||||
];
|
||||
patchPhase = ''
|
||||
sed -i 's#mavenCentral..#maven("${deps}/maven")#g' build.gradle.kts
|
||||
sed -i 's#gradlePluginPortal..#maven("${deps}/maven")#g' settings.gradle.kts
|
||||
'';
|
||||
buildPhase = ''
|
||||
export GRADLE_USER_HOME=$(mktemp -d)
|
||||
gradle --offline --no-daemon --debug -Dorg.gradle.java.home=${openjdk_headless} applyPatches
|
||||
gradle --offline --no-daemon --info -Dorg.gradle.java.home=${openjdk_headless} createReobfBundlerJar
|
||||
'';
|
||||
installPhase = ''
|
||||
find build/lib
|
||||
'';
|
||||
}
|
1
minecraft/papermc-from-source/deps.hash
Normal file
1
minecraft/papermc-from-source/deps.hash
Normal file
|
@ -0,0 +1 @@
|
|||
sha256-w9lNjuMZiiuB73+e95phSu31IldeDowgv8eXRKcF/tg=
|
15
minecraft/papermc-from-source/deps.nix
Normal file
15
minecraft/papermc-from-source/deps.nix
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
callPackage,
|
||||
writeScript,
|
||||
}: let
|
||||
src = callPackage ./source.nix {};
|
||||
gradleDeps = callPackage ../../lib/gradleDeps.nix {};
|
||||
in (gradleDeps {
|
||||
pname = "paper-deps";
|
||||
version = src.passthru.source.date;
|
||||
inherit src;
|
||||
sha256 = builtins.readFile ./deps.hash;
|
||||
passthru.updateScript = writeScript "update-paper-deps" ''
|
||||
${../../scripts/update-gradle.sh} minecraft/papermc/deps.nix minecraft/papermc/deps.hash
|
||||
'';
|
||||
})
|
11
minecraft/papermc-from-source/source.json
Normal file
11
minecraft/papermc-from-source/source.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"url": "https://github.com/PaperMC/Paper",
|
||||
"rev": "bd496d0e0ddd5b4ec7702fde28e0fe9b4b703e0f",
|
||||
"date": "2022-09-28T04:27:26+01:00",
|
||||
"path": "/nix/store/qh5sza3l8kbbfcplkjjx81q32rjc47il-Paper",
|
||||
"sha256": "0w6ivh36da46lwkrf88fdbnngdac9ss41v3qvydgqsiicf150x0y",
|
||||
"fetchLFS": false,
|
||||
"fetchSubmodules": true,
|
||||
"deepClone": false,
|
||||
"leaveDotGit": true
|
||||
}
|
19
minecraft/papermc-from-source/source.nix
Normal file
19
minecraft/papermc-from-source/source.nix
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
applyPatches,
|
||||
fetchgit,
|
||||
writeScript,
|
||||
}: let
|
||||
source = builtins.fromJSON (builtins.readFile ./source.json);
|
||||
in
|
||||
(applyPatches {
|
||||
patches = [./build.patch];
|
||||
src = fetchgit {
|
||||
inherit (source) url rev sha256 fetchLFS fetchSubmodules deepClone leaveDotGit;
|
||||
};
|
||||
})
|
||||
.overrideAttrs (_: {
|
||||
passthru.source = source;
|
||||
passthru.updateScript = writeScript "update-paper-git" ''
|
||||
${../../scripts/update-git.sh} https://github.com/PaperMC/Paper minecraft/papermc/source.json "--leave-dotGit --fetch-submodules"
|
||||
'';
|
||||
})
|
41
minecraft/papermc/default.nix
Normal file
41
minecraft/papermc/default.nix
Normal file
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
stdenvNoCC,
|
||||
openjdk_headless,
|
||||
callPackage,
|
||||
lib,
|
||||
writeScript,
|
||||
}: let
|
||||
paperJar = callPackage ./jar.nix {};
|
||||
versionInfo = builtins.fromJSON (builtins.readFile ./paper.json);
|
||||
in
|
||||
stdenvNoCC.mkDerivation {
|
||||
preferLocalBuild = true;
|
||||
pname = "paper";
|
||||
version = "${versionInfo.version}.${toString versionInfo.build}";
|
||||
dontUnpack = true;
|
||||
dontConfigure = true;
|
||||
|
||||
buildPhase = ''
|
||||
cat > minecraft-server << EOF
|
||||
#!/bin/sh
|
||||
exec ${openjdk_headless}/bin/java \$@ -jar $out/share/papermc/papermc.jar nogui
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/share/papermc
|
||||
ln -s ${paperJar} $out/share/papermc/papermc.jar
|
||||
install -Dm555 -t $out/bin minecraft-server
|
||||
'';
|
||||
|
||||
meta = {
|
||||
description = "High performance minecraft server";
|
||||
# This is a fun one because while papermc’s patches are released under the gpl, they apply patches to a proprietary binary which they then execute, so
|
||||
license = lib.licenses.gpl3;
|
||||
unfree = true;
|
||||
};
|
||||
passthru.updateScript = writeScript "update-paper" '' #! /usr/bin/env nix-shell
|
||||
#! nix-shell -i bash -p curl jq
|
||||
|
||||
curl -L https://papermc.io/api/v2/projects/paper/versions/1.19.2/builds | jq '{"version":.version, "build":.builds[-1].build, "name":.builds[-1].downloads.application.name, "sha256":.builds[-1].downloads.application.sha256}' > minecraft/papermc/paper.json
|
||||
'';
|
||||
}
|
7
minecraft/papermc/jar.nix
Normal file
7
minecraft/papermc/jar.nix
Normal file
|
@ -0,0 +1,7 @@
|
|||
{fetchurl}: let
|
||||
versionInfo = builtins.fromJSON (builtins.readFile ./paper.json);
|
||||
in
|
||||
fetchurl {
|
||||
url = "https://papermc.io/api/v2/projects/paper/versions/${versionInfo.version}/builds/${toString versionInfo.build}/downloads/${versionInfo.name}";
|
||||
inherit (versionInfo) sha256;
|
||||
}
|
6
minecraft/papermc/paper.json
Normal file
6
minecraft/papermc/paper.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"version": "1.19.2",
|
||||
"build": 177,
|
||||
"name": "paper-1.19.2-177.jar",
|
||||
"sha256": "4f16eb2cb417049109be7ba679af79b26ce164b9aa8ff5686aaec432706d0a08"
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
#! /usr/bin/env nix-shell
|
||||
#! nix-shell -i bash -p curl jq
|
||||
|
||||
curl -L https://papermc.io/api/v2/projects/paper/versions/1.19.2/builds | jq '{"version":.version, "build":.builds[-1].build, "name":.builds[-1].downloads.application.name, "sha256":.builds[-1].downloads.application.sha256}' > paper.json
|
6
scripts/update-gradle.sh
Executable file
6
scripts/update-gradle.sh
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p nix-prefetch
|
||||
PACKAGE_PATH=$1
|
||||
WRITE_PATH=$2
|
||||
|
||||
nix-prefetch "{ sha256 }: (callPackage (import $PACKAGE_PATH) { }).overrideAttrs (_: { outputHash = sha256; })" > $WRITE_PATH
|
Reference in a new issue