fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
6.6 KiB237 linesraw
1{ config, lib, ... }:
2
3with lib;
4
5let
6
7  extraConfigType = with lib.types;
8    attrsOf (oneOf [ str int bool (listOf str) ]);
9
10  perAccountGroups = { name, config, ... }: {
11    options = {
12      name = mkOption {
13        type = types.str;
14        # Make value of name the same as the name used with the dot prefix
15        default = name;
16        readOnly = true;
17        description = ''
18          The name of this group for this account. These names are different than
19          some others, because they will hide channel names that are the same.
20        '';
21      };
22
23      channels = mkOption {
24        type = types.attrsOf (types.submodule channel);
25        default = { };
26        description = ''
27          List of channels that should be grouped together into this group. When
28          performing a synchronization, the groups are synchronized, rather than
29          the individual channels.
30
31          Using these channels and then grouping them together allows for you to
32          define the maildir hierarchy as you see fit.
33        '';
34      };
35    };
36  };
37
38  # Options for configuring channel(s) that will be composed together into a group.
39  channel = { name, config, ... }: {
40    options = {
41      name = mkOption {
42        type = types.str;
43        default = name;
44        readOnly = true;
45        description = ''
46          The unique name for THIS channel in THIS group. The group will refer to
47          this channel by this name.
48
49          In addition, you can manually sync just this channel by specifying this
50          name to mbsync on the command line.
51        '';
52      };
53
54      farPattern = mkOption {
55        type = types.str;
56        default = "";
57        example = "[Gmail]/Sent Mail";
58        description = ''
59          IMAP4 patterns for which mailboxes on the remote mail server to sync.
60          If `Patterns` are specified, `farPattern`
61          is interpreted as a prefix which is not matched against the patterns,
62          and is not affected by mailbox list overrides.
63
64          If this is left as the default, then mbsync will default to the pattern
65          `INBOX`.
66        '';
67      };
68
69      nearPattern = mkOption {
70        type = types.str;
71        default = "";
72        example = "Sent";
73        description = ''
74          Name for where mail coming from the remote (far) mail server will end up
75          locally. The mailbox specified by the far pattern will be placed in
76          this directory.
77
78          If this is left as the default, then mbsync will default to the pattern
79          `INBOX`.
80        '';
81      };
82
83      patterns = mkOption {
84        type = types.listOf types.str;
85        default = [ ];
86        example = [ "INBOX" ];
87        description = ''
88          Instead of synchronizing *just* the mailboxes that
89          match the `farPattern`, use it as a prefix which is
90          not matched against the patterns, and is not affected by mailbox list
91          overrides.
92        '';
93      };
94
95      extraConfig = mkOption {
96        type = extraConfigType;
97        default = { };
98        example = literalExpression ''
99          {
100            Create = "both";
101            CopyArrivalDate = "yes";
102            MaxMessages = 10000;
103            MaxSize = "1m";
104          }
105        '';
106        description = ''
107          Extra configuration lines to add to *THIS* channel's
108          configuration.
109        '';
110      };
111    };
112  };
113
114in {
115  options.mbsync = {
116    enable = mkEnableOption "synchronization using mbsync";
117
118    flatten = mkOption {
119      type = types.nullOr types.str;
120      default = null;
121      example = ".";
122      description = ''
123        If set, flattens the hierarchy within the maildir by
124        substituting the canonical hierarchy delimiter
125        `/` with this value.
126      '';
127    };
128
129    subFolders = mkOption {
130      type = types.enum [ "Verbatim" "Maildir++" "Legacy" ];
131      default = "Verbatim";
132      example = "Maildir++";
133      description = ''
134        The on-disk folder naming style. This option has no
135        effect when {option}`flatten` is used.
136      '';
137    };
138
139    create = mkOption {
140      type = types.enum [ "none" "maildir" "imap" "both" ];
141      default = "none";
142      example = "maildir";
143      description = ''
144        Automatically create missing mailboxes within the
145        given mail store.
146      '';
147    };
148
149    remove = mkOption {
150      type = types.enum [ "none" "maildir" "imap" "both" ];
151      default = "none";
152      example = "imap";
153      description = ''
154        Propagate mailbox deletions to the given mail store.
155      '';
156    };
157
158    expunge = mkOption {
159      type = types.enum [ "none" "maildir" "imap" "both" ];
160      default = "none";
161      example = "both";
162      description = ''
163        Permanently remove messages marked for deletion from
164        the given mail store.
165      '';
166    };
167
168    patterns = mkOption {
169      type = types.listOf types.str;
170      default = [ "*" ];
171      description = ''
172        Pattern of mailboxes to synchronize.
173      '';
174    };
175
176    groups = mkOption {
177      type = types.attrsOf (types.submodule perAccountGroups);
178      default = { };
179      # The default cannot actually be empty, but contains an attribute set where
180      # the channels set is empty. If a group is specified, then a name is given,
181      # creating the attribute set.
182      description = ''
183        Some email providers (Gmail) have a different directory hierarchy for
184        synchronized email messages. Namely, when using mbsync without specifying
185        a set of channels into a group, all synchronized directories end up beneath
186        the `[Gmail]/` directory.
187
188        This option allows you to specify a group, and subsequently channels that
189        will allow you to sync your mail into an arbitrary hierarchy.
190      '';
191    };
192
193    extraConfig.channel = mkOption {
194      type = extraConfigType;
195      default = { };
196      example = literalExpression ''
197        {
198          MaxMessages = 10000;
199          MaxSize = "1m";
200        };
201      '';
202      description = ''
203        Per channel extra configuration.
204      '';
205    };
206
207    extraConfig.local = mkOption {
208      type = extraConfigType;
209      default = { };
210      description = ''
211        Local store extra configuration.
212      '';
213    };
214
215    extraConfig.remote = mkOption {
216      type = extraConfigType;
217      default = { };
218      description = ''
219        Remote store extra configuration.
220      '';
221    };
222
223    extraConfig.account = mkOption {
224      type = extraConfigType;
225      default = { };
226      example = literalExpression ''
227        {
228          PipelineDepth = 10;
229          Timeout = 60;
230        };
231      '';
232      description = ''
233        Account section extra configuration.
234      '';
235    };
236  };
237}