nix-bitcoin/modules/clightning-plugins/zmq.nix
Erik Arvstedt 08fe9ba84a
services: add finer-grained address family restrictions
Due to a possible NixOS bug, this commit has no effect on NixOS 20.09
where `RestrictAddressFamilies` is a no-op.
It's only relevant for NixOS unstable with cgroups v2.

bitcoind+zmq: instead of allowing all address families, only add the required
AF_NETLINK family.

lnd: lnd only runs a zmq client, not a server, therefore it requires
no additional address families.

lightning-pool, clightning-plugin-zmq: add AF_NETLINK.
2021-03-22 14:35:29 +01:00

49 lines
1.1 KiB
Nix

{ config, lib, ... }:
with lib;
let
cfg = config.services.clightning.plugins.zmq;
nbLib = config.nix-bitcoin.lib;
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
{
options.services.clightning.plugins.zmq = {
enable = mkEnableOption "ZMQ (clightning plugin)";
} // lib.genAttrs endpoints mkEndpointOption;
config = mkIf cfg.enable {
services.clightning.extraConfig = ''
plugin=${config.nix-bitcoin.pkgs.clightning-plugins.zmq.path}
${concatStrings (map setEndpoint endpoints)}
'';
# The zmq server requires AF_NETLINK
systemd.services.clightning.serviceConfig.RestrictAddressFamilies =
mkForce nbLib.allowNetlink.RestrictAddressFamilies;
};
}