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 = {
|
2024-01-06 22:47:50 -05:00
|
|
|
user = mkDefault "borg";
|
|
|
|
environment = mkDefault {BORG_RSH = "ssh -i ${secrets.borg-ssh.path}";};
|
2023-12-27 01:59:28 -05:00
|
|
|
|
2024-01-06 22:47:50 -05:00
|
|
|
repo = mkDefault "ssh://matt@pve/data/backups/borg";
|
|
|
|
encryption = mkDefault {
|
2023-12-27 01:59:28 -05:00
|
|
|
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
|
2024-01-06 22:47:50 -05:00
|
|
|
startAt = mkDefault "00/3:00";
|
|
|
|
compression = mkDefault "auto,lzma";
|
2023-12-27 01:59:28 -05:00
|
|
|
};
|
2023-12-27 11:39:38 -05:00
|
|
|
|
2024-01-06 22:47:50 -05:00
|
|
|
jobs = mapAttrs (_: v: cfg.defaults // v) cfg.configs;
|
2023-12-27 01:59:28 -05:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|