diff --git a/modules/programs/borgmatic.nix b/modules/programs/borgmatic.nix index e1be117c..19670775 100644 --- a/modules/programs/borgmatic.nix +++ b/modules/programs/borgmatic.nix @@ -13,6 +13,13 @@ let default = null; }); + cleanRepositories = repos: + map (repo: + if builtins.isString repo then { + path = repo; + } else + removeNullValues repo) repos; + mkRetentionOption = frequency: mkNullableOption { type = types.int; @@ -27,6 +34,26 @@ let description = "Extra settings."; }; + repositoryOption = types.submodule { + options = { + path = mkOption { + type = types.str; + example = "ssh://myuser@myrepo.myserver.com/./repo"; + description = "Path of the repository."; + }; + + label = mkOption { + type = types.nullOr types.str; + default = null; + example = "remote"; + description = '' + Short text describing the repository. Can be used with the + `--repository` flag to select a repository. + ''; + }; + }; + }; + consistencyCheckModule = types.submodule { options = { name = mkOption { @@ -56,10 +83,23 @@ let }; repositories = mkOption { - type = types.listOf types.str; - description = "Paths to repositories."; - example = - literalExpression ''["ssh://myuser@myrepo.myserver.com/./repo"]''; + type = types.listOf (types.either types.str repositoryOption); + apply = cleanRepositories; + example = literalExpression '' + [ + { + "path" = "ssh://myuser@myrepo.myserver.com/./repo"; + "label" = "server"; + } + { + "path" = "/var/lib/backups/local.borg"; + "label" = "local"; + } + ] + ''; + description = '' + List of local or remote repositories with paths and optional labels. + ''; }; excludeHomeManagerSymlinks = mkOption { diff --git a/tests/modules/programs/borgmatic/basic-configuration.nix b/tests/modules/programs/borgmatic/basic-configuration.nix index a02c4764..15a57ca7 100644 --- a/tests/modules/programs/borgmatic/basic-configuration.nix +++ b/tests/modules/programs/borgmatic/basic-configuration.nix @@ -12,7 +12,14 @@ in { main = { location = { sourceDirectories = [ "/my-stuff-to-backup" ]; - repositories = [ "/mnt/disk1" "/mnt/disk2" ]; + repositories = [ + "/mnt/disk1" + { path = "/mnt/disk2"; } + { + path = "/mnt/disk3"; + label = "disk3"; + } + ]; extraConfig = { one_file_system = true; exclude_patterns = [ "*.swp" ]; @@ -65,11 +72,17 @@ in { expectations[source_directories[0]]="${ builtins.elemAt backups.main.location.sourceDirectories 0 }" - expectations[repositories[0]]="${ - builtins.elemAt backups.main.location.repositories 0 + expectations[repositories[0].path]="${ + (builtins.elemAt backups.main.location.repositories 0).path }" - expectations[repositories[1]]="${ - builtins.elemAt backups.main.location.repositories 1 + expectations[repositories[1].path]="${ + (builtins.elemAt backups.main.location.repositories 1).path + }" + expectations[repositories[2].path]="${ + (builtins.elemAt backups.main.location.repositories 2).path + }" + expectations[repositories[2].label]="${ + (builtins.elemAt backups.main.location.repositories 2).label }" expectations[one_file_system]="${ boolToString backups.main.location.extraConfig.one_file_system