summaryrefslogtreecommitdiffstats
path: root/krebs/3modules/newsbot-js.nix
blob: 2ff9a5ebbd9655e0716a2816d452933046965c9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{ config, lib, pkgs, ... }:

with import <stockholm/lib>;

let

  cfg = config.krebs.newsbot-js;

  out = {
    options.krebs.newsbot-js = api;
    config = mkIf cfg.enable imp;
  };

  api = {
    enable = mkEnableOption "Enable krebs newsbot";
    ircServer = mkOption {
      type = types.str;
      default = "echelon.retiolum";
      description = "to which server the bot should connect";
    };
    channel = mkOption {
      type = types.str;
      default = "#news";
      description = "post the news in this channel";
    };
    masterNick = mkOption {
      type = types.str;
      default = "knews";
      description = "nickname of the master bot";
    };
    feeds = mkOption {
      type = types.path;
      description = ''
        file with feeds to post
        format:
        $nick|$feedURI
      '';
    };
    urlShortenerHost = mkOption {
      type = types.str;
      default = "echelon";
      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";
    };
  };

  imp = {
    users.extraUsers.newsbot-js = {
      name = "newsbot-js";
      uid = genid "newsbot-js";
      description = "newsbot-js user";
      home = "/var/empty";
    };

    systemd.services.newsbot-js = {
      description = "krebs newsbot";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];

      path = with pkgs; [
        newsbot-js
      ];

      environment = {
        irc_server = cfg.ircServer;
        master_nick = cfg.masterNick;
        news_channel = cfg.channel;
        feeds_file = cfg.feeds;
        url_shortener_host = cfg.urlShortenerHost;
        url_shortener_port = cfg.urlShortenerPort;
      };

      restartIfChanged = true;

      serviceConfig = {
        User = "newsbot-js";
        Restart = "always";
        ExecStart = "${pkgs.newsbot-js}/bin/newsbot";
      };
    };
  };

in out