at 16.09-beta 4.3 kB view raw
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 default = "${pkgs.venus}/themes/classic_fancy"; 103 type = types.path; 104 description = '' 105 Directory containing a config.ini file which is merged with this one. 106 This is typically used to specify templating and bill of material 107 information. 108 ''; 109 }; 110 111 outputDirectory = mkOption { 112 type = types.path; 113 description = '' 114 Directory to place output files. 115 ''; 116 }; 117 118 cacheDirectory = mkOption { 119 default = "/var/cache/venus"; 120 type = types.path; 121 description = '' 122 Where cached feeds are stored. 123 ''; 124 }; 125 126 itemsPerPage = mkOption { 127 default = 15; 128 type = types.int; 129 description = '' 130 How many items to put on each page. 131 ''; 132 }; 133 134 feeds = mkOption { 135 default = []; 136 example = [ 137 { 138 name = "Rok Garbas"; 139 feedUrl= "http://url/to/rss/feed.xml"; 140 homepageUrl = "http://garbas.si"; 141 } 142 ]; 143 description = '' 144 List of feeds. 145 ''; 146 }; 147 148 }; 149 }; 150 151 config = mkIf cfg.enable { 152 153 system.activationScripts.venus = 154 '' 155 mkdir -p ${cfg.outputDirectory} 156 chown ${cfg.user}:${cfg.group} ${cfg.outputDirectory} -R 157 rm -rf ${cfg.cacheDirectory}/theme 158 mkdir -p ${cfg.cacheDirectory}/theme 159 cp -R ${cfg.outputTheme}/* ${cfg.cacheDirectory}/theme 160 chown ${cfg.user}:${cfg.group} ${cfg.cacheDirectory} -R 161 ''; 162 163 systemd.services.venus = 164 { description = "Planet Venus Feed Reader"; 165 path = [ pkgs.venus ]; 166 script = "exec venus-planet ${configFile}"; 167 serviceConfig.User = "${cfg.user}"; 168 serviceConfig.Group = "${cfg.group}"; 169 startAt = cfg.dates; 170 }; 171 172 }; 173}