nixpkgs/nixos/modules/services/backup/borgmatic.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

105 lines
3.3 KiB
Nix
Raw Normal View History

2021-02-17 04:49:52 +00:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.borgmatic;
2022-05-03 00:31:14 +00:00
settingsFormat = pkgs.formats.yaml { };
2023-08-06 16:15:57 +00:00
repository = with types; submodule {
options = {
path = mkOption {
type = str;
description = mdDoc ''
Path to the repository
'';
};
label = mkOption {
type = str;
description = mdDoc ''
Label to the repository
'';
};
};
};
cfgType = with types; submodule {
freeformType = settingsFormat.type;
2023-08-06 16:15:57 +00:00
options = {
source_directories = mkOption {
2023-08-06 16:15:57 +00:00
type = nullOr (listOf str);
default = null;
description = mdDoc ''
2023-08-06 16:15:57 +00:00
List of source directories and files to backup. Globs and tildes are
expanded. Do not backslash spaces in path names.
'';
2023-08-06 16:15:57 +00:00
example = [ "/home" "/etc" "/var/log/syslog*" "/home/user/path with spaces" ];
};
repositories = mkOption {
2023-08-06 16:15:57 +00:00
type = nullOr (listOf repository);
default = null;
description = mdDoc ''
2023-08-06 16:15:57 +00:00
A required list of local or remote repositories with paths and
optional labels (which can be used with the --repository flag to
select a repository). 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 = [
2023-08-06 16:15:57 +00:00
{ path="ssh://user@backupserver/./sourcehostname.borg"; label="backupserver"; }
{ path="/mnt/backup"; label="local"; }
];
};
};
};
2022-05-03 00:31:14 +00:00
cfgfile = settingsFormat.generate "config.yaml" cfg.settings;
in
{
2021-02-17 04:49:52 +00:00
options.services.borgmatic = {
enable = mkEnableOption (mdDoc "borgmatic");
2021-02-17 04:49:52 +00:00
settings = mkOption {
description = mdDoc ''
2021-02-17 04:49:52 +00:00
See https://torsion.org/borgmatic/docs/reference/configuration/
'';
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-02-17 04:49:52 +00:00
};
};
config = mkIf cfg.enable {
2023-08-06 16:15:57 +00:00
warnings = []
++ optional (cfg.settings != null && cfg.settings ? location)
2023-08-06 16:15:57 +00:00
"`services.borgmatic.settings.location` is deprecated, please move your options out of sections to the global scope"
++ optional (catAttrs "location" (attrValues cfg.configurations) != [])
"`services.borgmatic.configurations.<name>.location` is deprecated, please move your options out of sections to the global scope"
;
2021-02-17 04:49:52 +00:00
environment.systemPackages = [ pkgs.borgmatic ];
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-02-17 04:49:52 +00:00
systemd.packages = [ pkgs.borgmatic ];
2023-04-17 15:10:23 +00:00
# Workaround: https://github.com/NixOS/nixpkgs/issues/81138
systemd.timers.borgmatic.wantedBy = [ "timers.target" ];
2021-02-17 04:49:52 +00:00
};
}