summaryrefslogtreecommitdiff
path: root/modules/services/mail/offlineimap.nix
blob: 81c8bdbb24cbc3d5d2a8cd540d2a14c861c5262d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.offlineimap;
in {

  options.services.offlineimap = {
    enable = mkEnableOption "Offlineimap, a software to dispose your mailbox(es) as a local Maildir(s)";

    package = mkOption {
      type = types.package;
      default = pkgs.offlineimap;
      defaultText = "pkgs.offlineimap";
      description = "Offlineimap derivation to use.";
    };

    path = mkOption {
      type = types.listOf types.path;
      default = [];
      example = literalExpression "[ pkgs.pass pkgs.bash pkgs.notmuch ]";
      description = "List of derivations to put in Offlineimap's path.";
    };

    startInterval = mkOption {
      type = types.nullOr types.int;
      default = 300;
      description = "Optional key to start offlineimap services each N seconds";
    };

    runQuick = mkOption {
      type = types.bool;
      default = false;
      description = ''
        Run only quick synchronizations.
        Ignore any flag updates on IMAP servers. If a flag on the remote IMAP changes, and we have the message locally, it will be left untouched in a quick run.
      '';
    };

    extraConfig = mkOption {
      type = types.lines;
      default = "";
      description = "Additional text to be appended to {file}`offlineimaprc`.";
    };
  };

  config = mkIf cfg.enable {
    environment.systemPackages = [ cfg.package ];
    environment.etc."offlineimaprc".text = cfg.extraConfig;
    launchd.user.agents.offlineimap = {
      path                            = [ cfg.package ];
      command                         = "${cfg.package}/bin/offlineimap -c /etc/offlineimaprc" + optionalString (cfg.runQuick) " -q";
      serviceConfig.KeepAlive         = false;
      serviceConfig.RunAtLoad         = true;
      serviceConfig.StartInterval     = cfg.startInterval;
      serviceConfig.StandardErrorPath = "/var/log/offlineimap.log";
      serviceConfig.StandardOutPath   = "/var/log/offlineimap.log";
    };
  };
}