2009-10-12 18:36:19 +02:00
|
|
|
{ config, pkgs, ... }:
|
2009-03-06 13:27:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
with pkgs.lib;
|
2009-03-06 13:27:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
let
|
|
|
|
|
2008-06-30 23:12:02 +02:00
|
|
|
startingDependency = if config.services.gw6c.enable then "gw6c" else "network-interfaces";
|
|
|
|
|
|
|
|
cfg = config.services.dovecot;
|
|
|
|
|
|
|
|
dovecotConf =
|
2009-08-16 16:49:14 +02:00
|
|
|
''
|
|
|
|
base_dir = /var/run/dovecot/
|
|
|
|
|
|
|
|
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 {
|
|
|
|
mechanisms = plain login
|
|
|
|
userdb passwd {
|
|
|
|
}
|
|
|
|
passdb pam {
|
|
|
|
}
|
|
|
|
user = root
|
|
|
|
}
|
|
|
|
auth_debug = yes
|
|
|
|
auth_verbose = yes
|
2008-06-30 23:12:02 +02:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
pop3_uidl_format = %08Xv%08Xu
|
2008-06-30 23:12:02 +02:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
log_path = /var/log/dovecot.log
|
|
|
|
'';
|
|
|
|
|
|
|
|
confFile = pkgs.writeText "dovecot.conf" dovecotConf;
|
2008-06-30 23:12:02 +02:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
in
|
2008-06-30 23:12:02 +02:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
{
|
2008-06-30 23:12:02 +02:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
###### interface
|
2008-06-30 23:12:02 +02:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
options = {
|
|
|
|
|
|
|
|
services.dovecot = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the Dovecot POP3/IMAP server.";
|
|
|
|
};
|
2008-07-01 12:50:38 +02:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
user = mkOption {
|
|
|
|
default = "dovecot";
|
|
|
|
description = "Dovecot user name.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
default = "dovecot";
|
|
|
|
description = "Dovecot group name.";
|
|
|
|
};
|
2008-06-30 23:12:02 +02:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
sslServerCert = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Server certificate";
|
|
|
|
};
|
|
|
|
|
|
|
|
sslCACert = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "CA certificate used by the server certificate.";
|
|
|
|
};
|
|
|
|
|
|
|
|
sslServerKey = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Server key.";
|
|
|
|
};
|
2008-06-30 23:12:02 +02:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
2008-06-30 23:12:02 +02:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
|
|
|
|
###### implementation
|
2009-03-06 13:27:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
config = mkIf config.services.dovecot.enable {
|
2009-03-06 13:27:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
security.pam.services = [ { name = "dovecot"; } ];
|
2009-03-06 13:27:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = cfg.user;
|
|
|
|
uid = config.ids.uids.dovecot;
|
|
|
|
description = "Dovecot user";
|
|
|
|
group = cfg.group;
|
|
|
|
};
|
2009-03-06 13:27:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
users.extraGroups = singleton
|
|
|
|
{ name = cfg.group;
|
|
|
|
gid = config.ids.gids.dovecot;
|
|
|
|
};
|
2009-03-06 13:27:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
jobAttrs.dovecot =
|
|
|
|
{ description = "Dovecot IMAP/POP3 server";
|
2009-03-06 13:27:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
startOn = "${startingDependency}/started";
|
2009-03-06 13:27:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
${pkgs.coreutils}/bin/mkdir -p /var/run/dovecot /var/run/dovecot/login
|
|
|
|
${pkgs.coreutils}/bin/chown -R ${cfg.user}.${cfg.group} /var/run/dovecot
|
2009-08-16 16:49:14 +02:00
|
|
|
'';
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
exec = "${pkgs.dovecot}/sbin/dovecot -F -c ${confFile}";
|
2009-08-16 16:49:14 +02:00
|
|
|
};
|
|
|
|
|
2009-03-06 13:27:10 +01:00
|
|
|
};
|
2009-08-16 16:49:14 +02:00
|
|
|
|
2008-06-30 23:12:02 +02:00
|
|
|
}
|