27c45b82cc
This greatly improves readability and makes it easier to discover options. This commit was genereated by running the following script inside the repo root dir: #!/usr/bin/env ruby def transform(src) return false if src.include?('inherit options;') success = false options = nil src.sub!(/^ options.*?^ }.*?;/m) do |match| options = match " inherit options;" end return false if !options src.sub!(/^with lib;\s*let\n+/m) do |match| success = true <<~EOF with lib; let #{options} EOF end success end Dir['modules/**/*.nix'].each do |f| src = File.read(f) if transform(src) puts "Changed file #{f}" File.write(f, src) end end
51 lines
1.1 KiB
Nix
51 lines
1.1 KiB
Nix
{ config, lib, ... }:
|
|
|
|
with lib;
|
|
let
|
|
options.services.clightning.plugins.zmq = {
|
|
enable = mkEnableOption "ZMQ (clightning plugin)";
|
|
} // lib.genAttrs endpoints mkEndpointOption;
|
|
|
|
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
|
|
{
|
|
inherit options;
|
|
|
|
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;
|
|
};
|
|
}
|