finish up dovecot configuration
also factor out users into own file
This commit is contained in:
parent
4fdace2538
commit
1d53a88a21
5 changed files with 103 additions and 33 deletions
|
@ -46,8 +46,8 @@ let
|
|||
in
|
||||
{
|
||||
services = import ./mail-server/services.nix {
|
||||
inherit mail_dir vmail_user_name vmail_id_start vmail_group_name
|
||||
login_accounts valiases domain enable_imap enable_pop3;
|
||||
inherit mail_dir vmail_user_name vmail_group_name valiases domain
|
||||
enable_imap enable_pop3;
|
||||
};
|
||||
|
||||
environment = import ./mail-server/environment.nix {
|
||||
|
@ -59,6 +59,11 @@ in
|
|||
};
|
||||
|
||||
systemd = import ./mail-server/systemd.nix {
|
||||
inherit mail_dir;
|
||||
inherit mail_dir vmail_group_name;
|
||||
};
|
||||
|
||||
users = import ./mail-server/users.nix {
|
||||
inherit vmail_id_start vmail_user_name vmail_group_name domain mail_dir
|
||||
login_accounts;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -14,13 +14,71 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
{ vmail_group_name, vmail_user_name, dovecot_maildir, enable_imap, enable_pop3,
|
||||
{ vmail_group_name, vmail_user_name, mail_dir, enable_imap, enable_pop3,
|
||||
... }:
|
||||
let
|
||||
# maildir in format "/${domain}/${user}/"
|
||||
dovecot_maildir = "maildir:${mail_dir}/%d/%n/";
|
||||
in
|
||||
{
|
||||
enable = true;
|
||||
enableImap = enable_imap;
|
||||
enablePop3 = enable_pop3;
|
||||
mailGroup = vmail_group_name;
|
||||
mailUser = vmail_user_name;
|
||||
mailLocation = dovecot_maildir; # maildir in format "/${domain}/${user}/"
|
||||
mailLocation = dovecot_maildir;
|
||||
#sslServerCert = "/etc/nixos/cert/${cert_file}"; // TODO: Define
|
||||
#sslServerKey = "/etc/nixos/cert/${key_file}"; // TODO: Define
|
||||
enableLmtp = true;
|
||||
extraConfig = ''
|
||||
#Extra Config
|
||||
mail_access_groups = ${vmail_group_name}
|
||||
ssl = required
|
||||
|
||||
service lmtp {
|
||||
unix_listener /var/lib/postfix/queue/private/dovecot-lmtp {
|
||||
group = postfix
|
||||
mode = 0600
|
||||
user = postfix # TODO: < make variable
|
||||
}
|
||||
}
|
||||
|
||||
service auth {
|
||||
unix_listener /var/lib/postfix/queue/private/auth {
|
||||
mode = 0660
|
||||
user = postfix # TODO: < make variable
|
||||
group = postfix # TODO: < make variable
|
||||
}
|
||||
}
|
||||
|
||||
auth_mechanisms = plain login
|
||||
|
||||
namespace inbox {
|
||||
|
||||
#prefix = INBOX.
|
||||
# the namespace prefix isn't added again to the mailbox names.
|
||||
inbox = yes
|
||||
# ...
|
||||
|
||||
mailbox "Trash" {
|
||||
auto = no
|
||||
special_use = \Trash
|
||||
}
|
||||
|
||||
mailbox "Junk" {
|
||||
auto = subscribe
|
||||
special_use = \Junk
|
||||
}
|
||||
|
||||
mailbox "Drafts" {
|
||||
auto = subscribe
|
||||
special_use = \Drafts
|
||||
}
|
||||
|
||||
mailbox "Sent" {
|
||||
auto = subscribe
|
||||
special_use = \Sent
|
||||
}
|
||||
}
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -14,30 +14,10 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
{ mail_dir, vmail_user_name, vmail_id_start, vmail_group_name, login_accounts,
|
||||
valiases, domain, enable_imap, enable_pop3 }:
|
||||
{ mail_dir, vmail_user_name, vmail_group_name, valiases, domain, enable_imap,
|
||||
enable_pop3 }:
|
||||
|
||||
let
|
||||
dovecot_maildir = "maildir:" + mail_dir + "/%d/%n/";
|
||||
vmail_user = [{
|
||||
name = vmail_user_name;
|
||||
isNormalUser = false;
|
||||
uid = vmail_id_start;
|
||||
home = mail_dir;
|
||||
createHome = true;
|
||||
group = vmail_group_name;
|
||||
}];
|
||||
|
||||
# accountsToUser :: String -> UserRecord
|
||||
accountsToUser = x: {
|
||||
name = x + "@" + domain;
|
||||
isNormalUser = false;
|
||||
group = vmail_group_name;
|
||||
};
|
||||
|
||||
# mail_user :: [ UserRecord ]
|
||||
mail_user = map accountsToUser login_accounts;
|
||||
|
||||
# valiasToString :: { from = "..."; to = "..." } -> String
|
||||
valiasToString = x: x.from + "@" + domain + " " + x.to "@" + domain + "\n";
|
||||
|
||||
|
@ -55,7 +35,7 @@ in
|
|||
};
|
||||
|
||||
dovecot2 = import ./dovecot.nix {
|
||||
inherit vmail_group_name vmail_user_name dovecot_maildir enable_imap
|
||||
inherit vmail_group_name vmail_user_name mail_dir enable_imap
|
||||
enable_pop3;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -14,12 +14,17 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
{ mail_dir }:
|
||||
{ mail_dir, vmail_group_name }:
|
||||
|
||||
{
|
||||
# Set the correct permissions for dovecot vmail folder. See
|
||||
# <http://wiki2.dovecot.org/SharedMailboxes/Permissions>. We choose
|
||||
# to use the systemd service to set the folder permissions whenever
|
||||
# dovecot gets started.
|
||||
services.dovecot2.preStart = ("mkdir -p " + mail_dir + "; chmod 02770 " + mail_dir);
|
||||
services.dovecot2.preStart =
|
||||
''
|
||||
mkdir -p ${mail_dir}
|
||||
chgrp ${vmail_group_name} ${mail_dir}
|
||||
chmod 02770 ${mail_dir}
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -14,14 +14,36 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
{ vmail_id_start, vmail_user, mail_user }:
|
||||
{ vmail_id_start, vmail_user_name, vmail_group_name, domain, mail_dir,
|
||||
login_accounts }:
|
||||
|
||||
let
|
||||
vmail_user = [{
|
||||
name = vmail_user_name;
|
||||
isNormalUser = false;
|
||||
uid = vmail_id_start;
|
||||
home = mail_dir;
|
||||
createHome = true;
|
||||
group = vmail_group_name;
|
||||
}];
|
||||
|
||||
# accountsToUser :: String -> UserRecord
|
||||
accountsToUser = x: {
|
||||
name = x + "@" + domain;
|
||||
isNormalUser = false;
|
||||
group = vmail_group_name;
|
||||
};
|
||||
|
||||
# mail_user :: [ UserRecord ]
|
||||
mail_user = map accountsToUser login_accounts;
|
||||
|
||||
in
|
||||
{
|
||||
# set the vmail gid to a specific value
|
||||
users.groups = {
|
||||
groups = {
|
||||
vmail = { gid = vmail_id_start; };
|
||||
};
|
||||
|
||||
# define all users
|
||||
users.extraUsers = vmail_user ++ mail_user;
|
||||
extraUsers = vmail_user ++ mail_user;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue