From 60574841c6fd2a95dd3907c73c1f11200f637346 Mon Sep 17 00:00:00 2001 From: Robin Raymond Date: Sat, 12 Aug 2017 11:27:19 +0200 Subject: [PATCH] restructuring; now works with 17.03/17.09-pre I had to remove some of the features, they need to be slowely added in again. --- mail-config.nix | 23 +++++++++++- mail-server/dovecot.nix | 26 +++++-------- mail-server/environment.nix | 23 ++++++++++++ mail-server/networking.nix | 26 +++++++++++++ mail-server/postfix.nix | 15 ++++---- mail-server.nix => mail-server/services.nix | 41 ++++++--------------- mail-server/users.nix | 27 ++++++++++++++ 7 files changed, 125 insertions(+), 56 deletions(-) create mode 100644 mail-server/environment.nix create mode 100644 mail-server/networking.nix rename mail-server.nix => mail-server/services.nix (62%) create mode 100644 mail-server/users.nix diff --git a/mail-config.nix b/mail-config.nix index 268188f..3629a1f 100644 --- a/mail-config.nix +++ b/mail-config.nix @@ -1,5 +1,5 @@ # nixos-mailserver: a simple mail server -# Copyright (C) 2016 Robin Raymond +# Copyright (C) 2016-2017 Robin Raymond # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -45,5 +45,24 @@ let virus_scanning = false; in { - imports = [ ./mail-server.nix ]; + 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; + }; + + environment = import ./mail-server/environment.nix { + inherit pkgs; + }; + + networking = import ./mail-server/networking.nix { + inherit domain host_prefix; + }; + + # TODO: Move to /mail-server/systemd.nix + # TODO: Respect setting of maildir + # 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. + systemd.services.dovecot2.preStart = "chmod 02770 /var/vmail"; } diff --git a/mail-server/dovecot.nix b/mail-server/dovecot.nix index 2af17b4..97f5d15 100644 --- a/mail-server/dovecot.nix +++ b/mail-server/dovecot.nix @@ -1,5 +1,5 @@ # nixos-mailserver: a simple mail server -# Copyright (C) 2016 Robin Raymond +# Copyright (C) 2016-2017 Robin Raymond # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -14,21 +14,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -{ config, pkgs, vmail_group_name, vmail_user_name, dovecot_maildir, enable_imap, -enable_pop3, ... }: +{ vmail_group_name, vmail_user_name, dovecot_maildir, enable_imap, enable_pop3, +... }: { - # 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. - systemd.services.dovecot2.preStart = "chmod 02770 /var/vmail"; - - services.dovecot2 = { - enable = true; - enableImap = enable_imap; # IMAP - enablePop3 = enable_pop3; # POP3 - mailGroup = vmail_group_name; - mailUser = vmail_user_name; - mailLocation = dovecot_maildir; # maildir in format "/${domain}/${user}/" - }; + enable = true; + enableImap = enable_imap; + enablePop3 = enable_pop3; + mailGroup = vmail_group_name; + mailUser = vmail_user_name; + mailLocation = dovecot_maildir; # maildir in format "/${domain}/${user}/" } diff --git a/mail-server/environment.nix b/mail-server/environment.nix new file mode 100644 index 0000000..7f4d5d7 --- /dev/null +++ b/mail-server/environment.nix @@ -0,0 +1,23 @@ +# nixos-mailserver: a simple mail server +# Copyright (C) 2016-2017 Robin Raymond +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see + +{ pkgs, ... }: + +{ + systemPackages = with pkgs; [ + dovecot opendkim openssh postfix clamav rspamd rmilter + ]; +} diff --git a/mail-server/networking.nix b/mail-server/networking.nix new file mode 100644 index 0000000..7f3897b --- /dev/null +++ b/mail-server/networking.nix @@ -0,0 +1,26 @@ +# nixos-mailserver: a simple mail server +# Copyright (C) 2016-2017 Robin Raymond +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see + +{ domain, host_prefix, ... }: + +{ + hostName = host_prefix + "." + domain; + + firewall = { + enable = true; + allowedTCPPorts = [ 25 143 587 ]; # < TODO: make this flexible + }; +} diff --git a/mail-server/postfix.nix b/mail-server/postfix.nix index 2d69a74..9db6fca 100644 --- a/mail-server/postfix.nix +++ b/mail-server/postfix.nix @@ -1,5 +1,5 @@ # nixos-mailserver: a simple mail server -# Copyright (C) 2016 Robin Raymond +# Copyright (C) 2016-2017 Robin Raymond # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -14,12 +14,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -{ config, pkgs, valias_file, vaccounts_file, ... }: +{ valiases_file, vaccounts_file, ... }: + { - services.postfix = { - enable = true; - networksStyle = "host"; - mapFiles."valias" = valias_file; - mapFiles."vaccounts" = vaccounts_file; - }; + enable = true; + networksStyle = "host"; + # mapFiles."valias" = valiases_file; + # mapFiles."vaccounts" = vaccounts_file; } diff --git a/mail-server.nix b/mail-server/services.nix similarity index 62% rename from mail-server.nix rename to mail-server/services.nix index 20e47c8..fe848d9 100644 --- a/mail-server.nix +++ b/mail-server/services.nix @@ -1,5 +1,5 @@ # nixos-mailserver: a simple mail server -# Copyright (C) 2016 Robin Raymond +# Copyright (C) 2016-2017 Robin Raymond # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -14,8 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -{ config, pkgs, mail_dir, vmail_user_name, vmail_id_start, vmail_group_name, -domain, login_accounts, valiases, host_prefix, ... }: +{ mail_dir, vmail_user_name, vmail_id_start, vmail_group_name, login_accounts, +valiases, domain, enable_imap, enable_pop3 }: let dovecot_maildir = "maildir:" + mail_dir + "/%d/%n/"; @@ -41,38 +41,21 @@ let # valiasToString :: { from = "..."; to = "..." } -> String valiasToString = x: x.from + "@" + domain + " " + x.to "@" + domain + "\n"; - # valiasFile :: [ String ] - valiasFile = map valiasToString valiases; + # valias_file :: [ String ] + valiases_file = map valiasToString valiases; in { - networking.hostName = host_prefix + "." + domain; - - environment.systemPackages = with pkgs; [ - dovecot opendkim openssh postfix clamav rspamd rmilter - ]; - - # set the vmail gid to a specific value - users.groups = { - vmail = { gid = vmail_id_start; }; - }; - - # define all users - users.extraUsers = vmail_user ++ mail_user; - - # rspamd - services.rspamd = { + rspamd = { enable = true; }; - # firewall - networking.firewall = { - enable = true; - allowedTCPPorts = [ 25 143 587 ]; # < TODO: make this flexible + postfix = import ./postfix.nix { + valiases_file = ""; vaccounts_file = ""; #< TODO: FIX }; - imports = [ - ./mail-server/dovecot.nix # dovecot - ./mail-server/postfix.nix # postfix - ]; + dovecot2 = import ./dovecot.nix { + inherit vmail_group_name vmail_user_name dovecot_maildir enable_imap + enable_pop3; + }; } diff --git a/mail-server/users.nix b/mail-server/users.nix new file mode 100644 index 0000000..cb1a090 --- /dev/null +++ b/mail-server/users.nix @@ -0,0 +1,27 @@ +# nixos-mailserver: a simple mail server +# Copyright (C) 2016-2017 Robin Raymond +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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 }: + +{ + # set the vmail gid to a specific value + users.groups = { + vmail = { gid = vmail_id_start; }; + }; + + # define all users + users.extraUsers = vmail_user ++ mail_user; +}