{ pkgs, config, lib, ... }: with lib; let json = pkgs.formats.json {}; cfg = config.services.webhook; debug = config.my.debug; in options.services.webhook = { enable = mkEnableOption "Set up webhooks"; pkg = mkOption { type = types.package; default = pkgs.webhook; description = "`webhook` package to use"; }; hostname = mkOption { type = types.str; description = "The vhost on which webhook will listen"; }; endPoint = mkOption { type = types.str; default = "hooks"; description = "The endpoint of the webhooks"; }; hooks = mkOption { type = types.listOf (types.submodule { options = mkOption { type = json.type; description = "Configuration for this webhook, check for supported values" }; }); description = "An list of enabled webhooks"; }; internalPort = mkOption { type = types.int; default = 9000; description = "The local port used to (proxy)pass requests from nginx to webhook"; }; }; config = mkIf cfg.enable { services.nginx = { enableACME = if debug then false else true; enable = true; virtualHosts."${cfg.hostname}".locations."${endpoint}".proxyPass = "http://127.0.0.1:${cfg.internalPort}/hooks"; }; systemd.services.webhook = { unitConfig = { Description = "Small server for creating HTTP hooks"; Documentation = "https://github.com/adnanh/webhook/"; }; serviceConfig = { ExecStart = "${cfg.pkg} -ip \"127.0.0.1\" -port \"${cfg.internalPort}\" -verbose -hooks ${json.generate "conf.json" cfg.hooks}"; }; wantedBy = [ "mulit-user.target" ]; }