at 23.11-pre 3.4 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 inherit (lib) literalExpression mkIf mkOption singleton types; 5 inherit (pkgs) coreutils; 6 cfg = config.services.exim; 7in 8 9{ 10 11 ###### interface 12 13 options = { 14 15 services.exim = { 16 17 enable = mkOption { 18 type = types.bool; 19 default = false; 20 description = lib.mdDoc "Whether to enable the Exim mail transfer agent."; 21 }; 22 23 config = mkOption { 24 type = types.lines; 25 default = ""; 26 description = lib.mdDoc '' 27 Verbatim Exim configuration. This should not contain exim_user, 28 exim_group, exim_path, or spool_directory. 29 ''; 30 }; 31 32 user = mkOption { 33 type = types.str; 34 default = "exim"; 35 description = lib.mdDoc '' 36 User to use when no root privileges are required. 37 In particular, this applies when receiving messages and when doing 38 remote deliveries. (Local deliveries run as various non-root users, 39 typically as the owner of a local mailbox.) Specifying this value 40 as root is not supported. 41 ''; 42 }; 43 44 group = mkOption { 45 type = types.str; 46 default = "exim"; 47 description = lib.mdDoc '' 48 Group to use when no root privileges are required. 49 ''; 50 }; 51 52 spoolDir = mkOption { 53 type = types.path; 54 default = "/var/spool/exim"; 55 description = lib.mdDoc '' 56 Location of the spool directory of exim. 57 ''; 58 }; 59 60 package = mkOption { 61 type = types.package; 62 default = pkgs.exim; 63 defaultText = literalExpression "pkgs.exim"; 64 description = lib.mdDoc '' 65 The Exim derivation to use. 66 This can be used to enable features such as LDAP or PAM support. 67 ''; 68 }; 69 70 queueRunnerInterval = mkOption { 71 type = types.str; 72 default = "5m"; 73 description = lib.mdDoc '' 74 How often to spawn a new queue runner. 75 ''; 76 }; 77 }; 78 79 }; 80 81 82 ###### implementation 83 84 config = mkIf cfg.enable { 85 86 environment = { 87 etc."exim.conf".text = '' 88 exim_user = ${cfg.user} 89 exim_group = ${cfg.group} 90 exim_path = /run/wrappers/bin/exim 91 spool_directory = ${cfg.spoolDir} 92 ${cfg.config} 93 ''; 94 systemPackages = [ cfg.package ]; 95 }; 96 97 users.users.${cfg.user} = { 98 description = "Exim mail transfer agent user"; 99 uid = config.ids.uids.exim; 100 group = cfg.group; 101 }; 102 103 users.groups.${cfg.group} = { 104 gid = config.ids.gids.exim; 105 }; 106 107 security.wrappers.exim = 108 { setuid = true; 109 owner = "root"; 110 group = "root"; 111 source = "${cfg.package}/bin/exim"; 112 }; 113 114 systemd.services.exim = { 115 description = "Exim Mail Daemon"; 116 wantedBy = [ "multi-user.target" ]; 117 restartTriggers = [ config.environment.etc."exim.conf".source ]; 118 serviceConfig = { 119 ExecStart = "+${cfg.package}/bin/exim -bdf -q${cfg.queueRunnerInterval}"; 120 ExecReload = "+${coreutils}/bin/kill -HUP $MAINPID"; 121 User = cfg.user; 122 }; 123 preStart = '' 124 if ! test -d ${cfg.spoolDir}; then 125 ${coreutils}/bin/mkdir -p ${cfg.spoolDir} 126 ${coreutils}/bin/chown ${cfg.user}:${cfg.group} ${cfg.spoolDir} 127 fi 128 ''; 129 }; 130 131 }; 132 133}