at 17.09-beta 2.5 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 inherit (lib) mkEnableOption mkIf mkOption singleton types; 5 inherit (pkgs) coreutils charybdis; 6 cfg = config.services.charybdis; 7 8 configFile = pkgs.writeText "charybdis.conf" '' 9 ${cfg.config} 10 ''; 11in 12 13{ 14 15 ###### interface 16 17 options = { 18 19 services.charybdis = { 20 21 enable = mkEnableOption "Charybdis IRC daemon"; 22 23 config = mkOption { 24 type = types.string; 25 description = '' 26 Charybdis IRC daemon configuration file. 27 ''; 28 }; 29 30 statedir = mkOption { 31 type = types.string; 32 default = "/var/lib/charybdis"; 33 description = '' 34 Location of the state directory of charybdis. 35 ''; 36 }; 37 38 user = mkOption { 39 type = types.string; 40 default = "ircd"; 41 description = '' 42 Charybdis IRC daemon user. 43 ''; 44 }; 45 46 group = mkOption { 47 type = types.string; 48 default = "ircd"; 49 description = '' 50 Charybdis IRC daemon group. 51 ''; 52 }; 53 54 motd = mkOption { 55 type = types.nullOr types.lines; 56 default = null; 57 description = '' 58 Charybdis MOTD text. 59 60 Charybdis will read its MOTD from /etc/charybdis/ircd.motd . 61 If set, the value of this option will be written to this path. 62 ''; 63 }; 64 65 }; 66 67 }; 68 69 70 ###### implementation 71 72 config = mkIf cfg.enable (lib.mkMerge [ 73 { 74 users.extraUsers = singleton { 75 name = cfg.user; 76 description = "Charybdis IRC daemon user"; 77 uid = config.ids.uids.ircd; 78 group = cfg.group; 79 }; 80 81 users.extraGroups = singleton { 82 name = cfg.group; 83 gid = config.ids.gids.ircd; 84 }; 85 86 systemd.services.charybdis = { 87 description = "Charybdis IRC daemon"; 88 wantedBy = [ "multi-user.target" ]; 89 environment = { 90 BANDB_DBPATH = "${cfg.statedir}/ban.db"; 91 }; 92 serviceConfig = { 93 ExecStart = "${charybdis}/bin/charybdis-ircd -foreground -logfile /dev/stdout -configfile ${configFile}"; 94 Group = cfg.group; 95 User = cfg.user; 96 PermissionsStartOnly = true; # preStart needs to run with root permissions 97 }; 98 preStart = '' 99 ${coreutils}/bin/mkdir -p ${cfg.statedir} 100 ${coreutils}/bin/chown ${cfg.user}:${cfg.group} ${cfg.statedir} 101 ''; 102 }; 103 104 } 105 106 (mkIf (cfg.motd != null) { 107 environment.etc."charybdis/ircd.motd".text = cfg.motd; 108 }) 109 ]); 110}