2022-01-13 13:40:18 +01:00
|
|
|
{ config, lib, ... }:
|
|
|
|
# borg core setup
|
|
|
|
# ---------------
|
|
|
|
# provides an easy interface for all services
|
|
|
|
# to append it's files to be backuped
|
|
|
|
{
|
2020-09-04 00:49:35 +02:00
|
|
|
|
|
|
|
options = {
|
2023-03-07 16:21:46 +01:00
|
|
|
backup = {
|
|
|
|
enable = lib.mkEnableOption "enable borg backup";
|
|
|
|
dirs = lib.mkOption {
|
|
|
|
default = [ ];
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description = ''
|
|
|
|
folders to 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" ];
|
|
|
|
};
|
|
|
|
servers = lib.mkOption {
|
|
|
|
default = {
|
|
|
|
robi.host = "144.76.13.147";
|
|
|
|
pepe.host = "pepe.private";
|
|
|
|
};
|
|
|
|
type = with lib.types; attrsOf (submodule {
|
|
|
|
options = {
|
|
|
|
host = lib.mkOption {
|
|
|
|
type = with lib.types; str;
|
|
|
|
};
|
|
|
|
user = lib.mkOption {
|
|
|
|
default = "borg";
|
|
|
|
type = with lib.types; str;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
description = ''
|
|
|
|
servers to backup to
|
|
|
|
'';
|
|
|
|
};
|
2020-09-04 00:49:35 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-11-01 09:20:42 +01:00
|
|
|
config =
|
|
|
|
let
|
|
|
|
myHostname = config.networking.hostName;
|
2023-03-07 16:21:46 +01:00
|
|
|
setup = { user, host }: {
|
2021-11-01 09:20:42 +01:00
|
|
|
paths = config.backup.dirs;
|
|
|
|
exclude = config.backup.exclude;
|
|
|
|
doInit = true;
|
2023-03-07 16:21:46 +01:00
|
|
|
repo = "${user}@${host}:./${myHostname}";
|
2021-11-01 09:20:42 +01:00
|
|
|
encryption = {
|
|
|
|
mode = "repokey-blake2";
|
2022-01-13 13:40:18 +01:00
|
|
|
passCommand = "cat ${config.sops.secrets.backup_repository_passphrase.path}";
|
2021-11-01 09:20:42 +01:00
|
|
|
};
|
2023-01-07 21:36:34 +01:00
|
|
|
environment = {
|
|
|
|
BORG_RSH = "ssh -i ${toString config.sops.secrets.backup_ssh_rsa_private.path}";
|
|
|
|
BORG_RELOCATED_REPO_ACCESS_IS_OK = "yes";
|
|
|
|
};
|
2021-11-01 09:20:42 +01:00
|
|
|
compression = "auto,lzma";
|
|
|
|
startAt = "daily";
|
|
|
|
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
|
|
|
|
2021-11-01 09:20:42 +01:00
|
|
|
in
|
2023-03-07 16:21:46 +01:00
|
|
|
|
|
|
|
lib.mkIf config.backup.enable {
|
2020-09-04 00:49:35 +02:00
|
|
|
|
2021-11-01 09:20:42 +01:00
|
|
|
sops.secrets.backup_repository_passphrase = { };
|
|
|
|
sops.secrets.backup_ssh_rsa_private = { };
|
2021-09-25 15:17:07 +02:00
|
|
|
|
2021-11-01 09:20:42 +01:00
|
|
|
services.borgbackup.jobs =
|
2023-03-07 16:21:46 +01:00
|
|
|
lib.mapAttrs (_: target: setup target) config.backup.servers;
|
|
|
|
|
|
|
|
#systemd.services = lib.mapAttrs'
|
|
|
|
# (name: _: {
|
|
|
|
# name = "borgbackup-job-${name}";
|
|
|
|
# value = { enable = config.backup.dirs != [ ]; };
|
|
|
|
# })
|
|
|
|
# config.backup.servers;
|
2020-09-04 00:49:35 +02:00
|
|
|
|
2021-11-01 09:20:42 +01:00
|
|
|
};
|
2020-09-04 00:49:35 +02:00
|
|
|
|
2023-03-07 16:21:46 +01:00
|
|
|
|
2020-09-04 00:49:35 +02:00
|
|
|
}
|