mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 18:41:34 +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
|
|
@ -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";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
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