at 21.11-pre 3.5 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.rss2email; 7in { 8 9 ###### interface 10 11 options = { 12 13 services.rss2email = { 14 15 enable = mkOption { 16 type = types.bool; 17 default = false; 18 description = "Whether to enable rss2email."; 19 }; 20 21 to = mkOption { 22 type = types.str; 23 description = "Mail address to which to send emails"; 24 }; 25 26 interval = mkOption { 27 type = types.str; 28 default = "12h"; 29 description = "How often to check the feeds, in systemd interval format"; 30 }; 31 32 config = mkOption { 33 type = with types; attrsOf (oneOf [ str int bool ]); 34 default = {}; 35 description = '' 36 The configuration to give rss2email. 37 38 Default will use system-wide <literal>sendmail</literal> to send the 39 email. This is rss2email's default when running 40 <literal>r2e new</literal>. 41 42 This set contains key-value associations that will be set in the 43 <literal>[DEFAULT]</literal> block along with the 44 <literal>to</literal> parameter. 45 46 See <literal>man r2e</literal> for more information on which 47 parameters are accepted. 48 ''; 49 }; 50 51 feeds = mkOption { 52 description = "The feeds to watch."; 53 type = types.attrsOf (types.submodule { 54 options = { 55 url = mkOption { 56 type = types.str; 57 description = "The URL at which to fetch the feed."; 58 }; 59 60 to = mkOption { 61 type = with types; nullOr str; 62 default = null; 63 description = '' 64 Email address to which to send feed items. 65 66 If <literal>null</literal>, this will not be set in the 67 configuration file, and rss2email will make it default to 68 <literal>rss2email.to</literal>. 69 ''; 70 }; 71 }; 72 }); 73 }; 74 }; 75 76 }; 77 78 79 ###### implementation 80 81 config = mkIf cfg.enable { 82 users.groups = { 83 rss2email.gid = config.ids.gids.rss2email; 84 }; 85 86 users.users = { 87 rss2email = { 88 description = "rss2email user"; 89 uid = config.ids.uids.rss2email; 90 group = "rss2email"; 91 }; 92 }; 93 94 environment.systemPackages = with pkgs; [ rss2email ]; 95 96 services.rss2email.config.to = cfg.to; 97 98 systemd.tmpfiles.rules = [ 99 "d /var/rss2email 0700 rss2email rss2email - -" 100 ]; 101 102 systemd.services.rss2email = let 103 conf = pkgs.writeText "rss2email.cfg" (lib.generators.toINI {} ({ 104 DEFAULT = cfg.config; 105 } // lib.mapAttrs' (name: feed: nameValuePair "feed.${name}" ( 106 { inherit (feed) url; } // 107 lib.optionalAttrs (feed.to != null) { inherit (feed) to; } 108 )) cfg.feeds 109 )); 110 in 111 { 112 preStart = '' 113 cp ${conf} /var/rss2email/conf.cfg 114 if [ ! -f /var/rss2email/db.json ]; then 115 echo '{"version":2,"feeds":[]}' > /var/rss2email/db.json 116 fi 117 ''; 118 path = [ pkgs.system-sendmail ]; 119 serviceConfig = { 120 ExecStart = 121 "${pkgs.rss2email}/bin/r2e -c /var/rss2email/conf.cfg -d /var/rss2email/db.json run"; 122 User = "rss2email"; 123 }; 124 }; 125 126 systemd.timers.rss2email = { 127 partOf = [ "rss2email.service" ]; 128 wantedBy = [ "timers.target" ]; 129 timerConfig.OnBootSec = "0"; 130 timerConfig.OnUnitActiveSec = cfg.interval; 131 }; 132 }; 133 134 meta.maintainers = with lib.maintainers; [ ekleog ]; 135}