stockholm/krebs/3modules/newsbot-js.nix

103 lines
2.6 KiB
Nix
Raw Normal View History

2015-10-18 02:25:26 +00:00
{ config, lib, pkgs, ... }:
2016-10-20 19:40:11 +00:00
with import <stockholm/lib>;
2015-10-18 02:25:26 +00:00
let
2016-03-15 13:37:46 +00:00
cfg = config.krebs.newsbot-js;
2015-10-18 02:25:26 +00:00
2017-09-08 22:09:04 +00:00
enable = cfg != {};
2015-10-18 02:25:26 +00:00
out = {
2016-03-15 13:37:46 +00:00
options.krebs.newsbot-js = api;
2017-09-08 22:09:04 +00:00
config = mkIf enable imp;
2015-10-18 02:25:26 +00:00
};
2017-09-08 22:09:04 +00:00
api = mkOption {
type = types.attrsOf (types.submodule ({ config, ... }: {
options = {
enable = mkEnableOption "Enable krebs newsbot" // { default = true; };
channel = mkOption {
type = types.str;
default = "#${config._module.args.name}";
description = "post the news in this channel";
};
feeds = mkOption {
type = types.path;
description = ''
file with feeds to post
format:
$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 {
type = types.str;
default = "go";
description = "what server to use for url shortening, host";
};
urlShortenerPort = mkOption {
type = types.str;
default = "80";
description = "what server to use for url shortening, port";
};
};
}));
default = {};
2015-10-18 02:25:26 +00:00
};
imp = {
users.extraUsers.newsbot-js = {
name = "newsbot-js";
2015-12-26 04:55:13 +00:00
uid = genid "newsbot-js";
2015-10-18 02:25:26 +00:00
description = "newsbot-js user";
home = "/var/empty";
};
2017-09-08 22:09:04 +00:00
systemd.services = mapAttrs' (name: newsbot:
nameValuePair "newsbot-${name}" {
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
2015-10-18 02:25:26 +00:00
2017-09-08 22:09:04 +00:00
path = with pkgs; [
newsbot-js
];
2015-10-18 02:25:26 +00:00
2017-09-08 22:09:04 +00:00
environment = {
irc_server = newsbot.ircServer;
master_nick = newsbot.masterNick;
news_channel = newsbot.channel;
feeds_file = newsbot.feeds;
url_shortener_host = newsbot.urlShortenerHost;
url_shortener_port = newsbot.urlShortenerPort;
};
2015-10-18 02:25:26 +00:00
2017-09-08 22:09:04 +00:00
restartIfChanged = true;
2015-10-18 02:25:26 +00:00
2017-09-08 22:09:04 +00:00
serviceConfig = {
User = "newsbot-js";
Restart = "always";
ExecStart = "${newsbot.package}/bin/newsbot";
2018-04-26 10:56:15 +00:00
WatchdogSec = "86400";
2017-09-08 22:09:04 +00:00
};
}
) cfg;
2015-10-18 02:25:26 +00:00
};
in out