stockholm/krebs/3modules/reaktor2.nix

88 lines
2.6 KiB
Nix
Raw Normal View History

2023-06-10 10:50:53 +00:00
{ config, pkgs, lib, ... }:
with import ../../lib/pure.nix { inherit lib; }; {
2019-01-21 11:11:03 +00:00
options.krebs.reaktor2 = mkOption {
default = {};
type = types.attrsOf (types.submodule (self: let
name = self.config._module.args.name;
in {
options = {
nick = mkOption {
default = name;
# TODO types.irc.nickname
type = types.str;
};
hostname = mkOption {
default = "irc.r";
type = types.hostname;
};
port = mkOption {
default = "6667";
# TODO type = types.service-name
};
plugins = mkOption {
default = [];
type = types.listOf types.attrs;
};
stateDir = mkOption {
default = "/var/lib/${self.config.username}";
2021-11-08 03:27:12 +00:00
defaultText = "/var/lib/username";
2019-01-21 11:11:03 +00:00
readOnly = true;
type = types.absolute-pathname;
};
systemd-service-name = mkOption {
default = "reaktor2${optionalString (name != "default") "-${name}"}";
2021-11-08 03:27:12 +00:00
defaultText = "reaktor2-name or just reaktor2 if name is \"default\"";
2019-01-21 11:11:03 +00:00
type = types.filename;
};
2019-01-29 20:39:16 +00:00
sendDelaySec = mkOption {
default = 0.7;
type = types.nullOr types.float;
};
username = mkOption {
2019-01-27 12:41:51 +00:00
default = self.config.systemd-service-name;
2021-11-08 03:27:12 +00:00
defaultText = "systemd-service-name";
type = types.username;
2019-01-27 12:41:51 +00:00
};
2019-01-27 17:33:22 +00:00
useTLS = mkOption {
default = self.config.port == "6697";
type = types.bool;
};
2020-04-18 16:49:10 +00:00
API.listen = mkOption {
default = null;
type = types.nullOr types.str;
};
2019-01-21 11:11:03 +00:00
};
}));
};
config = {
systemd.services = flip mapAttrs' config.krebs.reaktor2 (_: cfg:
nameValuePair cfg.systemd-service-name {
after = [ "network.target" ];
2019-10-22 22:49:48 +00:00
environment = {
LC_ALL = "en_US.UTF-8";
};
2019-01-21 11:11:03 +00:00
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = cfg.username;
2019-01-21 11:11:03 +00:00
Group = "reaktor2";
DynamicUser = true;
StateDirectory = cfg.username;
2019-01-21 11:11:03 +00:00
ExecStart = let
2024-08-13 18:04:02 +00:00
configFile = pkgs.writers.writeJSON configFileName configValue;
2019-01-21 11:11:03 +00:00
configFileName = "${cfg.systemd-service-name}.config.json";
2020-04-18 16:49:10 +00:00
configValue = stripAttr (
recursiveUpdate {
logTime = false;
} (removeAttrs cfg ["_module"])
);
2019-01-21 11:11:03 +00:00
in "${pkgs.reaktor2}/bin/reaktor ${configFile}";
Restart = "always";
RestartSec = "30";
};
}
);
};
}