nixpkgs/nixos/modules/services/misc/weechat.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.3 KiB
Nix
Raw Normal View History

2018-01-06 13:25:13 +00:00
{
config,
lib,
pkgs,
...
}:
2018-01-06 13:25:13 +00:00
let
cfg = config.services.weechat;
in
{
options.services.weechat = {
enable = lib.mkEnableOption "weechat";
package = lib.mkPackageOption pkgs "weechat" { };
root = lib.mkOption {
2018-01-06 13:25:13 +00:00
description = "Weechat state directory.";
type = lib.types.path;
2018-01-06 13:25:13 +00:00
default = "/var/lib/weechat";
};
sessionName = lib.mkOption {
description = "Name of the `screen` session for weechat.";
default = "weechat-screen";
type = lib.types.str;
};
binary = lib.mkOption {
type = lib.types.path;
description = "Binary to execute.";
default =
if (!cfg.headless) then "${cfg.package}/bin/weechat" else "${cfg.package}/bin/weechat-headless";
defaultText = lib.literalExpression ''"''${cfg.package}/bin/weechat"'';
example = lib.literalExpression ''"''${cfg.package}/bin/weechat-headless"'';
};
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
};
config = lib.mkIf cfg.enable {
2018-01-06 13:25:13 +00:00
users = {
groups.weechat = { };
2018-01-06 13:25:13 +00:00
users.weechat = {
group = "weechat";
isSystemUser = true;
2018-01-06 13:25:13 +00: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 = {
Type = "simple";
2018-01-06 13:25:13 +00:00
User = "weechat";
Group = "weechat";
ExecStart = lib.mkIf (cfg.headless) "${cfg.binary} --dir ${cfg.root} --stdout";
StateDirectory = lib.mkIf (cfg.root == "/var/lib/weechat") "weechat";
StateDirectoryMode = 750;
RemainAfterExit = "yes";
2018-01-06 13:25:13 +00: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" ];
};
security.wrappers.screen = lib.mkIf (!cfg.headless) {
setuid = true;
owner = "root";
group = "root";
source = "${pkgs.screen}/bin/screen";
};
2018-01-06 13:25:13 +00:00
};
meta.doc = ./weechat.md;
2018-01-06 13:25:13 +00:00
}