at 16.09-beta 2.6 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 inherit (lib) mkIf mkOption singleton types; 5 inherit (pkgs) coreutils exim; 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.string; 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.string; 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.string; 46 default = "exim"; 47 description = '' 48 Group to use when no root privileges are required. 49 ''; 50 }; 51 52 spoolDir = mkOption { 53 type = types.string; 54 default = "/var/spool/exim"; 55 description = '' 56 Location of the spool directory of exim. 57 ''; 58 }; 59 60 }; 61 62 }; 63 64 65 ###### implementation 66 67 config = mkIf cfg.enable { 68 69 environment = { 70 etc."exim.conf".text = '' 71 exim_user = ${cfg.user} 72 exim_group = ${cfg.group} 73 exim_path = /var/setuid-wrappers/exim 74 spool_directory = ${cfg.spoolDir} 75 ${cfg.config} 76 ''; 77 systemPackages = [ exim ]; 78 }; 79 80 users.extraUsers = singleton { 81 name = cfg.user; 82 description = "Exim mail transfer agent user"; 83 uid = config.ids.uids.exim; 84 group = cfg.group; 85 }; 86 87 users.extraGroups = singleton { 88 name = cfg.group; 89 gid = config.ids.gids.exim; 90 }; 91 92 security.setuidPrograms = [ "exim" ]; 93 94 systemd.services.exim = { 95 description = "Exim Mail Daemon"; 96 wantedBy = [ "multi-user.target" ]; 97 serviceConfig = { 98 ExecStart = "${exim}/bin/exim -bdf -q30m"; 99 ExecReload = "${coreutils}/bin/kill -HUP $MAINPID"; 100 }; 101 preStart = '' 102 if ! test -d ${cfg.spoolDir}; then 103 ${coreutils}/bin/mkdir -p ${cfg.spoolDir} 104 ${coreutils}/bin/chown ${cfg.user}:${cfg.group} ${cfg.spoolDir} 105 fi 106 ''; 107 }; 108 109 }; 110 111}