1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00
Files
niveum/configs/backup.nix

52 lines
1.3 KiB
Nix
Raw Normal View History

2022-01-18 21:29:30 +01:00
{
2022-03-10 21:52:12 +01:00
pkgs,
config,
...
}: let
inherit (import ../lib) restic;
2022-03-10 21:52:12 +01:00
in {
2022-01-18 21:29:30 +01:00
services.restic.backups.niveum = {
initialize = true;
inherit (restic) repository;
2022-03-10 21:52:12 +01:00
timerConfig = {
OnCalendar = "8:00";
RandomizedDelaySec = "1h";
};
passwordFile = config.age.secrets.restic.path;
2022-01-18 23:36:38 +01:00
extraBackupArgs = [
2024-04-03 07:56:07 +02:00
"--exclude=/home/kfm/sync/src/nixpkgs/.git"
2022-01-18 23:36:38 +01:00
"--exclude=node_modules"
2023-07-25 16:17:23 +02:00
"--exclude=.parcel-cache"
2022-01-18 23:36:38 +01:00
];
2022-01-18 21:29:30 +01:00
paths = [
2024-04-03 07:56:07 +02:00
"/home/kfm/sync"
"/home/kfm/state"
2022-01-19 00:48:15 +01:00
"/home/kfm/cloud"
2024-04-05 11:41:13 +02:00
"/home/kfm/mobile"
2022-01-19 00:48:15 +01:00
"/home/kfm/.gnupg"
"/home/kfm/.ssh"
2022-01-18 21:29:30 +01:00
];
};
2022-01-18 22:38:28 +01:00
2022-01-24 09:13:58 +01:00
systemd.services.restic-backups-niveum.serviceConfig = {
Restart = "on-failure";
RestartSec = "15s";
StartLimitIntervalSec = "1m"; # don't try more than 4 times
StartLimitBurst = 4;
};
2022-01-18 22:38:28 +01:00
environment.systemPackages = [
(pkgs.writers.writeDashBin "restic-niveum" ''
${pkgs.restic}/bin/restic -r ${restic.repository} -p ${config.age.secrets.restic.path} "$@"
2022-01-18 22:38:28 +01:00
'')
2022-01-19 09:38:19 +01:00
(pkgs.writers.writeDashBin "restic-mount" ''
mountdir=$(mktemp -d)
trap clean EXIT
clean() {
2022-01-23 14:26:54 +01:00
rm -r "$mountdir"
2022-01-19 09:38:19 +01:00
}
${pkgs.restic}/bin/restic -r ${restic.repository} -p ${config.age.secrets.restic.path} mount "$mountdir"
2022-01-19 09:38:19 +01:00
'')
2022-01-18 22:38:28 +01:00
];
2022-01-18 21:29:30 +01:00
}