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