at 21.11-pre 3.1 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 inherit (lib) 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 = "Whether to enable the Exim mail transfer agent."; 21 }; 22 23 config = mkOption { 24 type = types.lines; 25 default = ""; 26 description = '' 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 = '' 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 = '' 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 = '' 56 Location of the spool directory of exim. 57 ''; 58 }; 59 60 package = mkOption { 61 type = types.package; 62 default = pkgs.exim; 63 defaultText = "pkgs.exim"; 64 description = '' 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 = '' 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.source = "${cfg.package}/bin/exim"; 108 109 systemd.services.exim = { 110 description = "Exim Mail Daemon"; 111 wantedBy = [ "multi-user.target" ]; 112 restartTriggers = [ config.environment.etc."exim.conf".source ]; 113 serviceConfig = { 114 ExecStart = "${cfg.package}/bin/exim -bdf -q${cfg.queueRunnerInterval}"; 115 ExecReload = "${coreutils}/bin/kill -HUP $MAINPID"; 116 }; 117 preStart = '' 118 if ! test -d ${cfg.spoolDir}; then 119 ${coreutils}/bin/mkdir -p ${cfg.spoolDir} 120 ${coreutils}/bin/chown ${cfg.user}:${cfg.group} ${cfg.spoolDir} 121 fi 122 ''; 123 }; 124 125 }; 126 127}