nixos-config/modules/server/minecraft.nix

62 lines
1.3 KiB
Nix
Raw Permalink Normal View History

2024-10-26 15:15:06 +02:00
{
pkgs,
lib,
config,
...
}:
with lib;
2024-10-29 13:22:54 +01:00
let
serverStdinPath = config.systemd.sockets.minecraft-server.socketConfig.ListenFIFO;
in
2024-10-26 15:15:06 +02:00
{
options.my.server.papermc.enable = mkOption {
type = types.bool;
default = false;
};
config = mkIf config.my.server.papermc.enable {
services.minecraft-server = {
enable = true;
package = pkgs.papermc;
dataDir = "/srv/minecraft";
openFirewall = true;
2024-10-29 13:22:54 +01:00
eula = true;
};
systemd.services."minecraft-server-backup" = {
path = with pkgs; [
gnutar
gzip
];
script = ''
echo 'say Une backup du serveur va commencer dans 1 minute.' > ${serverStdinPath}
sleep 1m
cat << EOF > ${serverStdinPath}
say Sauvegarde en cours...
save-off
save-all
EOF
tar -cpzf /srv/minecraft-backups/backup-$(date -u +%Y%m%d_%H%M%S).tar.gz ${config.services.minecraft-server.dataDir}
cat << EOF > ${serverStdinPath}
save-on
say Sauvegarde terminée !
EOF
# Deleting saves older than 2 weeks
find /srv/minecraft-backups/ -type f -mtime +14 -name 'backup-*.tar.gz' -delete
'';
serviceConfig = {
Type = "oneshot";
User = "root";
};
startAt = "*-*-* 00:00,12:00";
2024-10-26 15:15:06 +02:00
};
};
}