1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.ircdHybrid; 8 9 ircdService = pkgs.stdenv.mkDerivation rec { 10 name = "ircd-hybrid-service"; 11 scripts = [ "=>/bin" ./control.in ]; 12 substFiles = [ "=>/conf" ./ircd.conf ]; 13 inherit (pkgs) ircdHybrid coreutils su iproute2 gnugrep procps; 14 15 ipv6Enabled = boolToString config.networking.enableIPv6; 16 17 inherit (cfg) serverName sid description adminEmail 18 extraPort; 19 20 cryptoSettings = 21 (optionalString (cfg.rsaKey != null) "rsa_private_key_file = \"${cfg.rsaKey}\";\n") + 22 (optionalString (cfg.certificate != null) "ssl_certificate_file = \"${cfg.certificate}\";\n"); 23 24 extraListen = map (ip: "host = \""+ip+"\";\nport = 6665 .. 6669, "+extraPort+"; ") cfg.extraIPs; 25 26 builder = ./builder.sh; 27 }; 28 29in 30 31{ 32 33 ###### interface 34 35 options = { 36 37 services.ircdHybrid = { 38 39 enable = mkEnableOption (lib.mdDoc "IRCD"); 40 41 serverName = mkOption { 42 default = "hades.arpa"; 43 type = types.str; 44 description = lib.mdDoc '' 45 IRCD server name. 46 ''; 47 }; 48 49 sid = mkOption { 50 default = "0NL"; 51 type = types.str; 52 description = lib.mdDoc '' 53 IRCD server unique ID in a net of servers. 54 ''; 55 }; 56 57 description = mkOption { 58 default = "Hybrid-7 IRC server."; 59 type = types.str; 60 description = lib.mdDoc '' 61 IRCD server description. 62 ''; 63 }; 64 65 rsaKey = mkOption { 66 default = null; 67 example = literalExpression "/root/certificates/irc.key"; 68 type = types.nullOr types.path; 69 description = lib.mdDoc '' 70 IRCD server RSA key. 71 ''; 72 }; 73 74 certificate = mkOption { 75 default = null; 76 example = literalExpression "/root/certificates/irc.pem"; 77 type = types.nullOr types.path; 78 description = lib.mdDoc '' 79 IRCD server SSL certificate. There are some limitations - read manual. 80 ''; 81 }; 82 83 adminEmail = mkOption { 84 default = "<bit-bucket@example.com>"; 85 type = types.str; 86 example = "<name@domain.tld>"; 87 description = lib.mdDoc '' 88 IRCD server administrator e-mail. 89 ''; 90 }; 91 92 extraIPs = mkOption { 93 default = []; 94 example = ["127.0.0.1"]; 95 type = types.listOf types.str; 96 description = lib.mdDoc '' 97 Extra IP's to bind. 98 ''; 99 }; 100 101 extraPort = mkOption { 102 default = "7117"; 103 type = types.str; 104 description = lib.mdDoc '' 105 Extra port to avoid filtering. 106 ''; 107 }; 108 109 }; 110 111 }; 112 113 114 ###### implementation 115 116 config = mkIf config.services.ircdHybrid.enable { 117 118 users.users.ircd = 119 { description = "IRCD owner"; 120 group = "ircd"; 121 uid = config.ids.uids.ircd; 122 }; 123 124 users.groups.ircd.gid = config.ids.gids.ircd; 125 126 systemd.services.ircd-hybrid = { 127 description = "IRCD Hybrid server"; 128 after = [ "started networking" ]; 129 wantedBy = [ "multi-user.target" ]; 130 script = "${ircdService}/bin/control start"; 131 }; 132 }; 133}