2018-06-12 21:40:05 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2019-05-01 13:32:37 +02:00
|
|
|
cfg = config.services.getmail;
|
2018-06-12 21:40:05 +02:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
accounts =
|
|
|
|
filter (a: a.getmail.enable) (attrValues config.accounts.email.accounts);
|
2018-06-12 21:40:05 +02:00
|
|
|
|
2019-05-01 13:32:37 +02:00
|
|
|
# Note: The getmail service does not expect a path, but just the filename!
|
2020-02-02 00:39:17 +01:00
|
|
|
renderConfigFilepath = a:
|
|
|
|
if a.primary then "getmailrc" else "getmail${a.name}";
|
|
|
|
configFiles =
|
|
|
|
concatMapStringsSep " " (a: " --rcfile ${renderConfigFilepath a}") accounts;
|
|
|
|
in {
|
2018-06-12 21:40:05 +02:00
|
|
|
options = {
|
2019-05-01 13:32:37 +02:00
|
|
|
services.getmail = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption
|
|
|
|
"the getmail systemd service to automatically retrieve mail";
|
2018-06-12 21:40:05 +02:00
|
|
|
|
|
|
|
frequency = mkOption {
|
2019-05-01 13:32:37 +02:00
|
|
|
type = types.str;
|
|
|
|
default = "*:0/5";
|
2018-06-12 21:40:05 +02:00
|
|
|
example = "hourly";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
The refresh frequency. Check `man systemd.time` for
|
2019-05-01 13:32:37 +02:00
|
|
|
more information on the syntax. If you use a gpg-agent in
|
|
|
|
combination with the passwordCommand, keep the poll
|
|
|
|
frequency below the cache-ttl value (as set by the
|
2023-07-01 01:30:13 +02:00
|
|
|
`default`) to avoid pinentry asking
|
2019-05-01 13:32:37 +02:00
|
|
|
permanently for a password.
|
2018-06-12 21:40:05 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-07-07 23:24:27 +02:00
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "services.getmail" pkgs
|
|
|
|
lib.platforms.linux)
|
|
|
|
];
|
|
|
|
|
2018-06-12 21:40:05 +02:00
|
|
|
systemd.user.services.getmail = {
|
2020-02-02 00:39:17 +01:00
|
|
|
Unit = { Description = "getmail email fetcher"; };
|
2022-06-05 11:48:58 +02:00
|
|
|
Service = { ExecStart = "${pkgs.getmail6}/bin/getmail ${configFiles}"; };
|
2018-06-12 21:40:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.user.timers.getmail = {
|
2020-02-02 00:39:17 +01:00
|
|
|
Unit = { Description = "getmail email fetcher"; };
|
2018-06-12 21:40:05 +02:00
|
|
|
Timer = {
|
|
|
|
OnCalendar = "${cfg.frequency}";
|
|
|
|
Unit = "getmail.service";
|
|
|
|
};
|
2020-02-02 00:39:17 +01:00
|
|
|
Install = { WantedBy = [ "timers.target" ]; };
|
2018-06-12 21:40:05 +02:00
|
|
|
};
|
2019-05-01 13:32:37 +02:00
|
|
|
|
2018-06-12 21:40:05 +02:00
|
|
|
};
|
|
|
|
}
|