mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-22 01:31:33 +01:00
Enable backups of syncthing state on alto
This commit is contained in:
parent
4bf2aef5cf
commit
5fb05b38a4
3 changed files with 49 additions and 0 deletions
48
modules/system/syncthing/backups.nix
Normal file
48
modules/system/syncthing/backups.nix
Normal 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
|
||||
"
|
||||
'';
|
||||
})
|
||||
];
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue