Minecraft server config
This commit is contained in:
@@ -123,6 +123,9 @@
|
||||
neovim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
|
||||
wget
|
||||
tmux
|
||||
git
|
||||
curl
|
||||
unzip
|
||||
];
|
||||
|
||||
# Enable the OpenSSH daemon.
|
||||
@@ -147,17 +150,68 @@
|
||||
|
||||
networking.firewall.enable = false;
|
||||
|
||||
systemd.user.services.tmux = {
|
||||
description = "Tmux session manager";
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "default.target" ];
|
||||
systemd.services.minecraft-setup = {
|
||||
description = "Minecraft Server Initial Setup";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" "minecraft-setup.service" ]; # wait for setup
|
||||
requires = [ "minecraft-setup.service" ]; # and fail if setup fails
|
||||
|
||||
# Only run if setup hasn't been completed yet
|
||||
unitConfig.ConditionPathExists = "!/home/h3lp/mineserver/.setup-done";
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart = "${pkgs.tmux}/bin/tmux new -A -s main";
|
||||
Restart = "always";
|
||||
RestartSec = 5;
|
||||
Type = "oneshot";
|
||||
User = "h3lp";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
|
||||
script = ''
|
||||
set -e
|
||||
|
||||
MINESERVER=/home/h3lp/mineserver
|
||||
TMPDIR=$(mktemp -d)
|
||||
|
||||
# 1) Clone repo and checkout cavemen branch
|
||||
${pkgs.git}/bin/git clone --branch cavemen \
|
||||
https://gitea.20111511.xyz/h3lp/autodeploy.git "$TMPDIR/autodeploy"
|
||||
|
||||
# 2) Read env vars from minecraft.env
|
||||
source "$TMPDIR/autodeploy/minecraft.env"
|
||||
|
||||
# 3) Download and extract server pack to /home/h3lp/mineserver
|
||||
mkdir -p "$MINESERVER"
|
||||
${pkgs.curl}/bin/curl -L "$SERVERPACK" -o "$TMPDIR/serverpack.tar.xz"
|
||||
${pkgs.gnutar}/bin/tar -xJf "$TMPDIR/serverpack.tar.xz" -C "$MINESERVER"
|
||||
|
||||
# 4) Download and extract world to /home/h3lp/mineserver/world
|
||||
mkdir -p "$MINESERVER/world"
|
||||
${pkgs.curl}/bin/curl -L "$WORLD" -o "$TMPDIR/world.tar.xz"
|
||||
# world.tar.xz contains world folder, otherwise use "$MINESERVER/world"
|
||||
${pkgs.gnutar}/bin/tar -xJf "$TMPDIR/world.tar.xz" -C "$MINESERVER"
|
||||
|
||||
# 5) Copy cavemen/* files over, overwriting existing
|
||||
cp -rf "$TMPDIR/autodeploy/cavemen/." "$MINESERVER/"
|
||||
chmod +x "$MINESERVER/nixrunserver.sh"
|
||||
|
||||
# Cleanup and mark setup as done
|
||||
rm -rf "$TMPDIR"
|
||||
touch "$MINESERVER/.setup-done"
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.services.minecraft = {
|
||||
description = "Minecraft Server";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "forking";
|
||||
User = "h3lp";
|
||||
WorkingDirectory = "/home/h3lp/mineserver";
|
||||
ExecStart = "${pkgs.tmux}/bin/tmux new-session -d -s minecraft /home/h3lp/mineserver/nixrunserver.sh";
|
||||
ExecStop = "${pkgs.tmux}/bin/tmux send-keys -t minecraft 'stop' Enter";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user