nixos/modules/restic-server-client/default.nix

39 lines
1.1 KiB
Nix
Raw Normal View History

2022-09-06 20:14:29 +02:00
{ hostname, inputs, custom, pkgs, time, ... }:
2022-01-29 15:31:42 +01:00
{
imports = [
"${inputs.self}/modules/telegram-notifications"
];
2022-02-28 18:19:50 +01:00
systemd.timers."restic-backups-${custom.username}" = {
wantedBy = [ "timers.target" ];
partOf = [ "restic-backups-${custom.username}.service" ];
timerConfig = {
OnCalendar = time;
};
};
2022-02-28 18:19:50 +01:00
systemd.services."restic-backups-${custom.username}" = {
2022-02-28 17:14:57 +01:00
serviceConfig = {
2022-02-28 18:30:59 +01:00
User = "root";
2022-02-28 17:14:57 +01:00
Type = "oneshot";
};
2022-02-28 18:19:50 +01:00
environment = {
RESTIC_PASSWORD_FILE = "/home/${custom.username}/.nixos/secrets/passwords/restic.key";
RESTIC_REPOSITORY = "rest:http://10.7.89.30:8000";
};
onFailure = [ "unit-status-telegram@%n.service" ];
script = ''
2022-05-31 22:23:38 +02:00
${pkgs.restic}/bin/restic backup \
--exclude-file=${inputs.self}/modules/restic/excludes.txt \
2022-08-23 21:29:45 +02:00
--tag home-dir /home/${custom.username}
2022-02-28 18:19:50 +01:00
${pkgs.restic}/bin/restic forget \
2022-08-23 21:29:45 +02:00
--tag home-dir \
2022-09-06 20:14:29 +02:00
--host ${hostname} \
--keep-daily 7 \
--keep-weekly 5 \
--keep-monthly 12 \
--keep-yearly 75
'';
2022-01-29 15:31:42 +01:00
};
}