From a3f8e4ff17fd5937bdfdd32513b4b5f86717fc3a Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 26 Jun 2022 15:48:32 +0200 Subject: machines/legosi: add weechat-qwerky Changes the weechat setup so that I can have multiple instances, each gets their own unix user & separate weechat instance. --- modules/user/profpatsch/programs/weechat.nix | 83 +++++++++++++++++----------- 1 file changed, 51 insertions(+), 32 deletions(-) (limited to 'modules/user/profpatsch/programs') diff --git a/modules/user/profpatsch/programs/weechat.nix b/modules/user/profpatsch/programs/weechat.nix index c291e574..2373598f 100644 --- a/modules/user/profpatsch/programs/weechat.nix +++ b/modules/user/profpatsch/programs/weechat.nix @@ -8,7 +8,6 @@ { config, lib, pkgs, ... }: let - cfg = config.vuizvui.user.profpatsch.programs.weechat; # tmux session name weechat runs in sessionName = "weechat"; @@ -69,12 +68,8 @@ let "attach-session" "-t" sessionName ]; -in - -{ - options.vuizvui.user.profpatsch.programs.weechat = { - enable = lib.mkEnableOption "weechat"; + weechatServiceOptions = { authorizedKeys = lib.mkOption { description = "ssh keys that should be able to connect to the weechat tmux session"; type = lib.types.listOf lib.types.str; @@ -88,6 +83,7 @@ in extraGroups = lib.mkOption { description = "extra groups to add to the weechat user"; type = lib.types.listOf lib.types.str; + default = []; }; weechatDataDir = lib.mkOption { @@ -95,7 +91,6 @@ in type = lib.types.path; }; - wrapExecStart = lib.mkOption { description = "bernstein-chaining command wrapped around weechat"; type = lib.types.listOf lib.types.str; @@ -103,39 +98,62 @@ in }; }; - config = lib.mkIf cfg.enable { + # map over the configs defined in the list option below + allCfgsString = f: + lib.concatStrings + (map f config.vuizvui.user.profpatsch.programs.weechat); + allCfgsMerge = f: + lib.foldl' lib.mergeAttrs {} + (map f config.vuizvui.user.profpatsch.programs.weechat); + +in + +{ + options.vuizvui.user.profpatsch.programs.weechat = lib.mkOption { + description = "the weechat services to start"; + type = lib.types.listOf (lib.types.submodule { + options = weechatServiceOptions; + }); + default = []; + }; + + config = { users = { groups.weechat = {}; - users.${cfg.userName} = { - isSystemUser = true; - createHome = true; - shell = bins.dash; - group = "weechat"; - home = cfg.weechatDataDir; - openssh.authorizedKeys.keys = cfg.authorizedKeys; - extraGroups = cfg.extraGroups; - }; + users = allCfgsMerge (cfg: { + ${cfg.userName} = { + isSystemUser = true; + createHome = true; + shell = bins.dash; + group = "weechat"; + home = cfg.weechatDataDir; + openssh.authorizedKeys.keys = cfg.authorizedKeys; + extraGroups = cfg.extraGroups; + }; + }); }; # make sure the only use-case for this account # is attaching the tmux session. - services.openssh.extraConfig = '' + services.openssh.extraConfig = allCfgsString (cfg: '' Match User ${cfg.userName} ForceCommand ${attachWeechatTmuxSession} - ''; - - systemd.services."weechat-${cfg.userName}" = { - environment.WEECHAT_HOME = cfg.weechatDataDir; - serviceConfig = { - ExecStart = startWeechatTmuxSession cfg.wrapExecStart; - Restart = "always"; - RestartSec = "3s"; - User = cfg.userName; - Group = "weechat"; + ''); + + systemd.services = allCfgsMerge (cfg: { + "weechat-${cfg.userName}" = { + environment.WEECHAT_HOME = cfg.weechatDataDir; + serviceConfig = { + ExecStart = startWeechatTmuxSession cfg.wrapExecStart; + Restart = "always"; + RestartSec = "3s"; + User = cfg.userName; + Group = "weechat"; + }; + wantedBy = [ "multi-user.target" ]; + wants = [ "network.target" ]; }; - wantedBy = [ "multi-user.target" ]; - wants = [ "network.target" ]; - }; + }); # This enables “lingering” for the CI user. # Inspired by the discussion (and linked code) @@ -146,9 +164,10 @@ in # remove all existing lingering users rm -r /var/lib/systemd/linger mkdir /var/lib/systemd/linger + '' + allCfgsString (cfg: '' # enable for the subset of declared users touch /var/lib/systemd/linger/${cfg.userName} - ''; + # ''); }; }; -- cgit 1.4.1