1{ config, lib, pkgs, ... }:
2
3with lib;
4let
5 cfg = config.services.venus;
6
7 configFile = pkgs.writeText "venus.ini"
8 ''
9 [Planet]
10 name = ${cfg.name}
11 link = ${cfg.link}
12 owner_name = ${cfg.ownerName}
13 owner_email = ${cfg.ownerEmail}
14 output_theme = ${cfg.cacheDirectory}/theme
15 output_dir = ${cfg.outputDirectory}
16 cache_directory = ${cfg.cacheDirectory}
17 items_per_page = ${toString cfg.itemsPerPage}
18 ${(concatStringsSep "\n\n"
19 (map ({ name, feedUrl, homepageUrl }:
20 ''
21 [${feedUrl}]
22 name = ${name}
23 link = ${homepageUrl}
24 '') cfg.feeds))}
25 '';
26
27in
28{
29
30 options = {
31 services.venus = {
32 enable = mkOption {
33 default = false;
34 type = types.bool;
35 description = ''
36 Planet Venus is an awesome ‘river of news’ feed reader. It downloads
37 news feeds published by web sites and aggregates their content
38 together into a single combined feed, latest news first.
39 '';
40 };
41
42 dates = mkOption {
43 default = "*:0/15";
44 type = types.str;
45 description = ''
46 Specification (in the format described by
47 <citerefentry><refentrytitle>systemd.time</refentrytitle>
48 <manvolnum>5</manvolnum></citerefentry>) of the time at
49 which the Venus will collect feeds.
50 '';
51 };
52
53 user = mkOption {
54 default = "root";
55 type = types.str;
56 description = ''
57 User for running venus script.
58 '';
59 };
60
61 group = mkOption {
62 default = "root";
63 type = types.str;
64 description = ''
65 Group for running venus script.
66 '';
67 };
68
69 name = mkOption {
70 default = "NixOS Planet";
71 type = types.str;
72 description = ''
73 Your planet's name.
74 '';
75 };
76
77 link = mkOption {
78 default = "http://planet.nixos.org";
79 type = types.str;
80 description = ''
81 Link to the main page.
82 '';
83 };
84
85 ownerName = mkOption {
86 default = "Rok Garbas";
87 type = types.str;
88 description = ''
89 Your name.
90 '';
91 };
92
93 ownerEmail = mkOption {
94 default = "some@example.com";
95 type = types.str;
96 description = ''
97 Your e-mail address.
98 '';
99 };
100
101 outputTheme = mkOption {
102 type = types.path;
103 description = ''
104 Directory containing a config.ini file which is merged with this one.
105 This is typically used to specify templating and bill of material
106 information.
107 '';
108 };
109
110 outputDirectory = mkOption {
111 type = types.path;
112 description = ''
113 Directory to place output files.
114 '';
115 };
116
117 cacheDirectory = mkOption {
118 default = "/var/cache/venus";
119 type = types.path;
120 description = ''
121 Where cached feeds are stored.
122 '';
123 };
124
125 itemsPerPage = mkOption {
126 default = 15;
127 type = types.int;
128 description = ''
129 How many items to put on each page.
130 '';
131 };
132
133 feeds = mkOption {
134 default = [];
135 example = [
136 {
137 name = "Rok Garbas";
138 feedUrl= "http://url/to/rss/feed.xml";
139 homepageUrl = "http://garbas.si";
140 }
141 ];
142 description = ''
143 List of feeds.
144 '';
145 };
146
147 };
148 };
149
150 config = mkIf cfg.enable {
151
152 system.activationScripts.venus =
153 ''
154 mkdir -p ${cfg.outputDirectory}
155 chown ${cfg.user}:${cfg.group} ${cfg.outputDirectory} -R
156 rm -rf ${cfg.cacheDirectory}/theme
157 mkdir -p ${cfg.cacheDirectory}/theme
158 cp -R ${cfg.outputTheme}/* ${cfg.cacheDirectory}/theme
159 chown ${cfg.user}:${cfg.group} ${cfg.cacheDirectory} -R
160 '';
161
162 systemd.services.venus =
163 { description = "Planet Venus Feed Reader";
164 path = [ pkgs.venus ];
165 script = "exec venus-planet ${configFile}";
166 serviceConfig.User = "${cfg.user}";
167 serviceConfig.Group = "${cfg.group}";
168 environment.SSL_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt";
169 startAt = cfg.dates;
170 };
171
172 services.venus.outputTheme = mkDefault "${pkgs.venus}/themes/classic_fancy";
173
174 };
175}