nixos/modules/restic/default.nix

44 lines
1.1 KiB
Nix
Raw Normal View History

2022-02-28 17:32:55 +01:00
{ config, inputs, custom, pkgs, ... }:
let
repository = "rest:http://10.7.89.30:8000";
in
2021-11-28 12:00:58 +01:00
{
2022-01-29 16:01:27 +01:00
environment.systemPackages = with pkgs; [
restic
];
2022-02-21 11:36:12 +01:00
services.restic.backups.${custom.username} = {
user = custom.username;
repository = repository;
2022-01-29 16:01:27 +01:00
timerConfig = {
OnCalendar = "hourly";
RandomizedDelaySec = "15min";
};
2022-02-21 11:36:12 +01:00
passwordFile = "/home/${custom.username}/.nixos/secrets/passwords/restic.key";
paths = [ "/home/${custom.username}/" ];
2021-11-28 12:00:58 +01:00
extraBackupArgs = [
2022-02-16 22:19:13 +01:00
"--exclude-file=${inputs.self}/modules/restic/excludes.txt"
2021-11-28 12:00:58 +01:00
];
};
2022-02-28 17:16:23 +01:00
systemd.services.restic-forget = {
2022-02-28 17:15:14 +01:00
serviceConfig = {
User = custom.username;
Type = "oneshot";
};
after = [ "restic-backups-${custom.username}.service" ];
script = ''
${pkgs.restic}/bin/restic \
--repo ${repository} \
--password-file "/home/${custom.username}/.nixos/secrets/passwords/restic.key" \
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
}