65 lines
1.6 KiB
Nix
65 lines
1.6 KiB
Nix
{
|
|
config,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
mkBackup = time: {
|
|
systemd.services."factorio-backup-save-${time}" = {
|
|
description = "Backup factorio saves";
|
|
script = ''
|
|
set -exuo pipefail
|
|
|
|
FILENAME="space-age-$(date --iso=seconds | tr ':' '_').zip"
|
|
DEST_DIR=~lelgenio/Documentos/GameSaves/factorio_saves/space-age-1/${time}
|
|
|
|
mkdir -p "$DEST_DIR"
|
|
cp /var/lib/factorio/saves/default.zip "$DEST_DIR"/$FILENAME
|
|
chown lelgenio "$DEST_DIR" "$DEST_DIR"/$FILENAME
|
|
|
|
# list all files, from oldest to newest
|
|
# remove the last 10 from the list
|
|
# delete the rest
|
|
cd "$DEST_DIR"
|
|
ls | head -n-10 | xargs -r rm -v
|
|
'';
|
|
serviceConfig.Type = "oneshot";
|
|
};
|
|
|
|
systemd.timers."factorio-backup-save-${time}" = {
|
|
timerConfig = {
|
|
# Systemd accepts descriptive names such as "daily"
|
|
# The times are at midnight, Persistent makes sure that the backups get executed
|
|
OnCalendar = time;
|
|
Persistent = true;
|
|
Unit = "factorio-backup-save-${time}.service";
|
|
};
|
|
wantedBy = [ "timers.target" ];
|
|
};
|
|
};
|
|
in
|
|
{
|
|
imports = [
|
|
(mkBackup "daily")
|
|
(mkBackup "monthly")
|
|
];
|
|
|
|
services.factorio = {
|
|
enable = true;
|
|
package = pkgs.my-factorio-headless;
|
|
public = true;
|
|
lan = true;
|
|
openFirewall = true;
|
|
admins = [ "lelgenio" ];
|
|
extraSettingsFile = config.sops.secrets."factorio/server-config.json".path;
|
|
};
|
|
|
|
systemd.services.factorio = {
|
|
after = [ "network-online.target" ];
|
|
wants = [ "network-online.target" ];
|
|
};
|
|
|
|
sops.secrets."factorio/server-config.json" = {
|
|
mode = "777";
|
|
};
|
|
}
|