2018-06-12 19:40:05 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2019-05-01 11:32:37 +00:00
|
|
|
cfg = config.services.getmail;
|
2018-06-12 19:40:05 +00:00
|
|
|
|
2019-05-01 11:32:37 +00:00
|
|
|
accounts = filter (a: a.getmail.enable)
|
|
|
|
(attrValues config.accounts.email.accounts);
|
2018-06-12 19:40:05 +00:00
|
|
|
|
2019-05-01 11:32:37 +00:00
|
|
|
# Note: The getmail service does not expect a path, but just the filename!
|
|
|
|
renderConfigFilepath = a: if a.primary then "getmailrc" else "getmail${a.name}";
|
|
|
|
configFiles = concatMapStringsSep " " (a: " --rcfile ${renderConfigFilepath a}") accounts;
|
2018-06-12 19:40:05 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2019-05-01 11:32:37 +00:00
|
|
|
services.getmail = {
|
|
|
|
enable = mkEnableOption "the getmail systemd service to automatically retrieve mail";
|
2018-06-12 19:40:05 +00:00
|
|
|
|
|
|
|
frequency = mkOption {
|
2019-05-01 11:32:37 +00:00
|
|
|
type = types.str;
|
|
|
|
default = "*:0/5";
|
2018-06-12 19:40:05 +00:00
|
|
|
example = "hourly";
|
|
|
|
description = ''
|
|
|
|
The refresh frequency. Check <literal>man systemd.time</literal> for
|
2019-05-01 11:32:37 +00: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
|
|
|
|
<literal>default</literal>) to avoid pinentry asking
|
|
|
|
permanently for a password.
|
2018-06-12 19:40:05 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.user.services.getmail = {
|
|
|
|
Unit = {
|
|
|
|
Description = "getmail email fetcher";
|
|
|
|
};
|
|
|
|
Service = {
|
2019-05-01 11:32:37 +00:00
|
|
|
ExecStart = "${pkgs.getmail}/bin/getmail ${configFiles}";
|
2018-06-12 19:40:05 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.user.timers.getmail = {
|
|
|
|
Unit = {
|
|
|
|
Description = "getmail email fetcher";
|
|
|
|
};
|
|
|
|
Timer = {
|
|
|
|
OnCalendar = "${cfg.frequency}";
|
|
|
|
Unit = "getmail.service";
|
|
|
|
};
|
|
|
|
Install = {
|
|
|
|
WantedBy = [ "timers.target" ];
|
|
|
|
};
|
|
|
|
};
|
2019-05-01 11:32:37 +00:00
|
|
|
|
2018-06-12 19:40:05 +00:00
|
|
|
};
|
|
|
|
}
|