Merge pull request #214759 from Tom-Hubrecht/borgmatic

nixos/borgmatic: Allow defining multiple configurations
This commit is contained in:
Ryan Lahfa 2023-03-04 11:38:39 +01:00 committed by GitHub
commit fd09c1bdc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 34 deletions

View file

@ -176,6 +176,8 @@ In addition to numerous new and upgraded packages, this release has the followin
- NixOS now defaults to using nsncd (a non-caching reimplementation in Rust) as NSS lookup dispatcher, instead of the buggy and deprecated glibc-provided nscd. If you need to switch back, set `services.nscd.enableNsncd = false`, but please open an issue in nixpkgs so your issue can be fixed. - NixOS now defaults to using nsncd (a non-caching reimplementation in Rust) as NSS lookup dispatcher, instead of the buggy and deprecated glibc-provided nscd. If you need to switch back, set `services.nscd.enableNsncd = false`, but please open an issue in nixpkgs so your issue can be fixed.
- `services.borgmatic` now allows for multiple configurations, placed in `/etc/borgmatic.d/`, you can define them with `services.borgmatic.configurations`.
- The `dnsmasq` service now takes configuration via the - The `dnsmasq` service now takes configuration via the
`services.dnsmasq.settings` attribute set. The option `services.dnsmasq.settings` attribute set. The option
`services.dnsmasq.extraConfig` will be deprecated when NixOS 22.11 reaches `services.dnsmasq.extraConfig` will be deprecated when NixOS 22.11 reaches

View file

@ -5,44 +5,58 @@ with lib;
let let
cfg = config.services.borgmatic; cfg = config.services.borgmatic;
settingsFormat = pkgs.formats.yaml { }; settingsFormat = pkgs.formats.yaml { };
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"
];
};
};
};
cfgfile = settingsFormat.generate "config.yaml" cfg.settings; cfgfile = settingsFormat.generate "config.yaml" cfg.settings;
in { in
{
options.services.borgmatic = { options.services.borgmatic = {
enable = mkEnableOption (lib.mdDoc "borgmatic"); enable = mkEnableOption (mdDoc "borgmatic");
settings = mkOption { settings = mkOption {
description = lib.mdDoc '' description = mdDoc ''
See https://torsion.org/borgmatic/docs/reference/configuration/ See https://torsion.org/borgmatic/docs/reference/configuration/
''; '';
type = types.submodule { default = null;
freeformType = settingsFormat.type; type = types.nullOr cfgType;
options.location = { };
source_directories = mkOption {
type = types.listOf types.str; configurations = mkOption {
description = lib.mdDoc '' description = mdDoc ''
List of source directories to backup (required). Globs and Set of borgmatic configurations, see https://torsion.org/borgmatic/docs/reference/configuration/
tildes are expanded. '';
''; default = { };
example = [ "/home" "/etc" "/var/log/syslog*" ]; type = types.attrsOf cfgType;
};
repositories = mkOption {
type = types.listOf types.str;
description = lib.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 = [
"user@backupserver:sourcehostname.borg"
"user@backupserver:{fqdn}"
];
};
};
};
}; };
}; };
@ -50,9 +64,13 @@ in {
environment.systemPackages = [ pkgs.borgmatic ]; environment.systemPackages = [ pkgs.borgmatic ];
environment.etc."borgmatic/config.yaml".source = cfgfile; 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;
systemd.packages = [ pkgs.borgmatic ]; systemd.packages = [ pkgs.borgmatic ];
}; };
} }