2020-11-18 18:01:45 -08:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
2021-09-13 04:40:47 -07:00
|
|
|
options.services.clightning.plugins.zmq = {
|
|
|
|
enable = mkEnableOption "ZMQ (clightning plugin)";
|
|
|
|
} // lib.genAttrs endpoints mkEndpointOption;
|
|
|
|
|
2020-11-18 18:01:45 -08:00
|
|
|
cfg = config.services.clightning.plugins.zmq;
|
|
|
|
|
2021-03-22 05:19:46 -07:00
|
|
|
nbLib = config.nix-bitcoin.lib;
|
|
|
|
|
2020-11-18 18:01:45 -08:00
|
|
|
endpoints = [
|
|
|
|
"channel-opened"
|
|
|
|
"connect"
|
|
|
|
"disconnect"
|
|
|
|
"invoice-payment"
|
|
|
|
"warning"
|
|
|
|
"forward-event"
|
|
|
|
"sendpay-success"
|
|
|
|
"sendpay-failure"
|
|
|
|
];
|
|
|
|
|
|
|
|
mkEndpointOption = name:
|
|
|
|
mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = "Endpoint for ${name}";
|
|
|
|
};
|
|
|
|
|
|
|
|
setEndpoint = ep:
|
|
|
|
let value = builtins.getAttr ep cfg; in
|
|
|
|
optionalString (value != null) ''
|
|
|
|
zmq-pub-${ep}=${value}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
2021-09-13 04:40:47 -07:00
|
|
|
inherit options;
|
2020-11-18 18:01:45 -08:00
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.clightning.extraConfig = ''
|
|
|
|
plugin=${config.nix-bitcoin.pkgs.clightning-plugins.zmq.path}
|
|
|
|
${concatStrings (map setEndpoint endpoints)}
|
|
|
|
'';
|
2021-03-22 05:19:46 -07:00
|
|
|
|
|
|
|
# The zmq server requires AF_NETLINK
|
|
|
|
systemd.services.clightning.serviceConfig.RestrictAddressFamilies =
|
|
|
|
mkForce nbLib.allowNetlink.RestrictAddressFamilies;
|
2020-11-18 18:01:45 -08:00
|
|
|
};
|
|
|
|
}
|