lol

Merge pull request #214759 from Tom-Hubrecht/borgmatic

nixos/borgmatic: Allow defining multiple configurations

authored by

Ryan Lahfa and committed by
GitHub
fd09c1bd cdb62c08

+54 -34
+2
nixos/doc/manual/release-notes/rl-2305.section.md
··· 176 176 177 177 - 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. 178 178 179 + - `services.borgmatic` now allows for multiple configurations, placed in `/etc/borgmatic.d/`, you can define them with `services.borgmatic.configurations`. 180 + 179 181 - The `dnsmasq` service now takes configuration via the 180 182 `services.dnsmasq.settings` attribute set. The option 181 183 `services.dnsmasq.extraConfig` will be deprecated when NixOS 22.11 reaches
+52 -34
nixos/modules/services/backup/borgmatic.nix
··· 5 5 let 6 6 cfg = config.services.borgmatic; 7 7 settingsFormat = pkgs.formats.yaml { }; 8 + 9 + cfgType = with types; submodule { 10 + freeformType = settingsFormat.type; 11 + options.location = { 12 + source_directories = mkOption { 13 + type = listOf str; 14 + description = mdDoc '' 15 + List of source directories to backup (required). Globs and 16 + tildes are expanded. 17 + ''; 18 + example = [ "/home" "/etc" "/var/log/syslog*" ]; 19 + }; 20 + repositories = mkOption { 21 + type = listOf str; 22 + description = mdDoc '' 23 + Paths to local or remote repositories (required). Tildes are 24 + expanded. Multiple repositories are backed up to in 25 + sequence. Borg placeholders can be used. See the output of 26 + "borg help placeholders" for details. See ssh_command for 27 + SSH options like identity file or port. If systemd service 28 + is used, then add local repository paths in the systemd 29 + service file to the ReadWritePaths list. 30 + ''; 31 + example = [ 32 + "ssh://user@backupserver/./sourcehostname.borg" 33 + "ssh://user@backupserver/./{fqdn}" 34 + "/var/local/backups/local.borg" 35 + ]; 36 + }; 37 + }; 38 + }; 39 + 8 40 cfgfile = settingsFormat.generate "config.yaml" cfg.settings; 9 - in { 41 + in 42 + { 10 43 options.services.borgmatic = { 11 - enable = mkEnableOption (lib.mdDoc "borgmatic"); 44 + enable = mkEnableOption (mdDoc "borgmatic"); 12 45 13 46 settings = mkOption { 14 - description = lib.mdDoc '' 47 + description = mdDoc '' 15 48 See https://torsion.org/borgmatic/docs/reference/configuration/ 16 49 ''; 17 - type = types.submodule { 18 - freeformType = settingsFormat.type; 19 - options.location = { 20 - source_directories = mkOption { 21 - type = types.listOf types.str; 22 - description = lib.mdDoc '' 23 - List of source directories to backup (required). Globs and 24 - tildes are expanded. 25 - ''; 26 - example = [ "/home" "/etc" "/var/log/syslog*" ]; 27 - }; 28 - repositories = mkOption { 29 - type = types.listOf types.str; 30 - description = lib.mdDoc '' 31 - Paths to local or remote repositories (required). Tildes are 32 - expanded. Multiple repositories are backed up to in 33 - sequence. Borg placeholders can be used. See the output of 34 - "borg help placeholders" for details. See ssh_command for 35 - SSH options like identity file or port. If systemd service 36 - is used, then add local repository paths in the systemd 37 - service file to the ReadWritePaths list. 38 - ''; 39 - example = [ 40 - "user@backupserver:sourcehostname.borg" 41 - "user@backupserver:{fqdn}" 42 - ]; 43 - }; 44 - }; 45 - }; 50 + default = null; 51 + type = types.nullOr cfgType; 52 + }; 53 + 54 + configurations = mkOption { 55 + description = mdDoc '' 56 + Set of borgmatic configurations, see https://torsion.org/borgmatic/docs/reference/configuration/ 57 + ''; 58 + default = { }; 59 + type = types.attrsOf cfgType; 46 60 }; 47 61 }; 48 62 ··· 50 64 51 65 environment.systemPackages = [ pkgs.borgmatic ]; 52 66 53 - environment.etc."borgmatic/config.yaml".source = cfgfile; 67 + environment.etc = (optionalAttrs (cfg.settings != null) { "borgmatic/config.yaml".source = cfgfile; }) // 68 + mapAttrs' 69 + (name: value: nameValuePair 70 + "borgmatic.d/${name}.yaml" 71 + { source = settingsFormat.generate "${name}.yaml" value; }) 72 + cfg.configurations; 54 73 55 74 systemd.packages = [ pkgs.borgmatic ]; 56 - 57 75 }; 58 76 }