-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminecraft.nix
More file actions
116 lines (96 loc) · 3 KB
/
minecraft.nix
File metadata and controls
116 lines (96 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Minecraft configuration loaded from minecraft.toml and whitelist.toml
{ pkgs, lib }:
let
data = lib.importTOML ./minecraft.toml;
whitelistData = lib.importTOML ./whitelist.toml;
fetchMod =
_name: info:
pkgs.fetchurl {
url = "https://cdn.modrinth.com/data/${info.modrinth_id}/versions/${info.version_id}/${info.filename}";
hash = info.hash;
};
filterMods = pred: lib.mapAttrs fetchMod (lib.filterAttrs (_name: pred) data.mods);
neoforgeServer = pkgs.stdenv.mkDerivation {
pname = "neoforge-server";
version = data.neoforge.version;
src = pkgs.fetchurl {
url = data.neoforge.url;
hash = data.neoforge.hash;
nativeBuildInputs = [
pkgs.jdk
pkgs.perl5Packages.strip-nondeterminism
];
downloadToTemp = true;
postFetch = ''
java -jar $downloadedFile --fat-offline --fat $out
strip-nondeterminism -t zip $out
'';
};
phases = [
"buildPhase"
"fixupPhase"
];
nativeBuildInputs = [
pkgs.jdk
pkgs.makeWrapper
];
buildPhase = ''
java -jar $src --install-server .
'';
fixupPhase = ''
mkdir -p "$out/"{lib,bin,share}
unix_args="$({ { grep java | tr ' ' '\n' | grep libraries ; } < run.sh ; })"
unix_args="''${unix_args:1}"
unix_args="''${unix_args/"libraries/"/"$out/lib/"}"
cp -r libraries/. $out/lib/
cp -r run.sh $out/bin/minecraft-server
sed -i $out/bin/minecraft-server \
-e 's~@user_jvm_args.txt~@'"$out"'/share/jvm_args.txt~' \
-e 's~@libraries~@'"$out"'/lib~'
sed -i "$unix_args" \
-e 's~libraries/~'"$out/lib/"'~g' \
-e 's~-DlibraryDirectory=libraries~-DlibraryDirectory='"$out/lib"'~'
touch $out/share/jvm_args.txt
patchShebangs $out/bin/minecraft-server
wrapProgram $out/bin/minecraft-server --prefix PATH : "${pkgs.jdk}/bin"
'';
};
serverMods = filterMods (info: info.server or false);
clientMods = filterMods (info: info.client or false);
serversDat =
pkgs.runCommand "servers-dat"
{
nativeBuildInputs = [ (pkgs.python3.withPackages (ps: [ ps.nbtlib ])) ];
}
''
python3 << 'EOF'
import os
from nbtlib import File, Compound, List, String, Byte
servers = File(gzipped=False)
servers["servers"] = List[Compound]([
Compound({
"name": String("${data.server.name}"),
"ip": String("${data.server.address}"),
"acceptTextures": Byte(1),
})
])
servers.save(os.environ["out"])
EOF
'';
in
{
inherit neoforgeServer serversDat;
minecraftVersion = data.neoforge.minecraft_version;
neoforgeVersion = data.neoforge.version;
serverName = data.server.name;
serverAddress = data.server.address;
whitelist = whitelistData.players;
server = {
mods = serverMods;
modList = lib.attrValues serverMods;
};
client = {
mods = clientMods;
modList = lib.attrValues clientMods;
};
}