2016-07-25 17:40:58 +02:00
|
|
|
# nixos-mailserver: a simple mail server
|
2018-01-29 10:34:27 +01:00
|
|
|
# Copyright (C) 2016-2018 Robin Raymond
|
2016-07-25 17:40:58 +02:00
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>
|
|
|
|
|
2017-09-03 11:13:34 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
2020-03-06 18:27:47 +01:00
|
|
|
with (import ./common.nix { inherit config pkgs lib; });
|
2017-08-13 11:51:07 +02:00
|
|
|
|
2017-08-12 12:28:46 +02:00
|
|
|
let
|
2017-09-03 11:13:34 +02:00
|
|
|
cfg = config.mailserver;
|
|
|
|
|
2020-03-06 18:27:47 +01:00
|
|
|
passwdDir = "/run/dovecot2";
|
2023-05-20 00:12:02 +02:00
|
|
|
passwdFile = "${passwdDir}/passwd";
|
2023-03-16 14:59:05 +01:00
|
|
|
userdbFile = "${passwdDir}/userdb";
|
2023-05-20 00:12:02 +02:00
|
|
|
# This file contains the ldap bind password
|
|
|
|
ldapConfFile = "${passwdDir}/dovecot-ldap.conf.ext";
|
2020-07-13 14:00:00 +02:00
|
|
|
bool2int = x: if x then "1" else "0";
|
|
|
|
|
2018-02-02 21:37:29 +01:00
|
|
|
maildirLayoutAppendix = lib.optionalString cfg.useFsLayout ":LAYOUT=fs";
|
2023-03-12 18:13:51 +01:00
|
|
|
maildirUTF8FolderNames = lib.optionalString cfg.useUTF8FolderNames ":UTF-8";
|
2017-08-12 18:27:22 +02:00
|
|
|
|
2018-02-02 21:37:29 +01:00
|
|
|
# maildir in format "/${domain}/${user}"
|
2020-07-13 14:00:00 +02:00
|
|
|
dovecotMaildir =
|
2024-11-05 23:53:52 +01:00
|
|
|
"maildir:${cfg.mailDirectory}/%d/%n/mail${maildirLayoutAppendix}${maildirUTF8FolderNames}"
|
2021-03-11 20:53:38 +01:00
|
|
|
+ (lib.optionalString (cfg.indexDir != null)
|
|
|
|
":INDEX=${cfg.indexDir}/%d/%n"
|
2020-07-13 14:00:00 +02:00
|
|
|
);
|
2018-05-04 14:56:33 +02:00
|
|
|
|
|
|
|
postfixCfg = config.services.postfix;
|
2018-05-15 04:17:18 +02:00
|
|
|
dovecot2Cfg = config.services.dovecot2;
|
|
|
|
|
|
|
|
stateDir = "/var/lib/dovecot";
|
|
|
|
|
|
|
|
pipeBin = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "pipe_bin";
|
|
|
|
src = ./dovecot/pipe_bin;
|
|
|
|
buildInputs = with pkgs; [ makeWrapper coreutils bash rspamd ];
|
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out/pipe/bin
|
|
|
|
cp $src/* $out/pipe/bin/
|
|
|
|
chmod a+x $out/pipe/bin/*
|
|
|
|
patchShebangs $out/pipe/bin
|
|
|
|
|
|
|
|
for file in $out/pipe/bin/*; do
|
|
|
|
wrapProgram $file \
|
|
|
|
--set PATH "${pkgs.coreutils}/bin:${pkgs.rspamd}/bin"
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
};
|
2020-03-06 18:27:47 +01:00
|
|
|
|
2023-05-20 00:12:02 +02:00
|
|
|
|
|
|
|
ldapConfig = pkgs.writeTextFile {
|
|
|
|
name = "dovecot-ldap.conf.ext.template";
|
|
|
|
text = ''
|
|
|
|
ldap_version = 3
|
|
|
|
uris = ${lib.concatStringsSep " " cfg.ldap.uris}
|
|
|
|
${lib.optionalString cfg.ldap.startTls ''
|
|
|
|
tls = yes
|
|
|
|
''}
|
|
|
|
tls_require_cert = hard
|
|
|
|
tls_ca_cert_file = ${cfg.ldap.tlsCAFile}
|
|
|
|
dn = ${cfg.ldap.bind.dn}
|
|
|
|
sasl_bind = no
|
|
|
|
auth_bind = yes
|
|
|
|
base = ${cfg.ldap.searchBase}
|
|
|
|
scope = ${mkLdapSearchScope cfg.ldap.searchScope}
|
2024-07-13 00:31:30 +02:00
|
|
|
${lib.optionalString (cfg.ldap.dovecot.userAttrs != null) ''
|
2023-06-28 23:07:11 +02:00
|
|
|
user_attrs = ${cfg.ldap.dovecot.userAttrs}
|
2023-05-20 00:12:02 +02:00
|
|
|
''}
|
|
|
|
user_filter = ${cfg.ldap.dovecot.userFilter}
|
|
|
|
${lib.optionalString (cfg.ldap.dovecot.passAttrs != "") ''
|
|
|
|
pass_attrs = ${cfg.ldap.dovecot.passAttrs}
|
|
|
|
''}
|
|
|
|
pass_filter = ${cfg.ldap.dovecot.passFilter}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-11-05 23:53:52 +01:00
|
|
|
# Move all mailboxes from the old location <mailDirectory>/<domain>/<user>
|
|
|
|
# to the new location <mailDirectory>/<domain>/<user>/mail.
|
|
|
|
moveMailDirsScript = pkgs.writeScript "move-mail-dirs" ''
|
|
|
|
#!${pkgs.stdenv.shell}
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
shopt -s dotglob extglob
|
|
|
|
|
|
|
|
for mailbox in $(find "${cfg.mailDirectory}" -mindepth 2 -maxdepth 2 -type d); do
|
|
|
|
if [ ! -d "$mailbox/mail" ]; then
|
|
|
|
mkdir "$mailbox/mail"
|
|
|
|
mv "$mailbox"/!(mail) "$mailbox/mail/"
|
|
|
|
chown -R ${cfg.vmailUserName}:${cfg.vmailGroupName} "$mailbox/mail"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2023-05-20 00:12:02 +02:00
|
|
|
setPwdInLdapConfFile = appendLdapBindPwd {
|
|
|
|
name = "ldap-conf-file";
|
|
|
|
file = ldapConfig;
|
2024-04-13 16:08:58 +02:00
|
|
|
prefix = ''dnpass = "'';
|
|
|
|
suffix = ''"'';
|
2023-05-20 00:12:02 +02:00
|
|
|
passwordFile = cfg.ldap.bind.passwordFile;
|
|
|
|
destination = ldapConfFile;
|
|
|
|
};
|
|
|
|
|
2020-03-06 18:27:47 +01:00
|
|
|
genPasswdScript = pkgs.writeScript "generate-password-file" ''
|
|
|
|
#!${pkgs.stdenv.shell}
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
if (! test -d "${passwdDir}"); then
|
|
|
|
mkdir "${passwdDir}"
|
|
|
|
chmod 755 "${passwdDir}"
|
|
|
|
fi
|
|
|
|
|
2023-06-28 10:22:07 +02:00
|
|
|
# Prevent world-readable password files, even temporarily.
|
|
|
|
umask 077
|
|
|
|
|
2020-03-06 18:27:47 +01:00
|
|
|
for f in ${builtins.toString (lib.mapAttrsToList (name: value: passwordFiles."${name}") cfg.loginAccounts)}; do
|
|
|
|
if [ ! -f "$f" ]; then
|
|
|
|
echo "Expected password hash file $f does not exist!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-05-20 00:12:02 +02:00
|
|
|
cat <<EOF > ${passwdFile}
|
2020-03-06 18:27:47 +01:00
|
|
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value:
|
2023-03-16 14:59:05 +01:00
|
|
|
"${name}:${"$(head -n 1 ${passwordFiles."${name}"})"}::::::"
|
|
|
|
) cfg.loginAccounts)}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat <<EOF > ${userdbFile}
|
|
|
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value:
|
|
|
|
"${name}:::::::"
|
2020-03-06 18:27:47 +01:00
|
|
|
+ (if lib.isString value.quota
|
|
|
|
then "userdb_quota_rule=*:storage=${value.quota}"
|
|
|
|
else "")
|
|
|
|
) cfg.loginAccounts)}
|
|
|
|
EOF
|
|
|
|
'';
|
2021-07-23 22:57:39 +02:00
|
|
|
|
|
|
|
junkMailboxes = builtins.attrNames (lib.filterAttrs (n: v: v ? "specialUse" && v.specialUse == "Junk") cfg.mailboxes);
|
|
|
|
junkMailboxNumber = builtins.length junkMailboxes;
|
|
|
|
# The assertion garantees there is exactly one Junk mailbox.
|
|
|
|
junkMailboxName = if junkMailboxNumber == 1 then builtins.elemAt junkMailboxes 0 else "";
|
|
|
|
|
2022-07-19 23:45:29 +02:00
|
|
|
mkLdapSearchScope = scope: (
|
|
|
|
if scope == "sub" then "subtree"
|
|
|
|
else if scope == "one" then "onelevel"
|
|
|
|
else scope
|
|
|
|
);
|
|
|
|
|
2017-08-12 12:28:46 +02:00
|
|
|
in
|
2016-07-25 17:40:58 +02:00
|
|
|
{
|
2017-09-03 11:13:34 +02:00
|
|
|
config = with cfg; lib.mkIf enable {
|
2021-07-23 22:57:39 +02:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = junkMailboxNumber == 1;
|
|
|
|
message = "nixos-mailserver requires exactly one dovecot mailbox with the 'special use' flag set to 'Junk' (${builtins.toString junkMailboxNumber} have been found)";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-06-27 10:03:43 +02:00
|
|
|
# for sieve-test. Shelling it in on demand usually doesnt' work, as it reads
|
|
|
|
# the global config and tries to open shared libraries configured in there,
|
|
|
|
# which are usually not compatible.
|
|
|
|
environment.systemPackages = [
|
|
|
|
pkgs.dovecot_pigeonhole
|
|
|
|
];
|
|
|
|
|
2017-09-03 11:13:34 +02:00
|
|
|
services.dovecot2 = {
|
|
|
|
enable = true;
|
2020-07-06 10:38:12 +02:00
|
|
|
enableImap = enableImap || enableImapSsl;
|
|
|
|
enablePop3 = enablePop3 || enablePop3Ssl;
|
2017-12-22 16:08:42 +01:00
|
|
|
enablePAM = false;
|
2017-12-22 16:58:35 +01:00
|
|
|
enableQuota = true;
|
2017-09-03 11:13:34 +02:00
|
|
|
mailGroup = vmailGroupName;
|
|
|
|
mailUser = vmailUserName;
|
2018-02-02 21:37:29 +01:00
|
|
|
mailLocation = dovecotMaildir;
|
2017-09-03 11:13:34 +02:00
|
|
|
sslServerCert = certificatePath;
|
|
|
|
sslServerKey = keyPath;
|
|
|
|
enableLmtp = true;
|
2020-07-13 14:00:00 +02:00
|
|
|
modules = [ pkgs.dovecot_pigeonhole ] ++ (lib.optional cfg.fullTextSearch.enable pkgs.dovecot_fts_xapian );
|
|
|
|
mailPlugins.globally.enable = lib.optionals cfg.fullTextSearch.enable [ "fts" "fts_xapian" ];
|
2020-07-06 10:38:12 +02:00
|
|
|
protocols = lib.optional cfg.enableManageSieve "sieve";
|
2017-09-13 13:06:44 +02:00
|
|
|
|
2024-01-14 20:55:20 +01:00
|
|
|
pluginSettings = {
|
|
|
|
sieve = "file:${cfg.sieveDirectory}/%u/scripts;active=${cfg.sieveDirectory}/%u/active.sieve";
|
|
|
|
sieve_default = "file:${cfg.sieveDirectory}/%u/default.sieve";
|
|
|
|
sieve_default_name = "default";
|
|
|
|
};
|
|
|
|
|
|
|
|
sieve = {
|
|
|
|
extensions = [
|
|
|
|
"fileinto"
|
|
|
|
];
|
|
|
|
|
|
|
|
scripts.after = builtins.toFile "spam.sieve" ''
|
2017-11-13 10:50:38 +01:00
|
|
|
require "fileinto";
|
|
|
|
|
|
|
|
if header :is "X-Spam" "Yes" {
|
2021-07-23 22:57:39 +02:00
|
|
|
fileinto "${junkMailboxName}";
|
2017-11-13 10:50:38 +01:00
|
|
|
stop;
|
|
|
|
}
|
|
|
|
'';
|
2024-01-14 20:55:20 +01:00
|
|
|
|
2024-03-04 08:14:21 +01:00
|
|
|
pipeBins = map lib.getExe [
|
|
|
|
(pkgs.writeShellScriptBin "sa-learn-ham.sh"
|
|
|
|
"exec ${pkgs.rspamd}/bin/rspamc -h /run/rspamd/worker-controller.sock learn_ham")
|
|
|
|
(pkgs.writeShellScriptBin "sa-learn-spam.sh"
|
|
|
|
"exec ${pkgs.rspamd}/bin/rspamc -h /run/rspamd/worker-controller.sock learn_spam")
|
2024-01-14 20:55:20 +01:00
|
|
|
];
|
2017-09-13 13:06:44 +02:00
|
|
|
};
|
|
|
|
|
2024-01-14 20:55:20 +01:00
|
|
|
imapsieve.mailbox = [
|
|
|
|
{
|
|
|
|
name = junkMailboxName;
|
|
|
|
causes = [ "COPY" "APPEND" ];
|
2024-03-04 08:14:21 +01:00
|
|
|
before = ./dovecot/imap_sieve/report-spam.sieve;
|
2024-01-14 20:55:20 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "*";
|
|
|
|
from = junkMailboxName;
|
|
|
|
causes = [ "COPY" ];
|
2024-03-04 08:14:21 +01:00
|
|
|
before = ./dovecot/imap_sieve/report-ham.sieve;
|
2024-01-14 20:55:20 +01:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2018-02-02 21:37:29 +01:00
|
|
|
mailboxes = cfg.mailboxes;
|
|
|
|
|
2017-09-03 11:13:34 +02:00
|
|
|
extraConfig = ''
|
|
|
|
#Extra Config
|
2017-11-13 22:46:59 +01:00
|
|
|
${lib.optionalString debug ''
|
|
|
|
mail_debug = yes
|
|
|
|
auth_debug = yes
|
|
|
|
verbose_ssl = yes
|
|
|
|
''}
|
|
|
|
|
2020-07-06 10:38:12 +02:00
|
|
|
${lib.optionalString (cfg.enableImap || cfg.enableImapSsl) ''
|
|
|
|
service imap-login {
|
|
|
|
inet_listener imap {
|
|
|
|
${if cfg.enableImap then ''
|
|
|
|
port = 143
|
|
|
|
'' else ''
|
2020-10-05 21:18:36 +02:00
|
|
|
# see https://dovecot.org/pipermail/dovecot/2010-March/047479.html
|
2020-07-06 10:38:12 +02:00
|
|
|
port = 0
|
|
|
|
''}
|
|
|
|
}
|
|
|
|
inet_listener imaps {
|
|
|
|
${if cfg.enableImapSsl then ''
|
|
|
|
port = 993
|
|
|
|
ssl = yes
|
|
|
|
'' else ''
|
2020-10-05 21:18:36 +02:00
|
|
|
# see https://dovecot.org/pipermail/dovecot/2010-March/047479.html
|
2020-07-06 10:38:12 +02:00
|
|
|
port = 0
|
|
|
|
''}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''}
|
|
|
|
${lib.optionalString (cfg.enablePop3 || cfg.enablePop3Ssl) ''
|
|
|
|
service pop3-login {
|
|
|
|
inet_listener pop3 {
|
|
|
|
${if cfg.enablePop3 then ''
|
|
|
|
port = 110
|
|
|
|
'' else ''
|
2020-10-05 21:18:36 +02:00
|
|
|
# see https://dovecot.org/pipermail/dovecot/2010-March/047479.html
|
2020-07-06 10:38:12 +02:00
|
|
|
port = 0
|
|
|
|
''}
|
|
|
|
}
|
|
|
|
inet_listener pop3s {
|
|
|
|
${if cfg.enablePop3Ssl then ''
|
|
|
|
port = 995
|
|
|
|
ssl = yes
|
|
|
|
'' else ''
|
2020-10-05 21:18:36 +02:00
|
|
|
# see https://dovecot.org/pipermail/dovecot/2010-March/047479.html
|
2020-07-06 10:38:12 +02:00
|
|
|
port = 0
|
|
|
|
''}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''}
|
|
|
|
|
2018-03-13 11:43:30 +01:00
|
|
|
protocol imap {
|
|
|
|
mail_max_userip_connections = ${toString cfg.maxConnectionsPerUser}
|
2018-05-15 04:17:18 +02:00
|
|
|
mail_plugins = $mail_plugins imap_sieve
|
2018-03-13 11:43:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protocol pop3 {
|
|
|
|
mail_max_userip_connections = ${toString cfg.maxConnectionsPerUser}
|
|
|
|
}
|
|
|
|
|
2017-09-03 11:13:34 +02:00
|
|
|
mail_access_groups = ${vmailGroupName}
|
|
|
|
ssl = required
|
2020-05-24 19:21:31 +02:00
|
|
|
ssl_min_protocol = TLSv1.2
|
2020-05-24 19:23:53 +02:00
|
|
|
ssl_prefer_server_ciphers = yes
|
2017-08-12 12:28:46 +02:00
|
|
|
|
2017-09-03 11:13:34 +02:00
|
|
|
service lmtp {
|
2018-05-04 16:52:58 +02:00
|
|
|
unix_listener dovecot-lmtp {
|
2018-05-04 14:56:33 +02:00
|
|
|
group = ${postfixCfg.group}
|
2017-11-13 10:50:38 +01:00
|
|
|
mode = 0600
|
2018-05-04 14:56:33 +02:00
|
|
|
user = ${postfixCfg.user}
|
2017-11-13 10:50:38 +01:00
|
|
|
}
|
2017-09-03 11:13:34 +02:00
|
|
|
}
|
2017-08-12 12:28:46 +02:00
|
|
|
|
2021-03-22 20:05:34 +01:00
|
|
|
recipient_delimiter = ${cfg.recipientDelimiter}
|
2020-05-19 23:58:09 +02:00
|
|
|
lmtp_save_to_detail_mailbox = ${cfg.lmtpSaveToDetailMailbox}
|
2019-07-26 19:00:32 +02:00
|
|
|
|
2017-09-13 13:06:44 +02:00
|
|
|
protocol lmtp {
|
2017-11-13 10:50:38 +01:00
|
|
|
mail_plugins = $mail_plugins sieve
|
2017-09-13 13:06:44 +02:00
|
|
|
}
|
|
|
|
|
2017-12-22 16:08:42 +01:00
|
|
|
passdb {
|
|
|
|
driver = passwd-file
|
2023-05-20 00:12:02 +02:00
|
|
|
args = ${passwdFile}
|
2017-12-22 16:08:42 +01:00
|
|
|
}
|
|
|
|
|
2017-12-22 16:58:35 +01:00
|
|
|
userdb {
|
|
|
|
driver = passwd-file
|
2023-03-16 14:59:05 +01:00
|
|
|
args = ${userdbFile}
|
2024-11-05 23:53:52 +01:00
|
|
|
default_fields = home=${cfg.mailDirectory}/%d/%n uid=${toString cfg.vmailUID} gid=${toString cfg.vmailUID}
|
2017-12-22 16:58:35 +01:00
|
|
|
}
|
|
|
|
|
2022-07-19 23:45:29 +02:00
|
|
|
${lib.optionalString cfg.ldap.enable ''
|
|
|
|
passdb {
|
|
|
|
driver = ldap
|
2023-05-20 00:12:02 +02:00
|
|
|
args = ${ldapConfFile}
|
2022-07-19 23:45:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
userdb {
|
|
|
|
driver = ldap
|
2023-05-20 00:12:02 +02:00
|
|
|
args = ${ldapConfFile}
|
2024-11-05 23:53:52 +01:00
|
|
|
default_fields = home=${cfg.mailDirectory}/%d/%n uid=${toString cfg.vmailUID} gid=${toString cfg.vmailUID}
|
2022-07-19 23:45:29 +02:00
|
|
|
}
|
|
|
|
''}
|
|
|
|
|
2024-10-31 16:58:53 +01:00
|
|
|
${lib.optionalString cfg.oauth.enable ''
|
|
|
|
passdb {
|
|
|
|
driver = oauth2
|
|
|
|
mechanisms = xoauth2 oauthbearer
|
|
|
|
args = ${cfg.oauth.backendConfigFile}
|
|
|
|
}
|
|
|
|
''}
|
|
|
|
|
2017-09-03 11:13:34 +02:00
|
|
|
service auth {
|
2018-05-04 16:52:58 +02:00
|
|
|
unix_listener auth {
|
2017-11-13 10:50:38 +01:00
|
|
|
mode = 0660
|
2018-05-04 14:56:33 +02:00
|
|
|
user = ${postfixCfg.user}
|
|
|
|
group = ${postfixCfg.group}
|
2017-11-13 10:50:38 +01:00
|
|
|
}
|
2017-09-03 11:13:34 +02:00
|
|
|
}
|
2017-08-12 12:28:46 +02:00
|
|
|
|
2024-10-31 16:58:53 +01:00
|
|
|
auth_mechanisms = plain login${lib.optionalString cfg.oauth.enable " oauthbearer xoauth2"}
|
2017-08-12 12:28:46 +02:00
|
|
|
|
2017-09-03 11:13:34 +02:00
|
|
|
namespace inbox {
|
2018-02-02 21:37:29 +01:00
|
|
|
separator = ${cfg.hierarchySeparator}
|
2017-11-13 10:50:38 +01:00
|
|
|
inbox = yes
|
2017-09-03 11:13:34 +02:00
|
|
|
}
|
2017-11-18 04:37:59 +01:00
|
|
|
|
2021-11-26 05:53:00 +01:00
|
|
|
${lib.optionalString cfg.fullTextSearch.enable ''
|
2020-07-13 14:00:00 +02:00
|
|
|
plugin {
|
|
|
|
plugin = fts fts_xapian
|
|
|
|
fts = xapian
|
|
|
|
fts_xapian = partial=${toString cfg.fullTextSearch.minSize} full=${toString cfg.fullTextSearch.maxSize} attachments=${bool2int cfg.fullTextSearch.indexAttachments} verbose=${bool2int cfg.debug}
|
|
|
|
|
|
|
|
fts_autoindex = ${if cfg.fullTextSearch.autoIndex then "yes" else "no"}
|
|
|
|
|
|
|
|
${lib.strings.concatImapStringsSep "\n" (n: x: "fts_autoindex_exclude${if n==1 then "" else toString n} = ${x}") cfg.fullTextSearch.autoIndexExclude}
|
|
|
|
|
|
|
|
fts_enforced = ${cfg.fullTextSearch.enforced}
|
|
|
|
}
|
|
|
|
|
|
|
|
${lib.optionalString (cfg.fullTextSearch.memoryLimit != null) ''
|
|
|
|
service indexer-worker {
|
|
|
|
vsz_limit = ${toString (cfg.fullTextSearch.memoryLimit*1024*1024)}
|
|
|
|
}
|
|
|
|
''}
|
|
|
|
''}
|
|
|
|
|
2017-11-20 22:51:57 +01:00
|
|
|
lda_mailbox_autosubscribe = yes
|
|
|
|
lda_mailbox_autocreate = yes
|
2017-09-03 11:13:34 +02:00
|
|
|
'';
|
|
|
|
};
|
2018-05-15 04:17:18 +02:00
|
|
|
|
2020-03-06 18:27:47 +01:00
|
|
|
systemd.services.dovecot2 = {
|
|
|
|
preStart = ''
|
2024-11-05 23:53:52 +01:00
|
|
|
${moveMailDirsScript}
|
2020-06-19 16:02:21 +02:00
|
|
|
${genPasswdScript}
|
2023-05-20 00:12:02 +02:00
|
|
|
'' + (lib.optionalString cfg.ldap.enable setPwdInLdapConfFile);
|
2020-03-06 18:27:47 +01:00
|
|
|
};
|
2019-10-18 21:21:01 +02:00
|
|
|
|
2023-05-20 00:12:02 +02:00
|
|
|
systemd.services.postfix.restartTriggers = [ genPasswdScript ] ++ (lib.optional cfg.ldap.enable [setPwdInLdapConfFile]);
|
2020-07-13 14:00:00 +02:00
|
|
|
|
|
|
|
systemd.services.dovecot-fts-xapian-optimize = lib.mkIf (cfg.fullTextSearch.enable && cfg.fullTextSearch.maintenance.enable) {
|
|
|
|
description = "Optimize dovecot indices for fts_xapian";
|
|
|
|
requisite = [ "dovecot2.service" ];
|
|
|
|
after = [ "dovecot2.service" ];
|
|
|
|
startAt = cfg.fullTextSearch.maintenance.onCalendar;
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
ExecStart = "${pkgs.dovecot}/bin/doveadm fts optimize -A";
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateNetwork = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectSystem = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
systemd.timers.dovecot-fts-xapian-optimize = lib.mkIf (cfg.fullTextSearch.enable && cfg.fullTextSearch.maintenance.enable && cfg.fullTextSearch.maintenance.randomizedDelaySec != 0) {
|
|
|
|
timerConfig = {
|
|
|
|
RandomizedDelaySec = cfg.fullTextSearch.maintenance.randomizedDelaySec;
|
|
|
|
};
|
|
|
|
};
|
2017-09-03 11:13:34 +02:00
|
|
|
};
|
2016-07-25 17:40:58 +02:00
|
|
|
}
|