iac/nixos/hosts/asxpio-services/minecraft.nix
Sergei Poljanski 55f3036574
All checks were successful
nixos / nixos (push) Successful in 28s
services: restart Minecraft after it exits on its own
AutoUpdateGeyser restarts the server with /restart. Paper finds no
start script, stops and exits 0, and Restart=always should start it
again. The module binds the stdin socket to the service, though: the
exit stopped the socket, the socket's stop cancelled the restart, and
the server stayed down from 2026-11-17 16:01 until started by hand.

PartOf keeps the socket across an exit and still stops it with the
service. FlushPending already drops the "stop" ExecStop leaves in the
FIFO.

Assisted-by: Claude:opus-5-5
2026-11-18 12:49:38 +04:00

48 lines
1.7 KiB
Nix

# Paper. The world, plugins and server.properties are data in
# /var/lib/minecraft and not managed here; Geyser (a plugin) adds the
# Bedrock port.
{ lib, pkgs, ... }:
{
services.minecraft-server = {
enable = true;
eula = true;
package = pkgs.papermc;
jvmOpts = "-Xmx4G -Xms2G";
};
asxpio.waitForData = [ "minecraft-server" ];
systemd.services.minecraft-server = {
# Stopping saves the world first
serviceConfig.TimeoutStopSec = 120;
# Geyser lists the network interfaces (netlink) for Bedrock's
# signalling; the module allows IP sockets only
serviceConfig.RestrictAddressFamilies = lib.mkForce [
"AF_INET"
"AF_INET6"
"AF_UNIX"
"AF_NETLINK"
];
# Geyser unpacks native libraries that expect a usual Linux around
# them (libcrypto, libstdc++)
environment.LD_LIBRARY_PATH = lib.makeLibraryPath [
pkgs.openssl
pkgs.stdenv.cc.cc.lib
];
};
# AutoUpdateGeyser restarts the server with /restart; Paper finds no
# start script and exits 0, and systemd must start it again. The
# module binds the stdin socket to the service, so the exit stopped
# the socket and the socket's stop cancelled Restart=always. PartOf
# keeps the socket across an exit and still stops it with the service.
systemd.services.minecraft-server.serviceConfig.RestartSec = 10;
systemd.sockets.minecraft-server = {
bindsTo = lib.mkForce [ ];
partOf = [ "minecraft-server.service" ];
};
networking.firewall.allowedTCPPorts = [ 25565 ];
asxpio.security.ports = [
"tcp/25565/java"
"tcp/19132/java" # Geyser's signalling
"udp/19132/java" # Bedrock
];
networking.firewall.allowedUDPPorts = [ 19132 ];
}