1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.bitlbee;
8 bitlbeeUid = config.ids.uids.bitlbee;
9
10 bitlbeePkg = pkgs.bitlbee.override {
11 enableLibPurple = cfg.libpurple_plugins != [];
12 enablePam = cfg.authBackend == "pam";
13 };
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 AuthBackend = ${cfg.authBackend}
25 Plugindir = ${pkgs.bitlbee-plugins cfg.plugins}/lib/bitlbee
26 ${lib.optionalString (cfg.hostName != "") "HostName = ${cfg.hostName}"}
27 ${lib.optionalString (cfg.protocols != "") "Protocols = ${cfg.protocols}"}
28 ${cfg.extraSettings}
29
30 [defaults]
31 ${cfg.extraDefaults}
32 '';
33
34 purple_plugin_path =
35 lib.concatMapStringsSep ":"
36 (plugin: "${plugin}/lib/pidgin/:${plugin}/lib/purple-2/")
37 cfg.libpurple_plugins
38 ;
39
40in
41
42{
43
44 ###### interface
45
46 options = {
47
48 services.bitlbee = {
49
50 enable = mkOption {
51 type = types.bool;
52 default = false;
53 description = ''
54 Whether to run the BitlBee IRC to other chat network gateway.
55 Running it allows you to access the MSN, Jabber, Yahoo! and ICQ chat
56 networks via an IRC client.
57 '';
58 };
59
60 interface = mkOption {
61 type = types.str;
62 default = "127.0.0.1";
63 description = ''
64 The interface the BitlBee deamon will be listening to. If `127.0.0.1',
65 only clients on the local host can connect to it; if `0.0.0.0', clients
66 can access it from any network interface.
67 '';
68 };
69
70 portNumber = mkOption {
71 default = 6667;
72 type = types.int;
73 description = ''
74 Number of the port BitlBee will be listening to.
75 '';
76 };
77
78 authBackend = mkOption {
79 default = "storage";
80 type = types.enum [ "storage" "pam" ];
81 description = ''
82 How users are authenticated
83 storage -- save passwords internally
84 pam -- Linux PAM authentication
85 '';
86 };
87
88 authMode = mkOption {
89 default = "Open";
90 type = types.enum [ "Open" "Closed" "Registered" ];
91 description = ''
92 The following authentication modes are available:
93 Open -- Accept connections from anyone, use NickServ for user authentication.
94 Closed -- Require authorization (using the PASS command during login) before allowing the user to connect at all.
95 Registered -- Only allow registered users to use this server; this disables the register- and the account command until the user identifies himself.
96 '';
97 };
98
99 hostName = mkOption {
100 default = "";
101 type = types.str;
102 description = ''
103 Normally, BitlBee gets a hostname using getsockname(). If you have a nicer
104 alias for your BitlBee daemon, you can set it here and BitlBee will identify
105 itself with that name instead.
106 '';
107 };
108
109 plugins = mkOption {
110 type = types.listOf types.package;
111 default = [];
112 example = literalExample "[ pkgs.bitlbee-facebook ]";
113 description = ''
114 The list of bitlbee plugins to install.
115 '';
116 };
117
118 libpurple_plugins = mkOption {
119 type = types.listOf types.package;
120 default = [];
121 example = literalExample "[ pkgs.purple-matrix ]";
122 description = ''
123 The list of libpurple plugins to install.
124 '';
125 };
126
127 configDir = mkOption {
128 default = "/var/lib/bitlbee";
129 type = types.path;
130 description = ''
131 Specify an alternative directory to store all the per-user configuration
132 files.
133 '';
134 };
135
136 protocols = mkOption {
137 default = "";
138 type = types.str;
139 description = ''
140 This option allows to remove the support of protocol, even if compiled
141 in. If nothing is given, there are no restrictions.
142 '';
143 };
144
145 extraSettings = mkOption {
146 default = "";
147 type = types.lines;
148 description = ''
149 Will be inserted in the Settings section of the config file.
150 '';
151 };
152
153 extraDefaults = mkOption {
154 default = "";
155 type = types.lines;
156 description = ''
157 Will be inserted in the Default section of the config file.
158 '';
159 };
160
161 };
162
163 };
164
165 ###### implementation
166
167 config = mkMerge [
168 (mkIf config.services.bitlbee.enable {
169 users.users.bitlbee = {
170 uid = bitlbeeUid;
171 description = "BitlBee user";
172 home = "/var/lib/bitlbee";
173 createHome = true;
174 };
175
176 users.groups.bitlbee = {
177 gid = config.ids.gids.bitlbee;
178 };
179
180 systemd.services.bitlbee = {
181 environment.PURPLE_PLUGIN_PATH = purple_plugin_path;
182 description = "BitlBee IRC to other chat networks gateway";
183 after = [ "network.target" ];
184 wantedBy = [ "multi-user.target" ];
185 serviceConfig.User = "bitlbee";
186 serviceConfig.ExecStart = "${bitlbeePkg}/sbin/bitlbee -F -n -c ${bitlbeeConfig}";
187 };
188
189 environment.systemPackages = [ bitlbeePkg ];
190
191 })
192 (mkIf (config.services.bitlbee.authBackend == "pam") {
193 security.pam.services.bitlbee = {};
194 })
195 ];
196
197}