From 93330c54531e494eed603a389b3c297a2834676b Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Thu, 11 Mar 2021 20:53:38 +0100 Subject: [PATCH] Move indexDir option to the mailserver scope This option has been initially in the mailserver.fullTextSearch scope. However, this option modifies the location of all index files of dovecot and not only those used by the full text search feature. It is then more relevant to have this option in the mailserver top level scope. Moreover, the default option has been changed to null in order to keep existing index files where they are: changing the index location means recreating all index files. The fts documentation however recommend to change this default location when enabling the fts feature. --- default.nix | 28 ++++++++++++++++++++-------- docs/fts.rst | 14 +++++++++++--- mail-server/dovecot.nix | 5 ++--- mail-server/systemd.nix | 4 +--- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/default.nix b/default.nix index 21c38e3..8905c5a 100644 --- a/default.nix +++ b/default.nix @@ -187,17 +187,29 @@ in default = {}; }; + indexDir = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + Folder to store search indices. If null, indices are stored + along with email, which could not necessarily be desirable, + especially when the fullTextSearch option is enable since + indices it creates are voluminous and do not need to be backed + up. + + Be careful when changing this option value since all indices + would be recreated at the new location (and clients would need + to resynchronize). + + Note the some variables can be used in the file path. See + https://doc.dovecot.org/configuration_manual/mail_location/#variables + for details. + ''; + example = "/var/lib/docecot/indices/%d/%n"; + }; fullTextSearch = { enable = mkEnableOption "Full text search indexing with xapian. This has significant performance and disk space cost."; - indexDir = mkOption { - type = types.nullOr types.str; - default = "/var/lib/dovecot/fts_xapian"; - description = '' - Folder to store search indices. If null, indices are stored along with email, which - is not necessarily desirable as indices are voluminous and do not need to be backed up. - ''; - }; autoIndex = mkOption { type = types.bool; default = true; diff --git a/docs/fts.rst b/docs/fts.rst index cf7b561..aed2cba 100644 --- a/docs/fts.rst +++ b/docs/fts.rst @@ -38,9 +38,17 @@ issues a search query, so latency will be high. Resource requirements ~~~~~~~~~~~~~~~~~~~~~~~~ -Indices can take more disk space than the emails themselves. By default, they -are kept in a different location (``/var/lib/dovecot/fts_xapian``) than emails -so that you can backup emails without indices. +Indices created by the full text search feature can take more disk +space than the emails themselves. By default, they are kept in the +emails location. When enabling the full text search feature, it is +recommended to move indices in a different location, such as +(``/var/lib/docecot/indices/%d/%n``) by using the option +``mailserver.indexDir``. + +.. warning:: + + When the value of the ``indexDir`` option is changed, all dovecot + indices needs to be recreated: clients would need to resynchronize. Indexation itself is rather resouces intensive, in CPU, and for emails with large headers, in memory as well. Initial indexation of existing emails can take diff --git a/mail-server/dovecot.nix b/mail-server/dovecot.nix index 293aaa6..3781bbd 100644 --- a/mail-server/dovecot.nix +++ b/mail-server/dovecot.nix @@ -31,9 +31,8 @@ let # maildir in format "/${domain}/${user}" dovecotMaildir = "maildir:${cfg.mailDirectory}/%d/%n${maildirLayoutAppendix}" - + (lib.optionalString - (cfg.fullTextSearch.enable && (cfg.fullTextSearch.indexDir != null)) - ":INDEX=${cfg.fullTextSearch.indexDir}/%d/%n" + + (lib.optionalString (cfg.indexDir != null) + ":INDEX=${cfg.indexDir}/%d/%n" ); postfixCfg = config.services.postfix; diff --git a/mail-server/systemd.nix b/mail-server/systemd.nix index 60a0b76..36e48d6 100644 --- a/mail-server/systemd.nix +++ b/mail-server/systemd.nix @@ -59,9 +59,7 @@ in preStart = let directories = lib.strings.escapeShellArgs ( [ mailDirectory ] - ++ lib.optional - (cfg.fullTextSearch.enable && (cfg.fullTextSearch.indexDir != null)) - cfg.fullTextSearch.indexDir + ++ lib.optional (cfg.indexDir != null) cfg.indexDir ); in '' # Create mail directory and set permissions. See