pkg: { config, lib, ... }: let cfg = config.services.noisebell-rss; bin = "${pkg}/bin/noisebell-rss"; in { options.services.noisebell-rss = { enable = lib.mkEnableOption "noisebell RSS/Atom feed"; domain = lib.mkOption { type = lib.types.str; description = "Domain for the Caddy virtual host."; }; port = lib.mkOption { type = lib.types.port; default = 3002; }; cacheUrl = lib.mkOption { type = lib.types.str; description = "URL of the cache service (e.g. http://localhost:3000)."; }; }; config = lib.mkIf cfg.enable { users.users.noisebell-rss = { isSystemUser = true; group = "noisebell-rss"; }; users.groups.noisebell-rss = {}; services.caddy.virtualHosts.${cfg.domain}.extraConfig = '' reverse_proxy localhost:${toString cfg.port} ''; systemd.services.noisebell-rss = { description = "Noisebell RSS/Atom feed"; wantedBy = [ "multi-user.target" ]; after = [ "network-online.target" "noisebell-cache.service" ]; wants = [ "network-online.target" ]; environment = { NOISEBELL_RSS_PORT = toString cfg.port; NOISEBELL_RSS_CACHE_URL = cfg.cacheUrl; NOISEBELL_RSS_SITE_URL = "https://${cfg.domain}"; RUST_LOG = "info"; }; script = '' exec ${bin} ''; serviceConfig = { Type = "simple"; Restart = "on-failure"; RestartSec = 5; User = "noisebell-rss"; Group = "noisebell-rss"; NoNewPrivileges = true; ProtectSystem = "strict"; ProtectHome = true; PrivateTmp = true; ProtectKernelTunables = true; ProtectKernelModules = true; ProtectControlGroups = true; RestrictSUIDSGID = true; }; }; }; }