1 { config, lib, pkgs, ... }:
6 cfg = config.services.borgmatic;
7 settingsFormat = pkgs.formats.yaml { };
9 repository = with types; submodule {
14 Path to the repository
20 Label to the repository
25 cfgType = with types; submodule {
26 freeformType = settingsFormat.type;
28 source_directories = mkOption {
32 List of source directories and files to backup. Globs and tildes are
33 expanded. Do not backslash spaces in path names.
35 example = [ "/home" "/etc" "/var/log/syslog*" "/home/user/path with spaces" ];
37 repositories = mkOption {
38 type = listOf repository;
41 A required list of local or remote repositories with paths and
42 optional labels (which can be used with the --repository flag to
43 select a repository). Tildes are expanded. Multiple repositories are
44 backed up to in sequence. Borg placeholders can be used. See the
45 output of "borg help placeholders" for details. See ssh_command for
46 SSH options like identity file or port. If systemd service is used,
47 then add local repository paths in the systemd service file to the
51 { path="ssh://user@backupserver/./sourcehostname.borg"; label="backupserver"; }
52 { path="/mnt/backup"; label="local"; }
58 cfgfile = settingsFormat.generate "config.yaml" cfg.settings;
61 options.services.borgmatic = {
62 enable = mkEnableOption "borgmatic";
66 See https://torsion.org/borgmatic/docs/reference/configuration/
69 type = types.nullOr cfgType;
72 configurations = mkOption {
74 Set of borgmatic configurations, see https://torsion.org/borgmatic/docs/reference/configuration/
77 type = types.attrsOf cfgType;
80 enableConfigCheck = mkEnableOption "checking all configurations during build time" // { default = true; };
86 (optionalAttrs (cfg.settings != null) { "borgmatic/config.yaml".source = cfgfile; }) //
88 (name: value: nameValuePair
89 "borgmatic.d/${name}.yaml"
90 { source = settingsFormat.generate "${name}.yaml" value; })
92 borgmaticCheck = name: f: pkgs.runCommandCC "${name} validation" { } ''
93 ${pkgs.borgmatic}/bin/borgmatic -c ${f.source} config validate
100 ++ optional (cfg.settings != null && cfg.settings ? location)
101 "`services.borgmatic.settings.location` is deprecated, please move your options out of sections to the global scope"
102 ++ optional (catAttrs "location" (attrValues cfg.configurations) != [])
103 "`services.borgmatic.configurations.<name>.location` is deprecated, please move your options out of sections to the global scope"
106 environment.systemPackages = [ pkgs.borgmatic ];
108 environment.etc = configFiles;
110 systemd.packages = [ pkgs.borgmatic ];
112 # Workaround: https://github.com/NixOS/nixpkgs/issues/81138
113 systemd.timers.borgmatic.wantedBy = [ "timers.target" ];
115 system.checks = mkIf cfg.enableConfigCheck (mapAttrsToList borgmaticCheck configFiles);