about summary refs log tree commit diff
path: root/modules/user/profpatsch/services/bitlbee.nix
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2020-06-19 02:59:03 +0200
committerProfpatsch <mail@profpatsch.de>2020-06-19 02:59:26 +0200
commit1ce91198e8692f98425205c3e1d2d4e8ceb41539 (patch)
treeb01152e21c4a35f61547d6829260ef8d3637a47a /modules/user/profpatsch/services/bitlbee.nix
parentb8a5df7611623e8cec098db41c5ff3b221e0d4f3 (diff)
modules/user/profpatsch/services: add bitlbee
Also add the service to legosi so I can use it from the weechat user.
Diffstat (limited to 'modules/user/profpatsch/services/bitlbee.nix')
-rw-r--r--modules/user/profpatsch/services/bitlbee.nix89
1 files changed, 89 insertions, 0 deletions
diff --git a/modules/user/profpatsch/services/bitlbee.nix b/modules/user/profpatsch/services/bitlbee.nix
new file mode 100644
index 00000000..76812ede
--- /dev/null
+++ b/modules/user/profpatsch/services/bitlbee.nix
@@ -0,0 +1,89 @@
+# starts bitlbee and creates a socket in /run/bitlbee.socket
+# which accepts one client.
+{ config, lib, pkgs, ... }:
+
+let
+  cfg = config.vuizvui.services.profpatsch.bitlbee;
+  bitlbeeUsername = "bitlebee";
+  stateDir = "bitlbee";
+
+  # based on the example config https://github.com/bitlbee/bitlbee/blob/master/bitlbee.conf
+  bitlbeeConfig = pkgs.writeText "bitlbee.conf" (lib.generators.toINI {} {
+    settings = {
+      RunMode = "Inetd";
+      User = bitlbeeUsername;
+      AuthMode = "Open";
+      AuthBackend = "storage";
+      ConfigDir = "/var/lib" + stateDir;
+      Protocols = "jabber";
+      # is this okay?
+      CAFile = "/etc/ssl/certs/ca-certificates.crt";
+    };
+  });
+
+in
+
+{
+
+  ###### interface
+
+  options = {
+
+    vuizvui.services.profpatsch.bitlbee = {
+
+      enable = lib.mkEnableOption "bitlbee";
+
+      socketFile = lib.mkOption {
+        description = ''
+          Where to put the unix socket.
+          It will be accessible by users in the `bitlbee` group.
+        '';
+        type = lib.types.str;
+        default = "/run/bitlbee.socket";
+      };
+    };
+  };
+
+  ###### implementation
+
+  config = (lib.mkIf cfg.enable {
+    users.users.bitlbee = {
+      description = "BitlBee user";
+      home = "/var/lib/bitlbee";
+      createHome = true;
+    };
+
+    users.groups.bitlbee.name = "bitlbee";
+
+    systemd.services."bitlbee@" = {
+      description = "BitlBee";
+      after = [ "network.target" ];
+      serviceConfig = {
+        User = "bitlbee";
+        ExecStart =
+        "${pkgs.bitlbee}/bin/bitlbee -v -c ${bitlbeeConfig}";
+        StateDirectory = "bitlbee";
+        # To get the inetd input
+        StandardInput = "socket";
+      };
+    };
+
+    # bitlbee
+    systemd.sockets.bitlbee = {
+      description = "bitlbee socket";
+      wantedBy = [ "sockets.target" ];
+      socketConfig = {
+        # Run in inetd mode
+        Accept = true;
+        # Only one client at a time
+        MaxConnections = 1;
+        ListenStream = cfg.socketFile;
+        SocketUser = "bitlbee";
+        SocketGroup = "bitlbee";
+        SocketMode = "0660";
+      };
+    };
+
+  });
+
+}