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