1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.borgmatic;
7 cfgfile = pkgs.writeText "config.yaml" (builtins.toJSON cfg.settings);
8in {
9 options.services.borgmatic = {
10 enable = mkEnableOption "borgmatic";
11
12 settings = mkOption {
13 description = ''
14 See https://torsion.org/borgmatic/docs/reference/configuration/
15 '';
16 type = types.submodule {
17 freeformType = with lib.types; attrsOf anything;
18 options.location = {
19 source_directories = mkOption {
20 type = types.listOf types.str;
21 description = ''
22 List of source directories to backup (required). Globs and
23 tildes are expanded.
24 '';
25 example = [ "/home" "/etc" "/var/log/syslog*" ];
26 };
27 repositories = mkOption {
28 type = types.listOf types.str;
29 description = ''
30 Paths to local or remote repositories (required). Tildes are
31 expanded. Multiple repositories are backed up to in
32 sequence. Borg placeholders can be used. See the output of
33 "borg help placeholders" for details. See ssh_command for
34 SSH options like identity file or port. If systemd service
35 is used, then add local repository paths in the systemd
36 service file to the ReadWritePaths list.
37 '';
38 example = [
39 "user@backupserver:sourcehostname.borg"
40 "user@backupserver:{fqdn}"
41 ];
42 };
43 };
44 };
45 };
46 };
47
48 config = mkIf cfg.enable {
49
50 environment.systemPackages = [ pkgs.borgmatic ];
51
52 environment.etc."borgmatic/config.yaml".source = cfgfile;
53
54 systemd.packages = [ pkgs.borgmatic ];
55
56 };
57}