newsbot-js: add multiple instances

This commit is contained in:
lassulus 2017-09-09 00:09:04 +02:00
parent e4969bf3e7
commit 22f74186ed

View File

@ -6,51 +6,59 @@ let
cfg = config.krebs.newsbot-js; cfg = config.krebs.newsbot-js;
enable = cfg != {};
out = { out = {
options.krebs.newsbot-js = api; options.krebs.newsbot-js = api;
config = mkIf cfg.enable imp; config = mkIf enable imp;
}; };
api = { api = mkOption {
enable = mkEnableOption "Enable krebs newsbot"; type = types.attrsOf (types.submodule ({ config, ... }: {
package = mkOption { options = {
type = types.package; enable = mkEnableOption "Enable krebs newsbot" // { default = true; };
default = pkgs.newsbot-js;
description = "newsbot package to use"; channel = mkOption {
}; type = types.str;
ircServer = mkOption { default = "#${config._module.args.name}";
type = types.str; description = "post the news in this channel";
default = "echelon.retiolum"; };
description = "to which server the bot should connect"; feeds = mkOption {
}; type = types.path;
channel = mkOption { description = ''
type = types.str; file with feeds to post
default = "#news"; format:
description = "post the news in this channel"; $nick|$feedURI
}; '';
masterNick = mkOption { };
type = types.str; ircServer = mkOption {
default = "knews"; type = types.str;
description = "nickname of the master bot"; default = "localhost";
}; description = "to which server the bot should connect";
feeds = mkOption { };
type = types.path; masterNick = mkOption {
description = '' type = types.str;
file with feeds to post default = config._module.args.name;
format: description = "nickname of the master bot";
$nick|$feedURI };
''; package = mkOption {
}; type = types.package;
urlShortenerHost = mkOption { default = pkgs.newsbot-js;
type = types.str; description = "newsbot package to use";
default = "echelon"; };
description = "what server to use for url shortening, host"; urlShortenerHost = mkOption {
}; type = types.str;
urlShortenerPort = mkOption { default = "go";
type = types.str; description = "what server to use for url shortening, host";
default = "80"; };
description = "what server to use for url shortening, port"; urlShortenerPort = mkOption {
}; type = types.str;
default = "80";
description = "what server to use for url shortening, port";
};
};
}));
default = {};
}; };
imp = { imp = {
@ -61,32 +69,33 @@ let
home = "/var/empty"; home = "/var/empty";
}; };
systemd.services.newsbot-js = { systemd.services = mapAttrs' (name: newsbot:
description = "krebs newsbot"; nameValuePair "newsbot-${name}" {
after = [ "network.target" ]; after = [ "network.target" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
path = with pkgs; [ path = with pkgs; [
newsbot-js newsbot-js
]; ];
environment = { environment = {
irc_server = cfg.ircServer; irc_server = newsbot.ircServer;
master_nick = cfg.masterNick; master_nick = newsbot.masterNick;
news_channel = cfg.channel; news_channel = newsbot.channel;
feeds_file = cfg.feeds; feeds_file = newsbot.feeds;
url_shortener_host = cfg.urlShortenerHost; url_shortener_host = newsbot.urlShortenerHost;
url_shortener_port = cfg.urlShortenerPort; url_shortener_port = newsbot.urlShortenerPort;
}; };
restartIfChanged = true; restartIfChanged = true;
serviceConfig = { serviceConfig = {
User = "newsbot-js"; User = "newsbot-js";
Restart = "always"; Restart = "always";
ExecStart = "${cfg.package}/bin/newsbot"; ExecStart = "${newsbot.package}/bin/newsbot";
}; };
}; }
) cfg;
}; };
in out in out