at 24.11-pre 3.2 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 inherit (lib) literalExpression mkIf mkOption singleton types mkPackageOption; 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 = mkPackageOption pkgs "exim" { 61 extraDescription = '' 62 This can be used to enable features such as LDAP or PAM support. 63 ''; 64 }; 65 66 queueRunnerInterval = mkOption { 67 type = types.str; 68 default = "5m"; 69 description = '' 70 How often to spawn a new queue runner. 71 ''; 72 }; 73 }; 74 75 }; 76 77 78 ###### implementation 79 80 config = mkIf cfg.enable { 81 82 environment = { 83 etc."exim.conf".text = '' 84 exim_user = ${cfg.user} 85 exim_group = ${cfg.group} 86 exim_path = /run/wrappers/bin/exim 87 spool_directory = ${cfg.spoolDir} 88 ${cfg.config} 89 ''; 90 systemPackages = [ cfg.package ]; 91 }; 92 93 users.users.${cfg.user} = { 94 description = "Exim mail transfer agent user"; 95 uid = config.ids.uids.exim; 96 group = cfg.group; 97 }; 98 99 users.groups.${cfg.group} = { 100 gid = config.ids.gids.exim; 101 }; 102 103 security.wrappers.exim = 104 { setuid = true; 105 owner = "root"; 106 group = "root"; 107 source = "${cfg.package}/bin/exim"; 108 }; 109 110 systemd.services.exim = { 111 description = "Exim Mail Daemon"; 112 wantedBy = [ "multi-user.target" ]; 113 restartTriggers = [ config.environment.etc."exim.conf".source ]; 114 serviceConfig = { 115 ExecStart = "!${cfg.package}/bin/exim -bdf -q${cfg.queueRunnerInterval}"; 116 ExecReload = "!${coreutils}/bin/kill -HUP $MAINPID"; 117 User = cfg.user; 118 }; 119 preStart = '' 120 if ! test -d ${cfg.spoolDir}; then 121 ${coreutils}/bin/mkdir -p ${cfg.spoolDir} 122 ${coreutils}/bin/chown ${cfg.user}:${cfg.group} ${cfg.spoolDir} 123 fi 124 ''; 125 }; 126 127 }; 128 129}