62 lines
1.3 KiB
Nix
62 lines
1.3 KiB
Nix
{
|
|
pkgs,
|
|
lib,
|
|
config,
|
|
...
|
|
}:
|
|
with lib;
|
|
let
|
|
serverStdinPath = config.systemd.sockets.minecraft-server.socketConfig.ListenFIFO;
|
|
in
|
|
{
|
|
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;
|
|
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";
|
|
};
|
|
};
|
|
}
|