2011-10-27 20:43:20 +01:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.dovecot2;
|
|
|
|
|
|
|
|
dovecotConf =
|
|
|
|
''
|
|
|
|
base_dir = /var/run/dovecot2/
|
|
|
|
|
2012-09-29 23:53:50 +01:00
|
|
|
protocols = ${optionalString cfg.enableImap "imap"} ${optionalString cfg.enablePop3 "pop3"}
|
2011-10-27 20:43:20 +01:00
|
|
|
''
|
|
|
|
+ (if cfg.sslServerCert!="" then
|
|
|
|
''
|
2012-09-21 11:28:49 +01:00
|
|
|
ssl_cert = <${cfg.sslServerCert}
|
|
|
|
ssl_key = <${cfg.sslServerKey}
|
|
|
|
ssl_ca = <${cfg.sslCACert}
|
2012-09-21 11:26:53 +01:00
|
|
|
disable_plaintext_auth = yes
|
2011-10-27 20:43:20 +01:00
|
|
|
'' else ''
|
|
|
|
ssl = no
|
|
|
|
disable_plaintext_auth = no
|
|
|
|
'')
|
|
|
|
|
|
|
|
+ ''
|
|
|
|
default_internal_user = ${cfg.user}
|
|
|
|
|
2012-06-10 16:07:25 +01:00
|
|
|
mail_location = ${cfg.mailLocation}
|
2011-10-27 20:43:20 +01:00
|
|
|
|
|
|
|
maildir_copy_with_hardlinks = yes
|
|
|
|
|
|
|
|
auth_mechanisms = plain login
|
|
|
|
service auth {
|
|
|
|
user = root
|
|
|
|
}
|
|
|
|
userdb {
|
2011-10-27 23:04:08 +01:00
|
|
|
driver = passwd
|
2011-10-27 20:43:20 +01:00
|
|
|
}
|
|
|
|
passdb {
|
2011-10-27 23:04:08 +01:00
|
|
|
driver = pam
|
|
|
|
args = dovecot2
|
2011-10-27 20:43:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pop3_uidl_format = %08Xv%08Xu
|
2012-09-21 15:04:46 +01:00
|
|
|
'' + cfg.extraConfig;
|
2011-10-27 20:43:20 +01:00
|
|
|
|
|
|
|
confFile = pkgs.writeText "dovecot.conf" dovecotConf;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.dovecot2 = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the Dovecot 2.x POP3/IMAP server.";
|
|
|
|
};
|
|
|
|
|
2012-09-29 23:53:50 +01:00
|
|
|
enablePop3 = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = "Start the POP3 listener (when Dovecot is enabled).";
|
|
|
|
};
|
|
|
|
|
|
|
|
enableImap = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = "Start the IMAP listener (when Dovecot is enabled).";
|
|
|
|
};
|
|
|
|
|
2011-10-27 20:43:20 +01:00
|
|
|
user = mkOption {
|
|
|
|
default = "dovecot2";
|
|
|
|
description = "Dovecot user name.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
default = "dovecot2";
|
|
|
|
description = "Dovecot group name.";
|
|
|
|
};
|
|
|
|
|
2012-09-21 15:04:46 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
example = "mail_debug = yes";
|
|
|
|
description = "Additional entries to put verbatim into Dovecot's config file.";
|
|
|
|
};
|
|
|
|
|
2012-06-10 16:07:25 +01:00
|
|
|
mailLocation = mkOption {
|
|
|
|
default = "maildir:/var/spool/mail/%u"; /* Same as inbox, as postfix */
|
|
|
|
example = "maildir:~/mail:INBOX=/var/spool/mail/%u";
|
|
|
|
description = ''
|
|
|
|
Location that dovecot will use for mail folders. Dovecot mail_location option.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-10-27 20:43:20 +01:00
|
|
|
sslServerCert = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Server certificate";
|
|
|
|
};
|
|
|
|
|
|
|
|
sslCACert = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "CA certificate used by the server certificate.";
|
|
|
|
};
|
|
|
|
|
|
|
|
sslServerKey = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Server key.";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.dovecot2.enable {
|
|
|
|
|
|
|
|
security.pam.services = [ { name = "dovecot2"; } ];
|
|
|
|
|
|
|
|
users.extraUsers = [
|
|
|
|
{ name = cfg.user;
|
|
|
|
uid = config.ids.uids.dovecot2;
|
|
|
|
description = "Dovecot user";
|
|
|
|
group = cfg.group;
|
|
|
|
}
|
|
|
|
{ name = "dovenull";
|
|
|
|
uid = config.ids.uids.dovenull2;
|
|
|
|
description = "Dovecot user for untrusted logins";
|
|
|
|
group = cfg.group;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
users.extraGroups = singleton
|
|
|
|
{ name = cfg.group;
|
|
|
|
gid = config.ids.gids.dovecot2;
|
|
|
|
};
|
|
|
|
|
|
|
|
jobs.dovecot2 =
|
|
|
|
{ description = "Dovecot IMAP/POP3 server";
|
|
|
|
|
2012-03-04 18:44:42 +00:00
|
|
|
startOn = "started networking";
|
2011-10-27 20:43:20 +01:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
${pkgs.coreutils}/bin/mkdir -p /var/run/dovecot2 /var/run/dovecot2/login
|
2012-05-17 20:43:32 +01:00
|
|
|
${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} /var/run/dovecot2
|
2011-10-27 20:43:20 +01:00
|
|
|
'';
|
|
|
|
|
2012-09-25 10:24:35 +01:00
|
|
|
exec = "${pkgs.dovecot}/sbin/dovecot -F -c ${confFile}";
|
2011-10-27 20:43:20 +01:00
|
|
|
};
|
|
|
|
|
2012-09-25 10:24:35 +01:00
|
|
|
environment.systemPackages = [ pkgs.dovecot ];
|
2011-10-27 23:04:08 +01:00
|
|
|
|
2012-09-29 23:53:50 +01:00
|
|
|
assertions = [{ assertion = cfg.enablePop3 || cfg.enableImap;
|
|
|
|
message = "dovecot needs at least one of the IMAP or POP3 listeners enabled";}];
|
|
|
|
|
2011-10-27 20:43:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|