nixos/modules/restic/default.nix

42 lines
1.1 KiB
Nix
Raw Normal View History

2022-02-28 17:32:55 +01:00
{ config, inputs, custom, pkgs, ... }:
2021-11-28 12:00:58 +01:00
{
environment.systemPackages = with pkgs;
[
restic
];
2022-01-29 16:01:27 +01:00
2022-02-28 18:13:09 +01:00
systemd.timers."restic-backups-${custom.username}" = {
wantedBy = [ "timers.target" ];
partOf = [ "restic-backups-${custom.username}.service" ];
2022-01-29 16:01:27 +01:00
timerConfig = {
OnCalendar = "hourly";
RandomizedDelaySec = "15min";
};
2021-11-28 12:00:58 +01:00
};
2022-02-28 18:13:09 +01:00
systemd.services."restic-backups-${custom.username}" = {
2022-02-28 17:15:14 +01:00
serviceConfig = {
User = custom.username;
Type = "oneshot";
};
environment = {
RESTIC_PASSWORD_FILE = "/home/${custom.username}/.nixos/secrets/passwords/restic.key";
RESTIC_REPOSITORY = "rest:http://10.7.89.30:8000";
};
script = ''
${pkgs.restic}/bin/restic \
--exclude-file=${inputs.self}/modules/restic/excludes.txt \
backup /home/${custom.username} \
${pkgs.restic}/bin/restic \
forget \
2022-02-28 17:32:55 +01:00
--host ${config.networking.hostName} \
--keep-hourly 25 \
--keep-daily 7 \
--keep-weekly 5 \
--keep-monthly 12 \
--keep-yearly 75 \
'';
};
2021-11-28 12:00:58 +01:00
}