Enable backups of syncthing state on alto

This commit is contained in:
SebastianStork 2025-04-13 13:54:24 +02:00
parent 4bf2aef5cf
commit 5fb05b38a4
3 changed files with 49 additions and 0 deletions

View file

@ -47,6 +47,7 @@ in
syncthing = { syncthing = {
enable = true; enable = true;
isServer = true; isServer = true;
backups.enable = true;
deviceId = "5R2MH7T-Q2ZZS2P-ZMSQ2UJ-B6VBHES-XYLNMZ6-7FYC27L-4P7MGJ2-FY4ITQD"; deviceId = "5R2MH7T-Q2ZZS2P-ZMSQ2UJ-B6VBHES-XYLNMZ6-7FYC27L-4P7MGJ2-FY4ITQD";
}; };
}; };

View file

@ -0,0 +1,48 @@
{
config,
pkgs,
lib,
...
}:
let
cfg = config.myConfig.syncthing;
in
{
options.myConfig.syncthing.backups.enable = lib.mkEnableOption "";
config = lib.mkIf cfg.backups.enable {
assertions = [
{
assertion = cfg.isServer;
message = "syncthing backups can only be made on a server";
}
];
myConfig.resticBackup.syncthing = {
healthchecks.enable = true;
extraConfig = {
backupPrepareCommand = ''
${lib.getExe' pkgs.systemd "systemctl"} stop syncthing.service
'';
backupCleanupCommand = ''
${lib.getExe' pkgs.systemd "systemctl"} start syncthing.service
'';
paths = [ "/var/lib/syncthing" ];
};
};
environment.systemPackages = [
(pkgs.writeShellApplication {
name = "syncthing-restore";
text = ''
sudo bash -c "
systemctl stop syncthing.service
restic-syncthing restore latest --target /
systemctl start syncthing.service
"
'';
})
];
};
}