at 24.11-pre 3.4 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 `sendmail` to send the 39 email. This is rss2email's default when running 40 `r2e new`. 41 42 This set contains key-value associations that will be set in the 43 `[DEFAULT]` block along with the 44 `to` parameter. 45 46 See `man r2e` 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 `null`, this will not be set in the 67 configuration file, and rss2email will make it default to 68 `rss2email.to`. 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.settings."10-rss2email"."/var/rss2email".d = { 99 user = "rss2email"; 100 group = "rss2email"; 101 mode = "0700"; 102 }; 103 104 systemd.services.rss2email = let 105 conf = pkgs.writeText "rss2email.cfg" (lib.generators.toINI {} ({ 106 DEFAULT = cfg.config; 107 } // lib.mapAttrs' (name: feed: nameValuePair "feed.${name}" ( 108 { inherit (feed) url; } // 109 lib.optionalAttrs (feed.to != null) { inherit (feed) to; } 110 )) cfg.feeds 111 )); 112 in 113 { 114 preStart = '' 115 if [ ! -f /var/rss2email/db.json ]; then 116 echo '{"version":2,"feeds":[]}' > /var/rss2email/db.json 117 fi 118 ''; 119 path = [ pkgs.system-sendmail ]; 120 serviceConfig = { 121 ExecStart = 122 "${pkgs.rss2email}/bin/r2e -c ${conf} -d /var/rss2email/db.json run"; 123 User = "rss2email"; 124 }; 125 }; 126 127 systemd.timers.rss2email = { 128 partOf = [ "rss2email.service" ]; 129 wantedBy = [ "timers.target" ]; 130 timerConfig.OnBootSec = "0"; 131 timerConfig.OnUnitActiveSec = cfg.interval; 132 }; 133 }; 134 135 meta.maintainers = with lib.maintainers; [ ekleog ]; 136}