fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
2.7 KiB106 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.mbsync;
8
9  mbsyncOptions = [ "--all" ] ++ optional (cfg.verbose) "--verbose"
10    ++ optional (cfg.configFile != null) "--config ${cfg.configFile}";
11
12in {
13  meta.maintainers = [ maintainers.pjones ];
14
15  options.services.mbsync = {
16    enable = mkEnableOption "mbsync";
17
18    package = mkOption {
19      type = types.package;
20      default = pkgs.isync;
21      defaultText = literalExpression "pkgs.isync";
22      example = literalExpression "pkgs.isync";
23      description = "The package to use for the mbsync binary.";
24    };
25
26    frequency = mkOption {
27      type = types.str;
28      default = "*:0/5";
29      description = ''
30        How often to run mbsync.  This value is passed to the systemd
31        timer configuration as the onCalendar option.  See
32        {manpage}`systemd.time(7)`
33        for more information about the format.
34      '';
35    };
36
37    verbose = mkOption {
38      type = types.bool;
39      default = true;
40      description = ''
41        Whether mbsync should produce verbose output.
42      '';
43    };
44
45    configFile = mkOption {
46      type = types.nullOr types.path;
47      default = null;
48      description = ''
49        Optional configuration file to link to use instead of
50        the default file ({file}`~/.mbsyncrc`).
51      '';
52    };
53
54    preExec = mkOption {
55      type = types.nullOr types.str;
56      default = null;
57      example = "mkdir -p %h/mail";
58      description = ''
59        An optional command to run before mbsync executes.  This is
60        useful for creating the directories mbsync is going to use.
61      '';
62    };
63
64    postExec = mkOption {
65      type = types.nullOr types.str;
66      default = null;
67      example = "\${pkgs.mu}/bin/mu index";
68      description = ''
69        An optional command to run after mbsync executes successfully.
70        This is useful for running mailbox indexing tools.
71      '';
72    };
73  };
74
75  config = mkIf cfg.enable {
76    assertions = [
77      (lib.hm.assertions.assertPlatform "services.mbsync" pkgs
78        lib.platforms.linux)
79    ];
80
81    systemd.user.services.mbsync = {
82      Unit = { Description = "mbsync mailbox synchronization"; };
83
84      Service = {
85        Type = "oneshot";
86        ExecStart =
87          "${cfg.package}/bin/mbsync ${concatStringsSep " " mbsyncOptions}";
88      } // (optionalAttrs (cfg.postExec != null) {
89        ExecStartPost = cfg.postExec;
90      }) // (optionalAttrs (cfg.preExec != null) {
91        ExecStartPre = cfg.preExec;
92      });
93    };
94
95    systemd.user.timers.mbsync = {
96      Unit = { Description = "mbsync mailbox synchronization"; };
97
98      Timer = {
99        OnCalendar = cfg.frequency;
100        Unit = "mbsync.service";
101      };
102
103      Install = { WantedBy = [ "timers.target" ]; };
104    };
105  };
106}