hackens-org-configurations/hosts/hackens-org/modules/webhooks.nix
2022-04-03 01:27:30 +02:00

55 lines
1.7 KiB
Nix

{ pkgs, config, lib, ... }:
with lib;
let
json = pkgs.formats.json {};
cfg = config.services.webhook;
in
{
options.services.webhooks = {
enable = mkEnableOption "Set up webhooks";
package = 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 = json.type;
description = "Configuration for this webhook, check <link xlink:href="https://github.com/adnanh/webhook/blob/master/docs/Hook-Definition.md"/> for supported values";
};
internalPort = mkOption {
type = types.int;
default = 9000;
description = "The local port used to (proxy)pass requests from nginx to webhook";
};
debug = mkOption {
type = types.bool;
default = false;
};
config = mkIf cfg.enable {
services.nginx = {
enable = true;
virtualHosts."${cfg.hostname}" = {
locations."${cfg.endpoint}".proxyPass = "http://127.0.0.1:${toString cfg.internalPort}/hooks";
enableACME = if cfg.debug then false else true;
};
};
systemd.services.webhook = {
enable = true;
unitConfig = {
Description = "Small server for creating HTTP hooks";
Documentation = "https://github.com/adnanh/webhook/";
};
script = "${cfg.package}/bin/webhook -nopanic -ip \"127.0.0.1\" -port \"${toString cfg.internalPort}\" -verbose -hooks ${json.generate "conf.json" cfg.hooks}";
wantedBy = [ "mulit-user.target" ];
};
};
}