2020-09-04 00:49:35 +02:00
|
|
|
{ config, lib, ... }: {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
backup.dirs = lib.mkOption {
|
|
|
|
default = [ ];
|
|
|
|
type = with lib.types; listOf str;
|
2020-09-05 14:37:49 +02:00
|
|
|
description = ''
|
|
|
|
folders to backup
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
backup.exclude = lib.mkOption {
|
|
|
|
default = [ ];
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description = ''
|
|
|
|
exclude files and folders matching a pattern.
|
|
|
|
Theses patterns effect all folders in `backup.dirs`.
|
|
|
|
see man borg pattern for more information
|
|
|
|
'';
|
|
|
|
example = [ ".git" "/home/*/.cache" ".stfolder" ];
|
2020-09-04 00:49:35 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = let
|
2021-09-25 15:17:07 +02:00
|
|
|
|
2020-09-04 00:49:35 +02:00
|
|
|
servers = [
|
|
|
|
{
|
|
|
|
name = "workhorse";
|
|
|
|
host = "workhorse.private";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "pepe";
|
|
|
|
host = "pepe.private";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
dirs = config.backup.dirs;
|
|
|
|
|
|
|
|
myHostname = config.networking.hostName;
|
|
|
|
|
|
|
|
setup = server: {
|
2020-09-05 14:37:49 +02:00
|
|
|
paths = config.backup.dirs;
|
|
|
|
exclude = config.backup.exclude;
|
2020-09-04 00:49:35 +02:00
|
|
|
doInit = true;
|
|
|
|
repo = "borg@${server}:./${myHostname}";
|
|
|
|
encryption = {
|
|
|
|
mode = "repokey-blake2";
|
|
|
|
# todo rename
|
2021-09-25 15:17:07 +02:00
|
|
|
# passCommand = "cat ${toString <secrets/backup/repo>}";
|
|
|
|
passCommand =
|
|
|
|
"cat ${config.sops.secrets.backup_repository_passphrase.path}";
|
2020-09-04 00:49:35 +02:00
|
|
|
};
|
2021-09-25 15:17:07 +02:00
|
|
|
environment.BORG_RSH =
|
|
|
|
"ssh -i ${toString config.sops.secrets.backup_ssh_rsa_private.path}";
|
2020-09-04 00:49:35 +02:00
|
|
|
compression = "auto,lzma";
|
|
|
|
startAt = "daily";
|
2020-09-05 14:37:49 +02:00
|
|
|
prune.keep = {
|
|
|
|
within = "10d"; # Keep all backups in the last 10 days.
|
|
|
|
weekly = 8; # Keep 8 additional end of week archives.
|
|
|
|
monthly = -1; # Keep end of month archive for every month
|
|
|
|
};
|
2020-09-04 00:49:35 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
2021-09-25 15:17:07 +02:00
|
|
|
sops.secrets.backup_repository_passphrase = { };
|
|
|
|
sops.secrets.backup_ssh_rsa_private = { };
|
|
|
|
|
2020-09-04 00:49:35 +02:00
|
|
|
services.borgbackup.jobs = let
|
|
|
|
setups = map ({ name, host }: { "${name}" = setup host; }) servers;
|
|
|
|
setupAttrs = lib.zipAttrsWith (_: vals: lib.head vals) setups;
|
|
|
|
nonEmptySetups =
|
|
|
|
lib.filterAttrs (_: { paths, ... }: builtins.length paths != 0)
|
|
|
|
setupAttrs;
|
|
|
|
in nonEmptySetups;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|