1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.weechat;
7in
8
9{
10 options.services.weechat = {
11 enable = mkEnableOption (lib.mdDoc "weechat");
12 root = mkOption {
13 description = lib.mdDoc "Weechat state directory.";
14 type = types.str;
15 default = "/var/lib/weechat";
16 };
17 sessionName = mkOption {
18 description = lib.mdDoc "Name of the `screen` session for weechat.";
19 default = "weechat-screen";
20 type = types.str;
21 };
22 binary = mkOption {
23 type = types.path;
24 description = lib.mdDoc "Binary to execute.";
25 default = "${pkgs.weechat}/bin/weechat";
26 defaultText = literalExpression ''"''${pkgs.weechat}/bin/weechat"'';
27 example = literalExpression ''"''${pkgs.weechat}/bin/weechat-headless"'';
28 };
29 };
30
31 config = mkIf cfg.enable {
32 users = {
33 groups.weechat = {};
34 users.weechat = {
35 createHome = true;
36 group = "weechat";
37 home = cfg.root;
38 isSystemUser = true;
39 };
40 };
41
42 systemd.services.weechat = {
43 environment.WEECHAT_HOME = cfg.root;
44 serviceConfig = {
45 User = "weechat";
46 Group = "weechat";
47 RemainAfterExit = "yes";
48 };
49 script = "exec ${config.security.wrapperDir}/screen -Dm -S ${cfg.sessionName} ${cfg.binary}";
50 wantedBy = [ "multi-user.target" ];
51 wants = [ "network.target" ];
52 };
53
54 security.wrappers.screen =
55 { setuid = true;
56 owner = "root";
57 group = "root";
58 source = "${pkgs.screen}/bin/screen";
59 };
60 };
61
62 meta.doc = ./weechat.md;
63}