summary refs log tree commit diff
path: root/nixos/modules/programs/venus.nix
blob: 58faf38777d06d88aa749261970288f996384f6d (plain) (blame)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
{ config, lib, pkgs, ... }:

with lib;
let
  cfg = config.services.venus;

  configFile = pkgs.writeText "venus.ini"
    ''
      [Planet]
      name = ${cfg.name}
      link = ${cfg.link}
      owner_name = ${cfg.ownerName}
      owner_email = ${cfg.ownerEmail}
      output_theme = ${cfg.cacheDirectory}/theme
      output_dir = ${cfg.outputDirectory}
      cache_directory = ${cfg.cacheDirectory}
      items_per_page = ${toString cfg.itemsPerPage}
      ${(concatStringsSep "\n\n"
            (map ({ name, feedUrl, homepageUrl }:
            ''
              [${feedUrl}]
              name = ${name}
              link = ${homepageUrl}
            '') cfg.feeds))}
    '';

in
{

  options = {
    services.venus = {
      enable = mkOption {
        default = false;
        type = types.bool;
        description = ''
          Planet Venus is an awesome ‘river of news’ feed reader. It downloads
          news feeds published by web sites and aggregates their content
          together into a single combined feed, latest news first.
        '';
      };

      dates = mkOption {
        default = "*:0/15";
        type = types.str;
        description = ''
          Specification (in the format described by
          <citerefentry><refentrytitle>systemd.time</refentrytitle>
          <manvolnum>7</manvolnum></citerefentry>) of the time at
          which the Venus will collect feeds.
        '';
      };

      user = mkOption {
        default = "root";
        type = types.str;
        description = ''
          User for running venus script.
        '';
      };

      group = mkOption {
        default = "root";
        type = types.str;
        description = ''
          Group for running venus script.
        '';
      };

      name = mkOption {
        default = "NixOS Planet";
        type = types.str;
        description = ''
          Your planet's name.
        '';
      };

      link = mkOption {
        default = "https://planet.nixos.org";
        type = types.str;
        description = ''
          Link to the main page.
        '';
      };

      ownerName = mkOption {
        default = "Rok Garbas";
        type = types.str;
        description = ''
          Your name.
        '';
      };

      ownerEmail = mkOption {
        default = "some@example.com";
        type = types.str;
        description = ''
          Your e-mail address.
        '';
      };

      outputTheme = mkOption {
        default = "${pkgs.venus}/themes/classic_fancy";
        type = types.path;
        description = ''
          Directory containing a config.ini file which is merged with this one.
          This is typically used to specify templating and bill of material
          information.
        '';
      };

      outputDirectory = mkOption {
        type = types.path;
        description = ''
          Directory to place output files.
        '';
      };

      cacheDirectory = mkOption {
        default = "/var/cache/venus";
        type = types.path;
        description = ''
            Where cached feeds are stored.
        '';
      };

      itemsPerPage = mkOption {
        default = 15;
        type = types.int;
        description = ''
          How many items to put on each page.
        '';
      };

      feeds = mkOption {
        default = [];
        example = [
          {
            name = "Rok Garbas";
            feedUrl= "http://url/to/rss/feed.xml";
            homepageUrl = "http://garbas.si";
          }
        ];
        description = ''
          List of feeds.
        '';
      };

    };
  };

  config = mkIf cfg.enable {

    system.activationScripts.venus =
      ''
        mkdir -p ${cfg.outputDirectory}
        chown ${cfg.user}:${cfg.group} ${cfg.outputDirectory} -R
        rm -rf ${cfg.cacheDirectory}/theme
        mkdir -p ${cfg.cacheDirectory}/theme
        cp -R ${cfg.outputTheme}/* ${cfg.cacheDirectory}/theme
        chown ${cfg.user}:${cfg.group} ${cfg.cacheDirectory} -R
      '';

    systemd.services.venus =
      { description = "Planet Venus Feed Reader";
        path  = [ pkgs.venus ];
        script = "exec venus-planet ${configFile}";
        serviceConfig.User = "${cfg.user}";
        serviceConfig.Group = "${cfg.group}";
        startAt = cfg.dates;
      };

  };
}