nixos/modules/restic/default.nix

70 lines
1.8 KiB
Nix
Raw Normal View History

2022-02-28 17:32:55 +01:00
{ config, inputs, custom, pkgs, ... }:
2022-03-01 15:01:50 +01:00
let
password_file = "/home/${custom.username}/.nixos/secrets/passwords/restic.key";
repository = "rest:http://10.7.89.30:8000";
2022-03-01 15:23:39 +01:00
in
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-03-18 16:51:39 +01:00
unitConfig.ConditionACPower = true;
2022-02-28 17:15:14 +01:00
serviceConfig = {
User = custom.username;
Type = "oneshot";
};
environment = {
2022-03-01 15:01:50 +01:00
RESTIC_PASSWORD_FILE = password_file;
RESTIC_REPOSITORY = repository;
};
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 \
'';
};
2022-03-01 15:01:50 +01:00
environment.shellAliases = {
restic-list = ''
restic \
2022-03-01 15:23:39 +01:00
--repo ${repository} \
--password-file ${password_file} \
snapshots --host ${config.networking.hostName}
2022-03-01 16:54:46 +01:00
'';
restic-mount = ''
mkdir -p /tmp/restic && \
restic \
--repo ${repository} \
--password-file ${password_file} \
--host ${config.networking.hostName} \
mount /tmp/restic
'';
restic-mount-all = ''
mkdir -p /tmp/restic && \
restic \
--repo ${repository} \
--password-file ${password_file} \
mount /tmp/restic
'';
2022-03-01 15:01:50 +01:00
};
2021-11-28 12:00:58 +01:00
}