at 23.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 = lib.mdDoc "Whether to enable rss2email."; 19 }; 20 21 to = mkOption { 22 type = types.str; 23 description = lib.mdDoc "Mail address to which to send emails"; 24 }; 25 26 interval = mkOption { 27 type = types.str; 28 default = "12h"; 29 description = lib.mdDoc "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 = lib.mdDoc '' 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 = lib.mdDoc "The feeds to watch."; 53 type = types.attrsOf (types.submodule { 54 options = { 55 url = mkOption { 56 type = types.str; 57 description = lib.mdDoc "The URL at which to fetch the feed."; 58 }; 59 60 to = mkOption { 61 type = with types; nullOr str; 62 default = null; 63 description = lib.mdDoc '' 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.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 if [ ! -f /var/rss2email/db.json ]; then 114 echo '{"version":2,"feeds":[]}' > /var/rss2email/db.json 115 fi 116 ''; 117 path = [ pkgs.system-sendmail ]; 118 serviceConfig = { 119 ExecStart = 120 "${pkgs.rss2email}/bin/r2e -c ${conf} -d /var/rss2email/db.json run"; 121 User = "rss2email"; 122 }; 123 }; 124 125 systemd.timers.rss2email = { 126 partOf = [ "rss2email.service" ]; 127 wantedBy = [ "timers.target" ]; 128 timerConfig.OnBootSec = "0"; 129 timerConfig.OnUnitActiveSec = cfg.interval; 130 }; 131 }; 132 133 meta.maintainers = with lib.maintainers; [ ekleog ]; 134}