53 lines
1.7 KiB
Nix
53 lines
1.7 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 = 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";
|
|
};
|
|
};
|
|
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 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.pkg}/bin/webhook -nopanic -ip \"127.0.0.1\" -port \"${toString cfg.internalPort}\" -verbose -hooks ${json.generate "conf.json" cfg.hooks}";
|
|
wantedBy = [ "mulit-user.target" ];
|
|
};
|
|
};
|
|
}
|