From 2e5b76ecc64a01c07cc7a9a8425f8f5fffbc752a Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Wed, 6 Jan 2016 00:18:03 +0300 Subject: [PATCH 01/16] dovecot22: 2.2.19 -> 2.2.21 --- pkgs/servers/mail/dovecot/2.2.x.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/servers/mail/dovecot/2.2.x.nix b/pkgs/servers/mail/dovecot/2.2.x.nix index 2d38f3f5cef3..ac0df550080b 100644 --- a/pkgs/servers/mail/dovecot/2.2.x.nix +++ b/pkgs/servers/mail/dovecot/2.2.x.nix @@ -2,14 +2,14 @@ , inotify-tools, clucene_core_2, sqlite }: stdenv.mkDerivation rec { - name = "dovecot-2.2.19"; + name = "dovecot-2.2.21"; buildInputs = [ perl openssl bzip2 zlib openldap clucene_core_2 sqlite ] ++ stdenv.lib.optionals (stdenv.isLinux) [ systemd pam inotify-tools ]; src = fetchurl { url = "http://dovecot.org/releases/2.2/${name}.tar.gz"; - sha256 = "17sf5aancad4pg1vx1606k99389wg76blpqzmnmxlz4hklzix7km"; + sha256 = "080bil83gr2dski4gk2bxykg2g497kqm2hn2z4xkbw71b6g17dvs"; }; preConfigure = '' From 97e3c42523083b9217b42f54c888c6895ca1ea5b Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sat, 9 Jan 2016 16:37:28 +0300 Subject: [PATCH 02/16] dovecot22: move modules dir to /etc --- .../mail/dovecot/2.2.x-module_dir.patch | 20 +++++++++---------- pkgs/servers/mail/dovecot/2.2.x.nix | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkgs/servers/mail/dovecot/2.2.x-module_dir.patch b/pkgs/servers/mail/dovecot/2.2.x-module_dir.patch index 3ba11d41b1bd..a6edc8d83ee9 100644 --- a/pkgs/servers/mail/dovecot/2.2.x-module_dir.patch +++ b/pkgs/servers/mail/dovecot/2.2.x-module_dir.patch @@ -6,7 +6,7 @@ diff -ur dovecot-2.2.12-orig/src/auth/main.c dovecot-2.2.12/src/auth/main.c mod_set.filter_callback = auth_module_filter; - modules = module_dir_load(AUTH_MODULE_DIR, NULL, &mod_set); -+ modules = module_dir_load("/var/lib/dovecot/modules/auth", NULL, &mod_set); ++ modules = module_dir_load("/etc/dovecot/modules/auth", NULL, &mod_set); module_dir_init(modules); if (!worker) @@ -15,7 +15,7 @@ diff -ur dovecot-2.2.12-orig/src/auth/main.c dovecot-2.2.12/src/auth/main.c mod_set.ignore_missing = TRUE; - modules = module_dir_load_missing(modules, AUTH_MODULE_DIR, names, -+ modules = module_dir_load_missing(modules, "/var/lib/dovecot/modules/auth", names, ++ modules = module_dir_load_missing(modules, "/etc/dovecot/modules/auth", names, &mod_set); module_dir_init(modules); } @@ -27,7 +27,7 @@ diff -ur dovecot-2.2.12-orig/src/config/all-settings.c dovecot-2.2.12/src/config .mail_plugins = "", - .mail_plugin_dir = MODULEDIR, -+ .mail_plugin_dir = "/var/lib/dovecot/modules", ++ .mail_plugin_dir = "/etc/dovecot/modules", .mail_log_prefix = "%s(%u): ", @@ -36,7 +36,7 @@ diff -ur dovecot-2.2.12-orig/src/config/all-settings.c dovecot-2.2.12/src/config .libexec_dir = PKG_LIBEXECDIR, .mail_plugins = "", - .mail_plugin_dir = MODULEDIR, -+ .mail_plugin_dir = "/var/lib/dovecot/modules", ++ .mail_plugin_dir = "/etc/dovecot/modules", .auth_socket_path = "auth-userdb", .doveadm_socket_path = "doveadm-server", .doveadm_worker_count = 0, @@ -49,7 +49,7 @@ diff -ur dovecot-2.2.12-orig/src/config/config-parser.c dovecot-2.2.12/src/confi memset(&mod_set, 0, sizeof(mod_set)); mod_set.abi_version = DOVECOT_ABI_VERSION; - modules = module_dir_load(CONFIG_MODULE_DIR, NULL, &mod_set); -+ modules = module_dir_load("/var/lib/dovecot/modules/settings", NULL, &mod_set); ++ modules = module_dir_load("/etc/dovecot/modules/settings", NULL, &mod_set); module_dir_init(modules); i_array_init(&new_roots, 64); @@ -61,7 +61,7 @@ diff -ur dovecot-2.2.12-orig/src/dict/main.c dovecot-2.2.12/src/dict/main.c mod_set.require_init_funcs = TRUE; - modules = module_dir_load(DICT_MODULE_DIR, NULL, &mod_set); -+ modules = module_dir_load("/var/lib/dovecot/modules/dict", NULL, &mod_set); ++ modules = module_dir_load("/etc/dovecot/modules/dict", NULL, &mod_set); module_dir_init(modules); /* Register only after loading modules. They may contain SQL drivers, @@ -73,7 +73,7 @@ diff -ur dovecot-2.2.12-orig/src/doveadm/doveadm-settings.c dovecot-2.2.12/src/d .libexec_dir = PKG_LIBEXECDIR, .mail_plugins = "", - .mail_plugin_dir = MODULEDIR, -+ .mail_plugin_dir = "/var/lib/dovecot/modules", ++ .mail_plugin_dir = "/etc/dovecot/modules", .auth_socket_path = "auth-userdb", .doveadm_socket_path = "doveadm-server", .doveadm_worker_count = 0, @@ -86,7 +86,7 @@ diff -ur dovecot-2.2.12-orig/src/lib-fs/fs-api.c dovecot-2.2.12/src/lib-fs/fs-ap mod_set.ignore_missing = TRUE; - fs_modules = module_dir_load_missing(fs_modules, MODULE_DIR, -+ fs_modules = module_dir_load_missing(fs_modules, "/var/lib/dovecot/modules", ++ fs_modules = module_dir_load_missing(fs_modules, "/etc/dovecot/modules", module_name, &mod_set); module_dir_init(fs_modules); @@ -99,7 +99,7 @@ diff -ur dovecot-2.2.12-orig/src/lib-ssl-iostream/iostream-ssl.c dovecot-2.2.12/ mod_set.abi_version = DOVECOT_ABI_VERSION; mod_set.setting_name = ""; - ssl_module = module_dir_load(MODULE_DIR, plugin_name, &mod_set); -+ ssl_module = module_dir_load("/var/lib/dovecot/modules", plugin_name, &mod_set); ++ ssl_module = module_dir_load("/etc/dovecot/modules", plugin_name, &mod_set); ssl_vfuncs = module_get_symbol(ssl_module, "ssl_vfuncs"); if (ssl_vfuncs == NULL) { @@ -112,7 +112,7 @@ diff -ur dovecot-2.2.12-orig/src/lib-storage/mail-storage-settings.c dovecot-2.2 .mail_plugins = "", - .mail_plugin_dir = MODULEDIR, -+ .mail_plugin_dir = "/var/lib/dovecot/modules", ++ .mail_plugin_dir = "/etc/dovecot/modules", .mail_log_prefix = "%s(%u): ", diff --git a/pkgs/servers/mail/dovecot/2.2.x.nix b/pkgs/servers/mail/dovecot/2.2.x.nix index ac0df550080b..4488e8c86b1f 100644 --- a/pkgs/servers/mail/dovecot/2.2.x.nix +++ b/pkgs/servers/mail/dovecot/2.2.x.nix @@ -27,7 +27,7 @@ stdenv.mkDerivation rec { ''; patches = [ - # Make dovecot look for plugins in /var/lib/dovecot/modules + # Make dovecot look for plugins in /etc/dovecot/modules # so we can symlink plugins from several packages there # The symlinking needs to be done in NixOS, as part of the # dovecot service start-up From cc0e255ab975b50adb895d8d9bec5a9a66665e4a Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sat, 9 Jan 2016 19:25:05 +0300 Subject: [PATCH 03/16] dovecot22: add options for building auth modules --- pkgs/servers/mail/dovecot/2.2.x.nix | 40 ++++++++++++++++++----------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/pkgs/servers/mail/dovecot/2.2.x.nix b/pkgs/servers/mail/dovecot/2.2.x.nix index 4488e8c86b1f..2237a09a6a68 100644 --- a/pkgs/servers/mail/dovecot/2.2.x.nix +++ b/pkgs/servers/mail/dovecot/2.2.x.nix @@ -1,11 +1,21 @@ -{ stdenv, fetchurl, perl, systemd, openssl, pam, bzip2, zlib, openldap -, inotify-tools, clucene_core_2, sqlite }: +{ stdenv, lib, fetchurl, perl, pkgconfig, systemd, openssl +, bzip2, zlib, inotify-tools, pam, libcap +, clucene_core_2, icu, openldap +# Auth modules +, withMySQL ? false, libmysql +, withPgSQL ? false, postgresql +, withSQLite ? true, sqlite +}: stdenv.mkDerivation rec { name = "dovecot-2.2.21"; - buildInputs = [ perl openssl bzip2 zlib openldap clucene_core_2 sqlite ] - ++ stdenv.lib.optionals (stdenv.isLinux) [ systemd pam inotify-tools ]; + nativeBuildInputs = [ perl pkgconfig ]; + buildInputs = [ openssl bzip2 zlib clucene_core_2 icu openldap ] + ++ lib.optionals (stdenv.isLinux) [ systemd pam libcap inotify-tools ] + ++ lib.optional withMySQL libmysql + ++ lib.optional withPgSQL postgresql + ++ lib.optional withSQLite sqlite; src = fetchurl { url = "http://dovecot.org/releases/2.2/${name}.tar.gz"; @@ -13,11 +23,10 @@ stdenv.mkDerivation rec { }; preConfigure = '' - substituteInPlace src/config/settings-get.pl --replace \ - "/usr/bin/env perl" "${perl}/bin/perl" + patchShebangs src/config/settings-get.pl ''; - postInstall = stdenv.lib.optionalString stdenv.isDarwin '' + postInstall = lib.optionalString stdenv.isDarwin '' install_name_tool -change libclucene-shared.1.dylib \ ${clucene_core_2}/lib/libclucene-shared.1.dylib \ $out/lib/dovecot/lib21_fts_lucene_plugin.so @@ -28,9 +37,8 @@ stdenv.mkDerivation rec { patches = [ # Make dovecot look for plugins in /etc/dovecot/modules - # so we can symlink plugins from several packages there - # The symlinking needs to be done in NixOS, as part of the - # dovecot service start-up + # so we can symlink plugins from several packages there. + # The symlinking needs to be done in NixOS. ./2.2.x-module_dir.patch ]; @@ -39,14 +47,16 @@ stdenv.mkDerivation rec { # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=626211 "--localstatedir=/var" "--with-ldap" - "--with-lucene" "--with-ssl=openssl" - "--with-sqlite" "--with-zlib" "--with-bzlib" - ] ++ stdenv.lib.optionals (stdenv.isLinux) [ - "--with-systemdsystemunitdir=$(out)/etc/systemd/system" - ]; + "--with-ldap" + "--with-lucene" + "--with-icu" + ] ++ lib.optional (stdenv.isLinux) "--with-systemdsystemunitdir=$(out)/etc/systemd/system" + ++ lib.optional withMySQL "--with-mysql" + ++ lib.optional withPgSQL "--with-pgsql" + ++ lib.optional withSQLite "--with-sqlite"; meta = { homepage = "http://dovecot.org/"; From 57234b97df21accb693e0ac1049772b776c8d454 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sat, 9 Jan 2016 19:25:48 +0300 Subject: [PATCH 04/16] dovecot22: specify sysconfdir to use system-wide config --- pkgs/servers/mail/dovecot/2.2.x.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkgs/servers/mail/dovecot/2.2.x.nix b/pkgs/servers/mail/dovecot/2.2.x.nix index 2237a09a6a68..ec4c5c935af0 100644 --- a/pkgs/servers/mail/dovecot/2.2.x.nix +++ b/pkgs/servers/mail/dovecot/2.2.x.nix @@ -26,7 +26,13 @@ stdenv.mkDerivation rec { patchShebangs src/config/settings-get.pl ''; - postInstall = lib.optionalString stdenv.isDarwin '' + # We need this for sysconfdir, see remark below. + installFlags = [ "DESTDIR=$(out)" ]; + + postInstall = '' + cp -r $out/$out/* $out + rm -rf $out/$(echo "$out" | cut -d "/" -f2) + '' + lib.optionalString stdenv.isDarwin '' install_name_tool -change libclucene-shared.1.dylib \ ${clucene_core_2}/lib/libclucene-shared.1.dylib \ $out/lib/dovecot/lib21_fts_lucene_plugin.so @@ -46,6 +52,8 @@ stdenv.mkDerivation rec { # It will hardcode this for /var/lib/dovecot. # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=626211 "--localstatedir=/var" + # We need this so utilities default to reading /etc/dovecot/dovecot.conf file. + "--sysconfdir=/etc" "--with-ldap" "--with-ssl=openssl" "--with-zlib" From cf1883f10671d556613c24346baf3f05b5c2fec5 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sat, 9 Jan 2016 16:39:55 +0300 Subject: [PATCH 05/16] dovecot: default to 2.2 --- pkgs/top-level/all-packages.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 993f8d8be12b..f686ce754324 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -9228,7 +9228,7 @@ let dnschain = callPackage ../servers/dnschain { }; - dovecot = dovecot21; + dovecot = dovecot22; dovecot21 = callPackage ../servers/mail/dovecot { }; From c956bc774b77d9e60ed50e6d28329f71afe5bc7b Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sun, 3 Jan 2016 05:55:19 +0300 Subject: [PATCH 06/16] dovecot_pigeonhole: 0.4.3 -> 0.4.10 --- .../plugins/pigeonhole}/default.nix | 23 +++++++++++-------- pkgs/top-level/all-packages.nix | 4 +++- 2 files changed, 16 insertions(+), 11 deletions(-) rename pkgs/servers/mail/{dovecot-pigeonhole => dovecot/plugins/pigeonhole}/default.nix (73%) diff --git a/pkgs/servers/mail/dovecot-pigeonhole/default.nix b/pkgs/servers/mail/dovecot/plugins/pigeonhole/default.nix similarity index 73% rename from pkgs/servers/mail/dovecot-pigeonhole/default.nix rename to pkgs/servers/mail/dovecot/plugins/pigeonhole/default.nix index 3ee73520d7ad..385cf7d35ba8 100644 --- a/pkgs/servers/mail/dovecot-pigeonhole/default.nix +++ b/pkgs/servers/mail/dovecot/plugins/pigeonhole/default.nix @@ -1,15 +1,15 @@ -{stdenv, fetchurl, dovecot22, openssl}: +{ stdenv, fetchurl, dovecot, openssl }: stdenv.mkDerivation rec { name = "dovecot-pigeonhole-${version}"; - version = "0.4.3"; + version = "0.4.10"; src = fetchurl { url = "http://pigeonhole.dovecot.org/releases/2.2/dovecot-2.2-pigeonhole-${version}.tar.gz"; - sha256 = "0mypnkc980s3kd1bmy4f93dliwg6n8jfsac8r51jrpvv0ymz94nn"; - }; + sha256 = "0vvjj1yjr189rn8f41z5rj8gfvk24a8j33q6spb6bd6k1wbfgpz9"; + }; - buildInputs = [ dovecot22 openssl ]; + buildInputs = [ dovecot openssl ]; preConfigure = '' substituteInPlace src/managesieve/managesieve-settings.c --replace \ @@ -18,18 +18,21 @@ stdenv.mkDerivation rec { substituteInPlace src/managesieve-login/managesieve-login-settings.c --replace \ ".executable = \"managesieve-login\"" \ ".executable = \"$out/libexec/dovecot/managesieve-login\"" - ''; + ''; - configureFlags = [ - "--with-dovecot=${dovecot22}/lib/dovecot" + configureFlags = [ + "--with-dovecot=${dovecot}/lib/dovecot" "--without-dovecot-install-dirs" "--with-moduledir=$(out)/lib/dovecot" - ]; + ]; + + enableParallelBuilding = true; meta = with stdenv.lib; { homepage = http://pigeonhole.dovecot.org/; description = "A sieve plugin for the Dovecot IMAP server"; license = licenses.lgpl21; maintainers = [ maintainers.rickynils ]; - }; + platforms = platforms.linux; + }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f686ce754324..a4abd6a54a28 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -9234,7 +9234,9 @@ let dovecot22 = callPackage ../servers/mail/dovecot/2.2.x.nix { }; - dovecot_pigeonhole = callPackage ../servers/mail/dovecot-pigeonhole { }; + dovecot_pigeonhole = callPackage ../servers/mail/dovecot/plugins/pigeonhole { + dovecot = dovecot22; + }; dspam = callPackage ../servers/mail/dspam { inherit (perlPackages) NetSMTP; From ec15cea84f185846702ed366ac82e2f068eb74ea Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Wed, 6 Jan 2016 00:19:42 +0300 Subject: [PATCH 07/16] dovecot_antispam: init at 20130429 --- .../mail/dovecot/plugins/antispam/default.nix | 34 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 pkgs/servers/mail/dovecot/plugins/antispam/default.nix diff --git a/pkgs/servers/mail/dovecot/plugins/antispam/default.nix b/pkgs/servers/mail/dovecot/plugins/antispam/default.nix new file mode 100644 index 000000000000..1a1ba1ad4486 --- /dev/null +++ b/pkgs/servers/mail/dovecot/plugins/antispam/default.nix @@ -0,0 +1,34 @@ +{ stdenv, fetchhg, autoconf, automake, dovecot, openssl }: + +stdenv.mkDerivation { + name = "dovecot-antispam-20130429"; + + src = fetchhg { + url = "http://hg.dovecot.org/dovecot-antispam-plugin/"; + rev = "5ebc6aae4d7c"; + sha256 = "181i79c9sf3a80mgmycfq1f77z7fpn3j2s0qiddrj16h3yklf4gv"; + }; + + buildInputs = [ dovecot openssl ]; + nativeBuildInputs = [ autoconf automake ]; + + preConfigure = '' + ./autogen.sh + # Ugly hack; any ideas? + sed "s,^dovecot_moduledir=.*,dovecot_moduledir=$out/lib/dovecot," ${dovecot}/lib/dovecot/dovecot-config > dovecot-config + ''; + + configureFlags = [ + "--with-dovecot=." + ]; + + enableParallelBuilding = true; + + meta = with stdenv.lib; { + homepage = http://wiki2.dovecot.org/Plugins/Antispam; + description = "An antispam plugin for the Dovecot IMAP server"; + license = licenses.gpl2; + maintainers = with maintainers; [ abbradar ]; + platforms = platforms.linux; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index a4abd6a54a28..d162b6fe10f6 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -9238,6 +9238,8 @@ let dovecot = dovecot22; }; + dovecot_antispam = callPackage ../servers/mail/dovecot/plugins/antispam { }; + dspam = callPackage ../servers/mail/dspam { inherit (perlPackages) NetSMTP; }; From d1a9c55d910af49a93023f9e7de44bdf4a5cc03c Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Wed, 6 Jan 2016 23:09:06 +0300 Subject: [PATCH 08/16] nixos/dovecot: add reload command --- nixos/modules/services/mail/dovecot.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/mail/dovecot.nix b/nixos/modules/services/mail/dovecot.nix index 36bdcaca47a3..e8eaeafff3e9 100644 --- a/nixos/modules/services/mail/dovecot.nix +++ b/nixos/modules/services/mail/dovecot.nix @@ -162,7 +162,7 @@ in enablePAM = mkOption { type = types.bool; default = true; - description = "Wether to create a own Dovecot PAM service and configure PAM user logins."; + description = "Whether to create a own Dovecot PAM service and configure PAM user logins."; }; showPAMFailure = mkOption { @@ -211,6 +211,7 @@ in serviceConfig = { ExecStart = "${dovecotPkg}/sbin/dovecot -F -c ${cfg.configFile}"; + ExecReload = "${dovecotPkg}/sbin/doveadm reload -c ${cfg.configFile}"; Restart = "on-failure"; RestartSec = "1s"; StartLimitInterval = "1min"; From 9c7b067c6a22338b91f77638c06f1f9e545755cc Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Thu, 7 Jan 2016 01:27:06 +0300 Subject: [PATCH 09/16] nixos/dovecot: create user/group only if they are default --- nixos/modules/services/mail/dovecot.nix | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/nixos/modules/services/mail/dovecot.nix b/nixos/modules/services/mail/dovecot.nix index e8eaeafff3e9..ae9de6445906 100644 --- a/nixos/modules/services/mail/dovecot.nix +++ b/nixos/modules/services/mail/dovecot.nix @@ -178,22 +178,22 @@ in security.pam.services.dovecot2 = mkIf cfg.enablePAM {}; users.extraUsers = [ - { name = cfg.user; - uid = config.ids.uids.dovecot2; - description = "Dovecot user"; - group = cfg.group; - } { name = "dovenull"; uid = config.ids.uids.dovenull2; description = "Dovecot user for untrusted logins"; group = cfg.group; } - ]; + ] ++ optional (cfg.user == "dovecot2") + { name = "dovecot2"; + uid = config.ids.uids.dovecot2; + description = "Dovecot user"; + group = cfg.group; + }; - users.extraGroups = singleton { - name = cfg.group; - gid = config.ids.gids.dovecot2; - }; + users.extraGroups = optional (cfg.group == "dovecot2") + { name = "dovecot2"; + gid = config.ids.gids.dovecot2; + }; systemd.services.dovecot2 = { description = "Dovecot IMAP/POP3 server"; From 122929cda74f92555c40e9888c968e02611cb3e8 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sat, 9 Jan 2016 04:15:25 +0300 Subject: [PATCH 10/16] nixos/dovecot: use systemd's RuntimeDirectory instead of creating it by ourselves --- nixos/modules/services/mail/dovecot.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nixos/modules/services/mail/dovecot.nix b/nixos/modules/services/mail/dovecot.nix index ae9de6445906..c9406a2ac516 100644 --- a/nixos/modules/services/mail/dovecot.nix +++ b/nixos/modules/services/mail/dovecot.nix @@ -203,8 +203,6 @@ in wantedBy = [ "multi-user.target" ]; preStart = '' - mkdir -p "${baseDir}/login" - chown -R ${cfg.user}:${cfg.group} "${baseDir}" rm -f "${stateDir}/modules" ln -s "${modulesDir}" "${stateDir}/modules" ''; @@ -215,6 +213,7 @@ in Restart = "on-failure"; RestartSec = "1s"; StartLimitInterval = "1min"; + RuntimeDirectory = [ "dovecot2" ]; }; }; From b2b58642fedd4b315bf8b92a3352792fa3d77bce Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sun, 10 Jan 2016 06:54:07 +0300 Subject: [PATCH 11/16] nixos/dovecot: add 'protocols' option --- nixos/modules/services/mail/dovecot.nix | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/nixos/modules/services/mail/dovecot.nix b/nixos/modules/services/mail/dovecot.nix index c9406a2ac516..e244bdbd30bb 100644 --- a/nixos/modules/services/mail/dovecot.nix +++ b/nixos/modules/services/mail/dovecot.nix @@ -9,16 +9,10 @@ let baseDir = "/run/dovecot2"; stateDir = "/var/lib/dovecot"; - protocols = concatStrings [ - (optionalString cfg.enableImap "imap") - (optionalString cfg.enablePop3 "pop3") - (optionalString cfg.enableLmtp "lmtp") - ]; - dovecotConf = concatStrings [ '' base_dir = ${baseDir} - protocols = ${protocols} + protocols = ${concatStringsSep " " cfg.protocols} '' (if isNull cfg.sslServerCert then '' @@ -87,6 +81,12 @@ in description = "Start the LMTP listener (when Dovecot is enabled)."; }; + protocols = mkOption { + type = types.listOf types.str; + default = [ ]; + description = "Additional listeners to start when Dovecot is enabled."; + }; + package = mkOption { type = types.package; default = pkgs.dovecot22; @@ -177,6 +177,11 @@ in security.pam.services.dovecot2 = mkIf cfg.enablePAM {}; + services.dovecot2.protocols = + optional cfg.enableImap "imap" + ++ optional cfg.enablePop3 "pop3" + ++ optional cfg.enableLmtp "lmtp"; + users.extraUsers = [ { name = "dovenull"; uid = config.ids.uids.dovenull2; @@ -220,7 +225,7 @@ in environment.systemPackages = [ dovecotPkg ]; assertions = [ - { assertion = cfg.enablePop3 || cfg.enableImap; + { assertion = intersectLists cfg.protocols [ "pop3" "imap" ] != []; message = "dovecot needs at least one of the IMAP or POP3 listeners enabled"; } { assertion = isNull cfg.sslServerCert == isNull cfg.sslServerKey From 94a43b41af1204f4a87261ddb0820c5c8e3bc2c8 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sun, 10 Jan 2016 06:58:56 +0300 Subject: [PATCH 12/16] nixos/dovecot: add dovecot package to modules, force proper dovecot version --- nixos/modules/services/mail/dovecot.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/mail/dovecot.nix b/nixos/modules/services/mail/dovecot.nix index e244bdbd30bb..c034e5e04700 100644 --- a/nixos/modules/services/mail/dovecot.nix +++ b/nixos/modules/services/mail/dovecot.nix @@ -55,7 +55,7 @@ let ]; modulesDir = pkgs.symlinkJoin "dovecot-modules" - (map (module: "${module}/lib/dovecot") cfg.modules); + (map (pkg: "${pkg}/lib/dovecot") ([ dovecotPkg ] ++ map (module: module.override { dovecot = dovecotPkg; }) cfg.modules)); in { From 70e77f9b53b036edfc9300ce3a16ecc637c5f6c3 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sun, 10 Jan 2016 07:00:34 +0300 Subject: [PATCH 13/16] nixos/dovecot: use new modules directory --- nixos/modules/services/mail/dovecot.nix | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/nixos/modules/services/mail/dovecot.nix b/nixos/modules/services/mail/dovecot.nix index c034e5e04700..974dfb708f1b 100644 --- a/nixos/modules/services/mail/dovecot.nix +++ b/nixos/modules/services/mail/dovecot.nix @@ -135,7 +135,7 @@ in example = literalExample "[ pkgs.dovecot_pigeonhole ]"; description = '' Symlinks the contents of lib/dovecot of every given package into - /var/lib/dovecot/modules. This will make the given modules available + /etc/dovecot/modules. This will make the given modules available if a dovecot package with the module_dir patch applied (like pkgs.dovecot22, the default) is being used. ''; @@ -200,6 +200,8 @@ in gid = config.ids.gids.dovecot2; }; + environment.etc."dovecot/modules".source = modulesDir; + systemd.services.dovecot2 = { description = "Dovecot IMAP/POP3 server"; @@ -207,11 +209,6 @@ in wants = [ "keys.target" ]; wantedBy = [ "multi-user.target" ]; - preStart = '' - rm -f "${stateDir}/modules" - ln -s "${modulesDir}" "${stateDir}/modules" - ''; - serviceConfig = { ExecStart = "${dovecotPkg}/sbin/dovecot -F -c ${cfg.configFile}"; ExecReload = "${dovecotPkg}/sbin/doveadm reload -c ${cfg.configFile}"; From 39bbac96afce0624b7ea57461431efcdabdd5fc8 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sun, 10 Jan 2016 07:02:24 +0300 Subject: [PATCH 14/16] nixos/dovecot: symlink system-wide config and use it --- nixos/modules/services/mail/dovecot.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/mail/dovecot.nix b/nixos/modules/services/mail/dovecot.nix index 974dfb708f1b..a2a93a520e9b 100644 --- a/nixos/modules/services/mail/dovecot.nix +++ b/nixos/modules/services/mail/dovecot.nix @@ -201,6 +201,7 @@ in }; environment.etc."dovecot/modules".source = modulesDir; + environment.etc."dovecot/dovecot.conf".source = cfg.configFile; systemd.services.dovecot2 = { description = "Dovecot IMAP/POP3 server"; @@ -208,10 +209,11 @@ in after = [ "keys.target" "network.target" ]; wants = [ "keys.target" ]; wantedBy = [ "multi-user.target" ]; + restartTriggers = [ cfg.configFile ]; serviceConfig = { - ExecStart = "${dovecotPkg}/sbin/dovecot -F -c ${cfg.configFile}"; - ExecReload = "${dovecotPkg}/sbin/doveadm reload -c ${cfg.configFile}"; + ExecStart = "${dovecotPkg}/sbin/dovecot -F"; + ExecReload = "${dovecotPkg}/sbin/doveadm reload"; Restart = "on-failure"; RestartSec = "1s"; StartLimitInterval = "1min"; From b781cf1a12ce77fd29ec0656bb04895b0cdaecf7 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sun, 10 Jan 2016 07:05:12 +0300 Subject: [PATCH 15/16] nixos/dovecot: add sieveScripts support --- nixos/modules/services/mail/dovecot.nix | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/nixos/modules/services/mail/dovecot.nix b/nixos/modules/services/mail/dovecot.nix index a2a93a520e9b..efe6a3beb9ae 100644 --- a/nixos/modules/services/mail/dovecot.nix +++ b/nixos/modules/services/mail/dovecot.nix @@ -51,6 +51,12 @@ let } '') + (optionalString (cfg.sieveScripts != {}) '' + plugin { + ${concatStringsSep "\n" (mapAttrsToList (to: from: "sieve_${to} = ${stateDir}/sieve/${to}") cfg.sieveScripts)} + } + '') + cfg.extraConfig ]; @@ -165,6 +171,12 @@ in description = "Whether to create a own Dovecot PAM service and configure PAM user logins."; }; + sieveScripts = mkOption { + type = types.attrsOf types.path; + default = {}; + description = "Sieve scripts to be executed. Key is a sequence, e.g. 'before2', 'after' etc."; + }; + showPAMFailure = mkOption { type = types.bool; default = false; @@ -219,6 +231,22 @@ in StartLimitInterval = "1min"; RuntimeDirectory = [ "dovecot2" ]; }; + + preStart = '' + rm -rf ${stateDir}/sieve + '' + optionalString (cfg.sieveScripts != {}) '' + mkdir -p ${stateDir}/sieve + ${concatStringsSep "\n" (mapAttrsToList (to: from: '' + if [ -d '${from}' ]; then + mkdir '${stateDir}/sieve/${to}' + cp ${from}/*.sieve '${stateDir}/sieve/${to}' + else + cp '${from}' '${stateDir}/sieve/${to}' + fi + ${pkgs.dovecot_pigeonhole}/bin/sievec '${stateDir}/sieve/${to}' + '') cfg.sieveScripts)} + chown -R '${cfg.user}:${cfg.group}' ${stateDir}/sieve + ''; }; environment.systemPackages = [ dovecotPkg ]; From 5b5e2c05c41de4d0aa298eab133923f2feb851a2 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sun, 10 Jan 2016 07:07:26 +0300 Subject: [PATCH 16/16] nixos/dovecot: add mail user and group --- nixos/modules/services/mail/dovecot.nix | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/mail/dovecot.nix b/nixos/modules/services/mail/dovecot.nix index efe6a3beb9ae..11e8b26c75ef 100644 --- a/nixos/modules/services/mail/dovecot.nix +++ b/nixos/modules/services/mail/dovecot.nix @@ -27,6 +27,8 @@ let '' default_internal_user = ${cfg.user} + ${optionalString (cfg.mailUser != null) "mail_uid = ${cfg.mailUser}"} + ${optionalString (cfg.mailGroup != null) "mail_gid = ${cfg.mailGroup}"} mail_location = ${cfg.mailLocation} @@ -135,6 +137,18 @@ in ''; }; + mailUser = mkOption { + type = types.nullOr types.str; + default = null; + description = "Default user to store mail for virtual users."; + }; + + mailGroup = mkOption { + type = types.nullOr types.str; + default = null; + description = "Default group to store mail for virtual users."; + }; + modules = mkOption { type = types.listOf types.package; default = []; @@ -245,7 +259,7 @@ in fi ${pkgs.dovecot_pigeonhole}/bin/sievec '${stateDir}/sieve/${to}' '') cfg.sieveScripts)} - chown -R '${cfg.user}:${cfg.group}' ${stateDir}/sieve + chown -R '${cfg.mailUser}:${cfg.mailGroup}' '${stateDir}/sieve' ''; };