fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
1.6 KiB60 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.getmail;
8
9  accounts =
10    filter (a: a.getmail.enable) (attrValues config.accounts.email.accounts);
11
12  # Note: The getmail service does not expect a path, but just the filename!
13  renderConfigFilepath = a:
14    if a.primary then "getmailrc" else "getmail${a.name}";
15  configFiles =
16    concatMapStringsSep " " (a: " --rcfile ${renderConfigFilepath a}") accounts;
17in {
18  options = {
19    services.getmail = {
20      enable = mkEnableOption
21        "the getmail systemd service to automatically retrieve mail";
22
23      frequency = mkOption {
24        type = types.str;
25        default = "*:0/5";
26        example = "hourly";
27        description = ''
28          The refresh frequency. Check `man systemd.time` for
29          more information on the syntax. If you use a gpg-agent in
30          combination with the passwordCommand, keep the poll
31          frequency below the cache-ttl value (as set by the
32          `default`) to avoid pinentry asking
33          permanently for a password.
34        '';
35      };
36    };
37  };
38
39  config = mkIf cfg.enable {
40    assertions = [
41      (lib.hm.assertions.assertPlatform "services.getmail" pkgs
42        lib.platforms.linux)
43    ];
44
45    systemd.user.services.getmail = {
46      Unit = { Description = "getmail email fetcher"; };
47      Service = { ExecStart = "${pkgs.getmail6}/bin/getmail ${configFiles}"; };
48    };
49
50    systemd.user.timers.getmail = {
51      Unit = { Description = "getmail email fetcher"; };
52      Timer = {
53        OnCalendar = "${cfg.frequency}";
54        Unit = "getmail.service";
55      };
56      Install = { WantedBy = [ "timers.target" ]; };
57    };
58
59  };
60}