nixos/modules/services/restic-client-desktop/default.nix

70 lines
1.8 KiB
Nix
Raw Normal View History

2024-02-02 13:45:05 +01:00
{
config,
inputs,
lib,
pkgs,
...
}:
2022-03-01 15:01:50 +01:00
let
cfg = config.services.az-restic-client-desktop;
2022-11-04 16:49:46 +01:00
password_file = config.age.secrets.resticKey.path;
repository = "rest:http://10.7.89.30:8000";
2024-02-02 13:45:05 +01:00
in
{
options = {
2024-02-02 13:45:05 +01:00
services.az-restic-client-desktop.enable = lib.mkEnableOption "Enable restic backups";
2022-11-04 16:49:46 +01:00
};
config = lib.mkIf cfg.enable {
services.az-telegram-notifications.enable = true;
age.secrets.infomaniakEnv = {
file = "${inputs.self}/scrts/infomaniak_env.age";
mode = "600";
owner = config.az-username;
group = "users";
2022-01-29 16:01:27 +01:00
};
age.secrets.resticKey = {
file = "${inputs.self}/scrts/restic.key.age";
mode = "600";
owner = config.az-username;
group = "users";
2022-02-28 17:15:14 +01:00
};
systemd.timers."restic-backups-${config.az-username}" = {
wantedBy = [ "timers.target" ];
partOf = [ "restic-backups-${config.az-username}.service" ];
timerConfig = {
OnCalendar = "hourly";
RandomizedDelaySec = "15min";
};
};
systemd.services."restic-backups-${config.az-username}" = {
unitConfig.ConditionACPower = true;
serviceConfig = {
User = config.az-username;
Type = "oneshot";
};
environment = {
RESTIC_PASSWORD_FILE = password_file;
RESTIC_REPOSITORY = repository;
};
onFailure = [ "unit-status-telegram@%n.service" ];
script = ''
${pkgs.restic}/bin/restic \
--exclude-file=${inputs.self}/modules/misc/restic-client/excludes.txt \
--tag home-dir \
backup /home/${config.az-username}
2022-08-23 20:13:31 +02:00
${pkgs.restic}/bin/restic \
forget \
--host ${config.networking.hostName} \
--keep-hourly 25 \
--keep-daily 7 \
--keep-weekly 5 \
--keep-monthly 12 \
--keep-yearly 2 \
'';
};
};
2021-11-28 12:00:58 +01:00
}