2 last months
This commit is contained in:
parent
f845745874
commit
15b909473e
63 changed files with 963 additions and 1103 deletions
82
hosts/greatyamada/services/minecraft/default.nix
Normal file
82
hosts/greatyamada/services/minecraft/default.nix
Normal file
|
@ -0,0 +1,82 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
cfg = config.services.minecraft-server;
|
||||
|
||||
bukkitConfigFile = ./bukkit.yml;
|
||||
|
||||
spigotConfigFile = ./spigot.yml;
|
||||
|
||||
cfgToString = v: if builtins.isBool v then lib.boolToString v else toString v;
|
||||
|
||||
eulaFile = builtins.toFile "eula.txt" ''
|
||||
# eula.txt managed by NixOS configuration
|
||||
eula=true
|
||||
'';
|
||||
|
||||
opsFile = builtins.toFile "ops.json" (builtins.toJSON [{
|
||||
name = "aveeeeryy";
|
||||
uuid = "b65a1bc3-c6a0-4e8c-99b8-3538cfec0cfc";
|
||||
level = 4;
|
||||
bypassesPlayerLimit = true;
|
||||
}]);
|
||||
|
||||
serverPropertiesFile = pkgs.writeText "server.properties" (''
|
||||
# server.properties managed by NixOS configuration
|
||||
'' + lib.concatStringsSep "\n"
|
||||
(lib.mapAttrsToList (n: v: "${n}=${cfgToString v}") cfg.serverProperties));
|
||||
|
||||
serverIcon = ./server-icon.png;
|
||||
|
||||
in {
|
||||
imports = [ ./plugins ];
|
||||
services.minecraft-server = {
|
||||
enable = true;
|
||||
package = pkgs.papermc.override {
|
||||
mcVersion = "1.20.6";
|
||||
buildNum = "147";
|
||||
};
|
||||
declarative = true;
|
||||
eula = true;
|
||||
openFirewall = true;
|
||||
jvmOpts =
|
||||
"-Xms4G -Xmx4G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true";
|
||||
serverProperties = {
|
||||
difficulty = "hard";
|
||||
enable-rcon = false;
|
||||
enforce-secure-profile = false;
|
||||
enforce-whitelist = true;
|
||||
hide-online-players = true;
|
||||
motd = "NixOS server";
|
||||
online-mode = true;
|
||||
pvp = false;
|
||||
server-port = 13914;
|
||||
spawn-protection = 0;
|
||||
white-list = true;
|
||||
};
|
||||
dataDir = import ./data-directory.nix;
|
||||
};
|
||||
# Overriden to have a non-declarative whitelist
|
||||
systemd.services.minecraft-server.preStart = lib.mkForce ''
|
||||
ln -sf ${eulaFile} eula.txt
|
||||
cp -f ${bukkitConfigFile} bukkit.yml
|
||||
chmod +w bukkit.yml
|
||||
cp -f ${spigotConfigFile} spigot.yml
|
||||
chmod +w spigot.yml
|
||||
cp -f ${opsFile} ops.json
|
||||
chmod +w ops.json
|
||||
ln -sf ${serverIcon} server-icon.png
|
||||
if [ -e .declarative ]; then
|
||||
# Was declarative before, no need to back up anything
|
||||
cp -f ${serverPropertiesFile} server.properties
|
||||
else
|
||||
# Declarative for the first time, backup stateful files
|
||||
cp -b --suffix=.stateful ${serverPropertiesFile} server.properties
|
||||
|
||||
# server.properties must have write permissions, because every time
|
||||
# the server starts it first parses the file and then regenerates it..
|
||||
chmod +w server.properties
|
||||
echo "Autogenerated file that signifies that this server configuration is managed declaratively by NixOS" \
|
||||
> .declarative
|
||||
fi
|
||||
'';
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue