2021-03-12 07:09:13 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.borgmatic;
|
2022-05-18 14:49:53 +00:00
|
|
|
settingsFormat = pkgs.formats.yaml { };
|
2023-03-04 12:14:45 +00:00
|
|
|
|
|
|
|
cfgType = with types; submodule {
|
|
|
|
freeformType = settingsFormat.type;
|
|
|
|
options.location = {
|
|
|
|
source_directories = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
description = mdDoc ''
|
|
|
|
List of source directories to backup (required). Globs and
|
|
|
|
tildes are expanded.
|
|
|
|
'';
|
|
|
|
example = [ "/home" "/etc" "/var/log/syslog*" ];
|
|
|
|
};
|
|
|
|
repositories = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
description = mdDoc ''
|
|
|
|
Paths to local or remote repositories (required). Tildes are
|
|
|
|
expanded. Multiple repositories are backed up to in
|
|
|
|
sequence. Borg placeholders can be used. See the output of
|
|
|
|
"borg help placeholders" for details. See ssh_command for
|
|
|
|
SSH options like identity file or port. If systemd service
|
|
|
|
is used, then add local repository paths in the systemd
|
|
|
|
service file to the ReadWritePaths list.
|
|
|
|
'';
|
|
|
|
example = [
|
|
|
|
"ssh://user@backupserver/./sourcehostname.borg"
|
|
|
|
"ssh://user@backupserver/./{fqdn}"
|
|
|
|
"/var/local/backups/local.borg"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
cfgfile = settingsFormat.generate "config.yaml" cfg.settings;
|
2023-03-04 12:14:45 +00:00
|
|
|
in
|
|
|
|
{
|
2021-03-12 07:09:13 +00:00
|
|
|
options.services.borgmatic = {
|
2023-03-04 12:14:45 +00:00
|
|
|
enable = mkEnableOption (mdDoc "borgmatic");
|
2021-03-12 07:09:13 +00:00
|
|
|
|
|
|
|
settings = mkOption {
|
2023-03-04 12:14:45 +00:00
|
|
|
description = mdDoc ''
|
2021-03-12 07:09:13 +00:00
|
|
|
See https://torsion.org/borgmatic/docs/reference/configuration/
|
|
|
|
'';
|
2023-03-04 12:14:45 +00:00
|
|
|
default = null;
|
|
|
|
type = types.nullOr cfgType;
|
|
|
|
};
|
|
|
|
|
|
|
|
configurations = mkOption {
|
|
|
|
description = mdDoc ''
|
|
|
|
Set of borgmatic configurations, see https://torsion.org/borgmatic/docs/reference/configuration/
|
|
|
|
'';
|
|
|
|
default = { };
|
|
|
|
type = types.attrsOf cfgType;
|
2021-03-12 07:09:13 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.borgmatic ];
|
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
environment.etc = (optionalAttrs (cfg.settings != null) { "borgmatic/config.yaml".source = cfgfile; }) //
|
|
|
|
mapAttrs'
|
|
|
|
(name: value: nameValuePair
|
|
|
|
"borgmatic.d/${name}.yaml"
|
|
|
|
{ source = settingsFormat.generate "${name}.yaml" value; })
|
|
|
|
cfg.configurations;
|
2021-03-12 07:09:13 +00:00
|
|
|
|
|
|
|
systemd.packages = [ pkgs.borgmatic ];
|
|
|
|
};
|
|
|
|
}
|