2009-10-12 17:36:19 +01:00
|
|
|
{ config, pkgs, ... }:
|
2009-03-06 12:27:10 +00:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
with pkgs.lib;
|
2009-03-06 12:27:10 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
let
|
|
|
|
|
2008-06-30 22:12:02 +01:00
|
|
|
cfg = config.services.dovecot;
|
|
|
|
|
2011-09-14 19:20:50 +01:00
|
|
|
dovecotConf =
|
2009-08-16 15:49:14 +01:00
|
|
|
''
|
2011-09-14 19:20:50 +01:00
|
|
|
base_dir = /var/run/dovecot/
|
2009-08-16 15:49:14 +01:00
|
|
|
|
|
|
|
protocols = imap imaps pop3 pop3s
|
|
|
|
''
|
|
|
|
+ (if cfg.sslServerCert!="" then
|
|
|
|
''
|
|
|
|
ssl_cert_file = ${cfg.sslServerCert}
|
|
|
|
ssl_key_file = ${cfg.sslServerKey}
|
|
|
|
ssl_ca_file = ${cfg.sslCACert}
|
|
|
|
'' else ''
|
|
|
|
ssl_disable = yes
|
|
|
|
disable_plaintext_auth = no
|
|
|
|
'')
|
|
|
|
|
|
|
|
+ ''
|
|
|
|
login_user = ${cfg.user}
|
|
|
|
login_chroot = no
|
|
|
|
|
|
|
|
mail_location = maildir:/var/spool/mail/%u
|
|
|
|
|
|
|
|
maildir_copy_with_hardlinks = yes
|
|
|
|
|
|
|
|
auth default {
|
2011-09-14 19:20:50 +01:00
|
|
|
mechanisms = plain login
|
2009-08-16 15:49:14 +01:00
|
|
|
userdb passwd {
|
|
|
|
}
|
|
|
|
passdb pam {
|
|
|
|
}
|
2011-09-14 19:20:50 +01:00
|
|
|
user = root
|
2009-08-16 15:49:14 +01:00
|
|
|
}
|
|
|
|
auth_debug = yes
|
|
|
|
auth_verbose = yes
|
2008-06-30 22:12:02 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
pop3_uidl_format = %08Xv%08Xu
|
2008-06-30 22:12:02 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
log_path = /var/log/dovecot.log
|
|
|
|
'';
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
confFile = pkgs.writeText "dovecot.conf" dovecotConf;
|
2008-06-30 22:12:02 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
in
|
2008-06-30 22:12:02 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
{
|
2008-06-30 22:12:02 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
###### interface
|
2008-06-30 22:12:02 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
services.dovecot = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the Dovecot POP3/IMAP server.";
|
|
|
|
};
|
2008-07-01 11:50:38 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
user = mkOption {
|
|
|
|
default = "dovecot";
|
|
|
|
description = "Dovecot user name.";
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
group = mkOption {
|
|
|
|
default = "dovecot";
|
|
|
|
description = "Dovecot group name.";
|
|
|
|
};
|
2008-06-30 22:12:02 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
sslServerCert = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Server certificate";
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
sslCACert = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "CA certificate used by the server certificate.";
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
sslServerKey = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Server key.";
|
|
|
|
};
|
2008-06-30 22:12:02 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
};
|
2008-06-30 22:12:02 +01:00
|
|
|
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
###### implementation
|
2009-03-06 12:27:10 +00:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
config = mkIf config.services.dovecot.enable {
|
2009-03-06 12:27:10 +00:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
security.pam.services = [ { name = "dovecot"; } ];
|
2009-03-06 12:27:10 +00:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = cfg.user;
|
|
|
|
uid = config.ids.uids.dovecot;
|
|
|
|
description = "Dovecot user";
|
|
|
|
group = cfg.group;
|
|
|
|
};
|
2009-03-06 12:27:10 +00:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
users.extraGroups = singleton
|
|
|
|
{ name = cfg.group;
|
|
|
|
gid = config.ids.gids.dovecot;
|
|
|
|
};
|
2009-03-06 12:27:10 +00:00
|
|
|
|
2009-10-12 19:09:34 +01:00
|
|
|
jobs.dovecot =
|
2009-10-12 17:36:19 +01:00
|
|
|
{ description = "Dovecot IMAP/POP3 server";
|
2009-03-06 12:27:10 +00:00
|
|
|
|
2012-03-04 18:44:42 +00:00
|
|
|
startOn = "started networking";
|
2009-03-06 12:27:10 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
preStart =
|
|
|
|
''
|
2011-09-14 19:20:50 +01:00
|
|
|
${pkgs.coreutils}/bin/mkdir -p /var/run/dovecot /var/run/dovecot/login
|
2012-05-17 20:43:32 +01:00
|
|
|
${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} /var/run/dovecot
|
2009-08-16 15:49:14 +01:00
|
|
|
'';
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
exec = "${pkgs.dovecot}/sbin/dovecot -F -c ${confFile}";
|
2009-08-16 15:49:14 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-03-06 12:27:10 +00:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2008-06-30 22:12:02 +01:00
|
|
|
}
|