summaryrefslogtreecommitdiffstats
path: root/lass/3modules/news.nix
blob: 06b80df8ddbb559859db393f80903d8ecf5c718c (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
{ config, lib, pkgs, ... }:

with import <stockholm/lib>;

let
  cfg = config.lass.news;

  out = {
    options.lass.news = api;
    config = lib.mkIf cfg.enable imp;
  };

  api = {
    enable = mkEnableOption "news";
    feeds = mkOption {
      type = types.listOf (types.submodule { options = {
        nick = mkOption {
          type = types.str;
        };
        feedurl = mkOption {
          type = types.str;
        };
        interval = mkOption {
          type = types.int;
          default = 1000;
        };
        channels = mkOption {
          type = types.listOf types.str;
        };
      };});
    };
    user = mkOption {
      type = types.user;
      default = {
        name = "news";
        home = "/var/lib/news";
      };
    };
    ircServer = mkOption {
      type = types.str;
      default = "echelon.r";
      description = "to which server the bot should connect";
    };
  };

  imp = {

    users.users.${cfg.user.name} = {
      inherit (cfg.user) home name uid;
      createHome = true;
    };

    systemd.services = listToAttrs (map (feed:
      nameValuePair "news-${feed.nick}" {
        wantedBy = [ "multi-user.target" ];
        after = [ "network.target" ];
        serviceConfig = {
          SyslogIdentifier = "news-${feed.nick}";
          User = cfg.user.name;
          PrivateTmp = true;
          Restart = "always";
          ExecStart = pkgs.writeDash "news-${feed.nick}" ''
            ${pkgs.haskellPackages.news}/bin/news '${feed.feedurl}' '${toString feed.interval}' \
              | ${pkgs.goify}/bin/goify \
              | while :; do
                ${pkgs.haskellPackages.kirk}/bin/ircout --nick '${feed.nick}' --host '${cfg.ircServer}' \
                  \${concatStringsSep " \\" feed.channels}
                done
          '';
        };
      }
    ) cfg.feeds);

  };

in out