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 iproute gnugrep procps;
14
15 ipv6Enabled = if config.networking.enableIPv6 then "true" else "false";
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 = mkOption {
40 default = false;
41 description = "
42 Enable IRCD.
43 ";
44 };
45
46 serverName = mkOption {
47 default = "hades.arpa";
48 description = "
49 IRCD server name.
50 ";
51 };
52
53 sid = mkOption {
54 default = "0NL";
55 description = "
56 IRCD server unique ID in a net of servers.
57 ";
58 };
59
60 description = mkOption {
61 default = "Hybrid-7 IRC server.";
62 description = "
63 IRCD server description.
64 ";
65 };
66
67 rsaKey = mkOption {
68 default = null;
69 example = literalExample "/root/certificates/irc.key";
70 description = "
71 IRCD server RSA key.
72 ";
73 };
74
75 certificate = mkOption {
76 default = null;
77 example = literalExample "/root/certificates/irc.pem";
78 description = "
79 IRCD server SSL certificate. There are some limitations - read manual.
80 ";
81 };
82
83 adminEmail = mkOption {
84 default = "<bit-bucket@example.com>";
85 example = "<name@domain.tld>";
86 description = "
87 IRCD server administrator e-mail.
88 ";
89 };
90
91 extraIPs = mkOption {
92 default = [];
93 example = ["127.0.0.1"];
94 description = "
95 Extra IP's to bind.
96 ";
97 };
98
99 extraPort = mkOption {
100 default = "7117";
101 description = "
102 Extra port to avoid filtering.
103 ";
104 };
105
106 };
107
108 };
109
110
111 ###### implementation
112
113 config = mkIf config.services.ircdHybrid.enable {
114
115 users.extraUsers = singleton
116 { name = "ircd";
117 description = "IRCD owner";
118 group = "ircd";
119 uid = config.ids.uids.ircd;
120 };
121
122 users.extraGroups.ircd.gid = config.ids.gids.ircd;
123
124 systemd.services."ircd-hybrid" = {
125 description = "IRCD Hybrid server";
126 after = [ "started networking" ];
127 wantedBy = [ "multi-user.target" ];
128 script = "${ircdService}/bin/control start";
129 };
130 };
131}