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