From 0ca7c3425f37ebb483567993a0f02159b8826dd0 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Fri, 5 Mar 2021 22:34:59 +0100 Subject: 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. --- modules/user/profpatsch/programs/weechat.nix | 37 +++++++++++++++++++--------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'modules') 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} ''; }; -- cgit 1.4.1