2018-01-06 13:25:13 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2024-12-14 17:14:54 +01:00
|
|
|
|
2018-01-06 13:25:13 +00:00
|
|
|
let
|
|
|
|
cfg = config.services.weechat;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.weechat = {
|
2024-08-30 00:46:52 +02:00
|
|
|
enable = lib.mkEnableOption "weechat";
|
2024-12-14 17:14:54 +01:00
|
|
|
|
2024-12-14 03:04:26 +01:00
|
|
|
package = lib.mkPackageOption pkgs "weechat" { };
|
|
|
|
|
2024-08-30 00:46:52 +02:00
|
|
|
root = lib.mkOption {
|
2018-01-06 13:25:13 +00:00
|
|
|
description = "Weechat state directory.";
|
2024-12-14 02:39:30 +01:00
|
|
|
type = lib.types.path;
|
2018-01-06 13:25:13 +00:00
|
|
|
default = "/var/lib/weechat";
|
|
|
|
};
|
2024-12-14 17:14:54 +01:00
|
|
|
|
2024-08-30 00:46:52 +02:00
|
|
|
sessionName = lib.mkOption {
|
2023-01-21 11:06:46 +01:00
|
|
|
description = "Name of the `screen` session for weechat.";
|
2018-09-05 17:01:57 +02:00
|
|
|
default = "weechat-screen";
|
2024-08-30 00:46:52 +02:00
|
|
|
type = lib.types.str;
|
2018-09-05 17:01:57 +02:00
|
|
|
};
|
2024-12-14 17:14:54 +01:00
|
|
|
|
2024-08-30 00:46:52 +02:00
|
|
|
binary = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
2021-10-03 18:06:03 +02:00
|
|
|
description = "Binary to execute.";
|
2024-12-14 05:12:36 +01:00
|
|
|
default =
|
|
|
|
if (!cfg.headless) then "${cfg.package}/bin/weechat" else "${cfg.package}/bin/weechat-headless";
|
2024-12-14 03:04:26 +01:00
|
|
|
defaultText = lib.literalExpression ''"''${cfg.package}/bin/weechat"'';
|
|
|
|
example = lib.literalExpression ''"''${cfg.package}/bin/weechat-headless"'';
|
2018-09-05 17:01:57 +02:00
|
|
|
};
|
2024-12-14 05:12:36 +01:00
|
|
|
|
|
|
|
headless = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Allows specifying if weechat should run in TUI or headless mode.
|
|
|
|
'';
|
|
|
|
};
|
2018-01-06 13:25:13 +00:00
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:52 +02:00
|
|
|
config = lib.mkIf cfg.enable {
|
2018-01-06 13:25:13 +00:00
|
|
|
users = {
|
2018-09-05 17:01:57 +02:00
|
|
|
groups.weechat = { };
|
2018-01-06 13:25:13 +00:00
|
|
|
users.weechat = {
|
|
|
|
group = "weechat";
|
2018-09-05 17:01:57 +02:00
|
|
|
isSystemUser = true;
|
2018-01-06 13:25:13 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-12-14 01:12:36 +01:00
|
|
|
systemd.tmpfiles.settings."weechat" = {
|
|
|
|
"${cfg.root}" = lib.mkIf (cfg.root != "/var/lib/weechat") {
|
|
|
|
d = {
|
|
|
|
user = "weechat";
|
|
|
|
group = "weechat";
|
|
|
|
mode = "750";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-01-06 13:25:13 +00:00
|
|
|
systemd.services.weechat = {
|
|
|
|
serviceConfig = {
|
2024-12-14 05:12:36 +01:00
|
|
|
Type = "simple";
|
2018-01-06 13:25:13 +00:00
|
|
|
User = "weechat";
|
|
|
|
Group = "weechat";
|
2024-12-14 05:12:36 +01:00
|
|
|
ExecStart = lib.mkIf (cfg.headless) "${cfg.binary} --dir ${cfg.root} --stdout";
|
2024-12-14 01:12:36 +01:00
|
|
|
StateDirectory = lib.mkIf (cfg.root == "/var/lib/weechat") "weechat";
|
|
|
|
StateDirectoryMode = 750;
|
2018-09-05 17:01:57 +02:00
|
|
|
RemainAfterExit = "yes";
|
2018-01-06 13:25:13 +00:00
|
|
|
};
|
2024-12-14 05:12:36 +01:00
|
|
|
script =
|
|
|
|
lib.mkIf (!cfg.headless)
|
|
|
|
"exec ${config.security.wrapperDir}/screen -Dm -S ${cfg.sessionName} ${cfg.binary} --dir ${cfg.root}";
|
2018-01-06 13:25:13 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
wants = [ "network.target" ];
|
|
|
|
};
|
2018-10-10 01:20:42 +02:00
|
|
|
|
2024-12-14 05:12:36 +01:00
|
|
|
security.wrappers.screen = lib.mkIf (!cfg.headless) {
|
2021-09-12 18:53:48 +02:00
|
|
|
setuid = true;
|
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
|
|
|
source = "${pkgs.screen}/bin/screen";
|
|
|
|
};
|
2018-01-06 13:25:13 +00:00
|
|
|
};
|
2018-09-05 17:01:57 +02:00
|
|
|
|
2023-01-25 00:33:40 +01:00
|
|
|
meta.doc = ./weechat.md;
|
2018-01-06 13:25:13 +00:00
|
|
|
}
|