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

46 lines
1.1 KiB
Nix
Raw Normal View History

2022-11-04 19:35:57 +01:00
{ custom
2022-11-04 16:49:46 +01:00
, path
, tag ? "home-dir"
, time
2022-11-04 16:49:46 +01:00
}: { config, pkgs, ... }:
2022-01-29 15:31:42 +01:00
{
imports = [
2022-11-04 19:35:57 +01:00
(import "${custom.inputs.self}/modules/telegram-notifications" { inherit custom; })
];
2022-11-04 16:49:46 +01:00
2022-11-04 19:35:57 +01:00
age.secrets.resticKey.file = "${custom.inputs.self}/scrts/restic.key.age";
2022-11-04 16:49:46 +01:00
systemd.timers."restic-backups" = {
2022-02-28 18:19:50 +01:00
wantedBy = [ "timers.target" ];
2022-11-04 16:49:46 +01:00
partOf = [ "restic-backups.service" ];
2022-02-28 18:19:50 +01:00
timerConfig = {
OnCalendar = time;
};
};
2022-11-04 16:49:46 +01:00
systemd.services."restic-backups" = {
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 = {
2022-11-04 16:49:46 +01:00
RESTIC_PASSWORD_FILE = config.age.secrets.resticKey.path;
2022-02-28 18:19:50 +01:00
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 \
2022-11-04 19:35:57 +01:00
--exclude-file=${custom.inputs.self}/modules/restic/excludes.txt \
--tag ${tag} ${path}
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-11-04 16:49:46 +01:00
--host ${config.networking.hostName} \
--keep-daily 7 \
--keep-weekly 5 \
--keep-monthly 12 \
--keep-yearly 75
'';
2022-01-29 15:31:42 +01:00
};
}