From 04be7262a62a413007fe6bf6e917a4e4d0f0df54 Mon Sep 17 00:00:00 2001 From: Andrey Arapov Date: Mon, 19 Jan 2015 10:45:20 +0100 Subject: [PATCH] nixos/dovecot: added configFile option and default Restart on-failure, PR #5845 Absolute path is required when one has such postfix configuration where he/she needs to specify the actual (real) path to active dovecot config. Without this commit applied, the dovecot is running in such way: /nix/store/hashAAA-dovecot-ver/sbin/dovecot -F -c /nix/store/hashBBB-dovecot2.conf and postfix can't be aware of the value of "hashBBB" via services.postfix.extraConfig = '' ... ''; (it can only be aware of "hashAAA" with ${pkgs.dovecot} parameter) Also enable Restart on-failure. Edit: set RestartSec to 1s --- nixos/modules/services/mail/dovecot.nix | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/nixos/modules/services/mail/dovecot.nix b/nixos/modules/services/mail/dovecot.nix index 1fb7102e7f3e..50ff1b38db12 100644 --- a/nixos/modules/services/mail/dovecot.nix +++ b/nixos/modules/services/mail/dovecot.nix @@ -45,8 +45,6 @@ let pop3_uidl_format = %08Xv%08Xu '' + cfg.extraConfig; - confFile = pkgs.writeText "dovecot.conf" dovecotConf; - in { @@ -88,6 +86,12 @@ in description = "Additional entries to put verbatim into Dovecot's config file."; }; + configFile = mkOption { + default = null; + description = "Config file used for the whole dovecot configuration."; + apply = v: if v != null then v else pkgs.writeText "dovecot.conf" dovecotConf; + }; + mailLocation = mkOption { default = "maildir:/var/spool/mail/%u"; /* Same as inbox, as postfix */ example = "maildir:~/mail:INBOX=/var/spool/mail/%u"; @@ -144,10 +148,11 @@ in gid = config.ids.gids.dovecot2; }; - jobs.dovecot2 = + systemd.services.dovecot2 = { description = "Dovecot IMAP/POP3 server"; - startOn = "started networking"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; preStart = '' @@ -155,7 +160,13 @@ in ${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} /var/run/dovecot2 ''; - exec = "${pkgs.dovecot}/sbin/dovecot -F -c ${confFile}"; + serviceConfig = { + ExecStart = "${pkgs.dovecot}/sbin/dovecot -F -c ${cfg.configFile}"; + Restart = "on-failure"; + RestartSec = "1s"; + StartLimitInterval = "1min"; + }; + }; environment.systemPackages = [ pkgs.dovecot ];