1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.bitlbee;
8 bitlbeeUid = config.ids.uids.bitlbee;
9
10 authModeCheck = v:
11 v == "Open" ||
12 v == "Closed" ||
13 v == "Registered";
14
15 bitlbeeConfig = pkgs.writeText "bitlbee.conf"
16 ''
17 [settings]
18 RunMode = Daemon
19 User = bitlbee
20 ConfigDir = ${cfg.configDir}
21 DaemonInterface = ${cfg.interface}
22 DaemonPort = ${toString cfg.portNumber}
23 AuthMode = ${cfg.authMode}
24 Plugindir = ${pkgs.bitlbee-plugins cfg.plugins}/lib/bitlbee
25 ${lib.optionalString (cfg.hostName != "") "HostName = ${cfg.hostName}"}
26 ${lib.optionalString (cfg.protocols != "") "Protocols = ${cfg.protocols}"}
27 ${cfg.extraSettings}
28
29 [defaults]
30 ${cfg.extraDefaults}
31 '';
32
33in
34
35{
36
37 ###### interface
38
39 options = {
40
41 services.bitlbee = {
42
43 enable = mkOption {
44 default = false;
45 description = ''
46 Whether to run the BitlBee IRC to other chat network gateway.
47 Running it allows you to access the MSN, Jabber, Yahoo! and ICQ chat
48 networks via an IRC client.
49 '';
50 };
51
52 interface = mkOption {
53 default = "127.0.0.1";
54 description = ''
55 The interface the BitlBee deamon will be listening to. If `127.0.0.1',
56 only clients on the local host can connect to it; if `0.0.0.0', clients
57 can access it from any network interface.
58 '';
59 };
60
61 portNumber = mkOption {
62 default = 6667;
63 description = ''
64 Number of the port BitlBee will be listening to.
65 '';
66 };
67
68 authMode = mkOption {
69 default = "Open";
70 type = types.addCheck types.str authModeCheck;
71 description = ''
72 The following authentication modes are available:
73 Open -- Accept connections from anyone, use NickServ for user authentication.
74 Closed -- Require authorization (using the PASS command during login) before allowing the user to connect at all.
75 Registered -- Only allow registered users to use this server; this disables the register- and the account command until the user identifies himself.
76 '';
77 };
78
79 hostName = mkOption {
80 default = "";
81 type = types.str;
82 description = ''
83 Normally, BitlBee gets a hostname using getsockname(). If you have a nicer
84 alias for your BitlBee daemon, you can set it here and BitlBee will identify
85 itself with that name instead.
86 '';
87 };
88
89 plugins = mkOption {
90 type = types.listOf types.package;
91 default = [];
92 example = literalExample "[ pkgs.bitlbee-facebook ]";
93 description = ''
94 The list of bitlbee plugins to install.
95 '';
96 };
97
98 configDir = mkOption {
99 default = "/var/lib/bitlbee";
100 type = types.path;
101 description = ''
102 Specify an alternative directory to store all the per-user configuration
103 files.
104 '';
105 };
106
107 protocols = mkOption {
108 default = "";
109 type = types.str;
110 description = ''
111 This option allows to remove the support of protocol, even if compiled
112 in. If nothing is given, there are no restrictions.
113 '';
114 };
115
116 extraSettings = mkOption {
117 default = "";
118 description = ''
119 Will be inserted in the Settings section of the config file.
120 '';
121 };
122
123 extraDefaults = mkOption {
124 default = "";
125 description = ''
126 Will be inserted in the Default section of the config file.
127 '';
128 };
129
130 };
131
132 };
133
134 ###### implementation
135
136 config = mkIf config.services.bitlbee.enable {
137
138 users.extraUsers = singleton
139 { name = "bitlbee";
140 uid = bitlbeeUid;
141 description = "BitlBee user";
142 home = "/var/lib/bitlbee";
143 createHome = true;
144 };
145
146 users.extraGroups = singleton
147 { name = "bitlbee";
148 gid = config.ids.gids.bitlbee;
149 };
150
151 systemd.services.bitlbee =
152 { description = "BitlBee IRC to other chat networks gateway";
153 after = [ "network.target" ];
154 wantedBy = [ "multi-user.target" ];
155 serviceConfig.User = "bitlbee";
156 serviceConfig.ExecStart = "${pkgs.bitlbee}/sbin/bitlbee -F -n -c ${bitlbeeConfig}";
157 };
158
159 environment.systemPackages = [ pkgs.bitlbee ];
160
161 };
162
163}