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,33 +6,23 @@ 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";
};
ircServer = mkOption {
type = types.str;
default = "echelon.retiolum";
description = "to which server the bot should connect";
};
channel = mkOption { channel = mkOption {
type = types.str; type = types.str;
default = "#news"; default = "#${config._module.args.name}";
description = "post the news in this channel"; description = "post the news in this channel";
}; };
masterNick = mkOption {
type = types.str;
default = "knews";
description = "nickname of the master bot";
};
feeds = mkOption { feeds = mkOption {
type = types.path; type = types.path;
description = '' description = ''
@ -41,9 +31,24 @@ let
$nick|$feedURI $nick|$feedURI
''; '';
}; };
ircServer = mkOption {
type = types.str;
default = "localhost";
description = "to which server the bot should connect";
};
masterNick = mkOption {
type = types.str;
default = config._module.args.name;
description = "nickname of the master bot";
};
package = mkOption {
type = types.package;
default = pkgs.newsbot-js;
description = "newsbot package to use";
};
urlShortenerHost = mkOption { urlShortenerHost = mkOption {
type = types.str; type = types.str;
default = "echelon"; default = "go";
description = "what server to use for url shortening, host"; description = "what server to use for url shortening, host";
}; };
urlShortenerPort = mkOption { urlShortenerPort = mkOption {
@ -52,6 +57,9 @@ let
description = "what server to use for url shortening, port"; description = "what server to use for url shortening, port";
}; };
}; };
}));
default = {};
};
imp = { imp = {
users.extraUsers.newsbot-js = { users.extraUsers.newsbot-js = {
@ -61,8 +69,8 @@ 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" ];
@ -71,12 +79,12 @@ let
]; ];
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;
@ -84,9 +92,10 @@ let
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