about summary refs log tree commit diff
path: root/modules
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2021-03-05 22:34:59 +0100
committerProfpatsch <mail@profpatsch.de>2021-03-05 22:56:29 +0100
commit0ca7c3425f37ebb483567993a0f02159b8826dd0 (patch)
tree41f99ace227bb1a0218cf594c0c31b995b89a42c /modules
parent143ed53f90b67f72e830fea5fa15ceb5d33a1ca6 (diff)
services/profpatsch/weechat: start factoring out some options
The goal is to be able to have multiple weechat services on one
machine, so a bunch of people can run their weechat clients under
different service users.
Diffstat (limited to 'modules')
-rw-r--r--modules/user/profpatsch/programs/weechat.nix37
1 files changed, 25 insertions, 12 deletions
diff --git a/modules/user/profpatsch/programs/weechat.nix b/modules/user/profpatsch/programs/weechat.nix
index 215f1e98..a4ade925 100644
--- a/modules/user/profpatsch/programs/weechat.nix
+++ b/modules/user/profpatsch/programs/weechat.nix
@@ -9,9 +9,8 @@
 
 let
   cfg = config.vuizvui.user.profpatsch.programs.weechat;
-  weechatDataDir = "/var/lib/weechat";
+  # tmux session name weechat runs in
   sessionName = "weechat";
-  userName = "weechat";
 
   inherit (pkgs.vuizvui.profpatsch)
     writeExecline
@@ -72,6 +71,22 @@ in
       type = lib.types.listOf lib.types.str;
     };
 
+    userName = lib.mkOption {
+      description = "user name of the user account that should be created for weechat";
+      type = lib.types.str;
+    };
+
+    extraGroups = lib.mkOption {
+      description = "extra groups to add to the weechat user";
+      type = lib.types.listOf lib.types.str;
+    };
+
+    weechatDataDir = lib.mkOption {
+      description = "the data directory used for keeping configuration, logs and other state";
+      type = lib.types.path;
+    };
+
+
     wrapExecStart = lib.mkOption {
       description = "bernstein-chaining command wrapped around weechat";
       type = lib.types.listOf lib.types.str;
@@ -82,33 +97,31 @@ in
   config = lib.mkIf cfg.enable {
     users = {
       groups.weechat = {};
-      users.${userName} = {
+      users.${cfg.userName} = {
         isSystemUser = true;
         createHome = true;
         shell = bins.dash;
         group = "weechat";
-        home = weechatDataDir;
+        home = cfg.weechatDataDir;
         openssh.authorizedKeys.keys = cfg.authorizedKeys;
-        # give this user access to the bitlbee group and socket
-        # TODO: should not be here I guess.
-        extraGroups = [ "bitlbee" ];
+        extraGroups = cfg.extraGroups;
       };
     };
 
     # make sure the only use-case for this account
     # is attaching the tmux session.
     services.openssh.extraConfig = ''
-      Match User ${userName}
+      Match User ${cfg.userName}
           ForceCommand ${attachWeechatTmuxSession}
     '';
 
-    systemd.services.weechat = {
-      environment.WEECHAT_HOME = weechatDataDir;
+    systemd.services."weechat-${cfg.userName}" = {
+      environment.WEECHAT_HOME = cfg.weechatDataDir;
       serviceConfig = {
         ExecStart = startWeechatTmuxSession cfg.wrapExecStart;
         Restart = "always";
         RestartSec = "3s";
-        User = userName;
+        User = cfg.userName;
         Group = "weechat";
       };
       wantedBy = [ "multi-user.target" ];
@@ -125,7 +138,7 @@ in
         rm -r /var/lib/systemd/linger
         mkdir /var/lib/systemd/linger
         # enable for the subset of declared users
-        touch /var/lib/systemd/linger/${userName}
+        touch /var/lib/systemd/linger/${cfg.userName}
       '';
     };