hackens-org-configurations/hosts/hackens-org/modules/webhook.nix
2022-04-02 15:47:36 +02:00

55 lines
1.8 KiB
Nix

{ 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 <link xlink:href="https://github.com/adnanh/webhook/blob/master/docs/Hook-Definition.md"/> 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" ];
}