From 18d419141df4958e8438b7883d6c061609f8170b Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Wed, 5 Sep 2018 17:01:57 +0200 Subject: [PATCH] nixos/weechat: cleanup module, add module documentation This adds several improvements the previously introduced `services.weechat` module: * Dropped `services.weechat.init` as the initialization script can now be done on package-level since 2af41719bc using the `configure` function. * Added `sessionName` option to explicitly configure a name for the `screen` session (by default: weechat-screen). * Added `binary` option to configure the binary name (e.g. `weechat-headless`). * Added docs regarding `screen` session and `weechat.service`. --- nixos/modules/services/misc/weechat.nix | 47 ++++++++----------- nixos/modules/services/misc/weechat.xml | 61 +++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 29 deletions(-) create mode 100644 nixos/modules/services/misc/weechat.xml diff --git a/nixos/modules/services/misc/weechat.nix b/nixos/modules/services/misc/weechat.nix index 535a7f9ef91f..1fcfb440485d 100644 --- a/nixos/modules/services/misc/weechat.nix +++ b/nixos/modules/services/misc/weechat.nix @@ -9,28 +9,33 @@ in { options.services.weechat = { enable = mkEnableOption "weechat"; - init = mkOption { - description = "Weechat commands applied at start, one command per line."; - example = '' - /set relay.network.password correct-horse-battery-staple - /relay add weechat 9001 - ''; - type = types.str; - default = ""; - }; root = mkOption { description = "Weechat state directory."; type = types.str; default = "/var/lib/weechat"; }; + sessionName = mkOption { + description = "Name of the `screen' session for weechat."; + default = "weechat-screen"; + type = types.str; + }; + binary = mkOption { + description = "Binary to execute (by default \${weechat}/bin/weechat)."; + example = literalExample '' + ''${pkgs.weechat}/bin/weechat-headless + ''; + default = "${pkgs.weechat}/bin/weechat"; + }; }; config = mkIf cfg.enable { users = { + groups.weechat = {}; users.weechat = { createHome = true; group = "weechat"; home = cfg.root; + isSystemUser = true; }; }; @@ -39,29 +44,13 @@ in serviceConfig = { User = "weechat"; Group = "weechat"; + RemainAfterExit = "yes"; }; - script = "exec ${pkgs.screen}/bin/screen -D -m ${pkgs.weechat}/bin/weechat"; + script = "exec ${pkgs.screen}/bin/screen -Dm -S ${cfg.sessionName} ${cfg.binary}"; wantedBy = [ "multi-user.target" ]; wants = [ "network.target" ]; }; - - systemd.paths.weechat-fifo = { - pathConfig = { - PathExists = "${cfg.root}/weechat_fifo"; - Unit = "weechat-apply-init.service"; - }; - wantedBy = [ "multi-user.target" ]; - }; - - systemd.services.weechat-apply-init = let - initFile = pkgs.writeText "weechat-init" cfg.init; - in { - script = "sed 's/^/*/' ${initFile} > ${cfg.root}/weechat_fifo"; - serviceConfig = { - Type = "oneshot"; - User = "weechat"; - Group = "weechat"; - }; - }; }; + + meta.doc = ./weechat.xml; } diff --git a/nixos/modules/services/misc/weechat.xml b/nixos/modules/services/misc/weechat.xml new file mode 100644 index 000000000000..de86dede2eb5 --- /dev/null +++ b/nixos/modules/services/misc/weechat.xml @@ -0,0 +1,61 @@ + + +WeeChat +WeeChat is a fast and extensible IRC client. + +
Basic Usage + +By default, the module creates a +systemd unit +which runs the chat client in a detached +screen session. + + + + +This can be done by enabling the weechat service: + + +{ ... }: + +{ + services.weechat.enable = true; +} + + + +The service is managed by a dedicated user +named weechat in the state directory +/var/lib/weechat. + +
+
Re-attaching to WeeChat + +WeeChat runs in a screen session owned by a dedicated user. To explicitly +allow your another user to attach to this session, the screenrc needs to be tweaked +by adding multiuser support: + + +{ + programs.screen.screenrc = '' + multiuser on + acladd normal_user + ''; +} + + +Now, the session can be re-attached like this: + + +screen -r weechat-screen + + + +The session name can be changed using services.weechat.sessionName. + +
+