2023-12-27 01:59:28 -05:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
2023-12-27 11:39:38 -05:00
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.services.borgbackup;
|
|
|
|
secrets = config.sops.secrets;
|
|
|
|
in {
|
2023-12-27 01:59:28 -05:00
|
|
|
# Make this file declare default settings
|
2023-12-27 11:39:38 -05:00
|
|
|
options.services.borgbackup = {
|
|
|
|
#
|
2023-12-27 01:59:28 -05:00
|
|
|
defaults = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
};
|
2023-12-27 11:39:38 -05:00
|
|
|
configs = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
};
|
2023-12-27 01:59:28 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
users.groups.borg = {};
|
|
|
|
users.users.borg = {
|
|
|
|
isSystemUser = true;
|
2023-12-27 11:39:38 -05:00
|
|
|
# https://mynixos.com/nixpkgs/option/services.borgbackup.jobs.%3Cname%3E.readWritePaths
|
2023-12-27 01:59:28 -05:00
|
|
|
createHome = true;
|
|
|
|
home = "/var/lib/borg";
|
|
|
|
group = "borg";
|
|
|
|
extraGroups = ["mc"];
|
|
|
|
};
|
|
|
|
|
|
|
|
programs.ssh.knownHosts = {
|
|
|
|
pve.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG/4mrp8E4Ittwg8feRmPtDHSDR2+Pq4uZHeF5MweVcW";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.borgbackup = {
|
|
|
|
defaults = {
|
|
|
|
user = "borg";
|
2023-12-27 11:39:38 -05:00
|
|
|
environment = {BORG_RSH = "ssh -i ${secrets.borg-ssh.path}";};
|
2023-12-27 01:59:28 -05:00
|
|
|
|
|
|
|
repo = "ssh://matt@pve/data/backups/borg";
|
|
|
|
encryption = {
|
|
|
|
mode = "repokey";
|
|
|
|
passCommand = let
|
|
|
|
cat = "${pkgs.coreutils}/bin/cat";
|
2023-12-27 11:39:38 -05:00
|
|
|
key = secrets.borg-repo.path;
|
2023-12-27 01:59:28 -05:00
|
|
|
in "${cat} ${key}";
|
|
|
|
};
|
|
|
|
|
|
|
|
# Run every 3 hours
|
|
|
|
startAt = "00/3:00";
|
|
|
|
compression = "auto,lzma";
|
|
|
|
};
|
2023-12-27 11:39:38 -05:00
|
|
|
|
|
|
|
jobs = mapAttrs (_: v: v // cfg.defaults) cfg.configs;
|
2023-12-27 01:59:28 -05:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|