diff --git a/mail-config.nix b/mail-config.nix index 7541065..8003d2a 100644 --- a/mail-config.nix +++ b/mail-config.nix @@ -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; }; } diff --git a/mail-server/dovecot.nix b/mail-server/dovecot.nix index 97f5d15..8f9c6b2 100644 --- a/mail-server/dovecot.nix +++ b/mail-server/dovecot.nix @@ -14,13 +14,71 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -{ 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 + } + } + ''; } diff --git a/mail-server/services.nix b/mail-server/services.nix index fe848d9..cba29d8 100644 --- a/mail-server/services.nix +++ b/mail-server/services.nix @@ -14,30 +14,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -{ 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; }; } diff --git a/mail-server/systemd.nix b/mail-server/systemd.nix index 61767fa..0d2fe23 100644 --- a/mail-server/systemd.nix +++ b/mail-server/systemd.nix @@ -14,12 +14,17 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -{ mail_dir }: +{ mail_dir, vmail_group_name }: { # Set the correct permissions for dovecot vmail folder. See # . 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} + ''; } diff --git a/mail-server/users.nix b/mail-server/users.nix index cb1a090..3697c6f 100644 --- a/mail-server/users.nix +++ b/mail-server/users.nix @@ -14,14 +14,36 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -{ 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; }