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