8 cfg = config.services.borgmatic;
9 settingsFormat = pkgs.formats.yaml { };
18 Path to the repository
21 label = lib.mkOption {
24 Label to the repository
32 freeformType = settingsFormat.type;
34 source_directories = lib.mkOption {
38 List of source directories and files to backup. Globs and tildes are
39 expanded. Do not backslash spaces in path names.
45 "/home/user/path with spaces"
48 repositories = lib.mkOption {
49 type = listOf repository;
52 A required list of local or remote repositories with paths and
53 optional labels (which can be used with the --repository flag to
54 select a repository). Tildes are expanded. Multiple repositories are
55 backed up to in sequence. Borg placeholders can be used. See the
56 output of "borg help placeholders" for details. See ssh_command for
57 SSH options like identity file or port. If systemd service is used,
58 then add local repository paths in the systemd service file to the
63 path = "ssh://user@backupserver/./sourcehostname.borg";
64 label = "backupserver";
75 cfgfile = settingsFormat.generate "config.yaml" cfg.settings;
78 options.services.borgmatic = {
79 enable = lib.mkEnableOption "borgmatic";
81 settings = lib.mkOption {
83 See https://torsion.org/borgmatic/docs/reference/configuration/
86 type = lib.types.nullOr cfgType;
89 configurations = lib.mkOption {
91 Set of borgmatic configurations, see https://torsion.org/borgmatic/docs/reference/configuration/
94 type = lib.types.attrsOf cfgType;
97 enableConfigCheck = lib.mkEnableOption "checking all configurations during build time" // {
105 (lib.optionalAttrs (cfg.settings != null) { "borgmatic/config.yaml".source = cfgfile; })
108 lib.nameValuePair "borgmatic.d/${name}.yaml" {
109 source = settingsFormat.generate "${name}.yaml" value;
111 ) cfg.configurations;
114 pkgs.runCommandCC "${name} validation" { } ''
115 ${pkgs.borgmatic}/bin/borgmatic -c ${f.source} config validate
119 lib.mkIf cfg.enable {
124 lib.optional (cfg.settings != null && cfg.settings ? location)
125 "`services.borgmatic.settings.location` is deprecated, please move your options out of sections to the global scope"
127 lib.optional (lib.catAttrs "location" (lib.attrValues cfg.configurations) != [ ])
128 "`services.borgmatic.configurations.<name>.location` is deprecated, please move your options out of sections to the global scope";
130 environment.systemPackages = [ pkgs.borgmatic ];
132 environment.etc = configFiles;
134 systemd.packages = [ pkgs.borgmatic ];
136 # Workaround: https://github.com/NixOS/nixpkgs/issues/81138
137 systemd.timers.borgmatic.wantedBy = [ "timers.target" ];
139 system.checks = lib.mkIf cfg.enableConfigCheck (lib.mapAttrsToList borgmaticCheck configFiles);