2021-03-01 01:59:23 -08:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
options.services.lightning-pool = {
|
2021-12-14 10:51:23 -08:00
|
|
|
enable = mkEnableOption "Lightning Pool, a marketplace for inbound lightning liquidity ";
|
2021-03-01 01:59:23 -08:00
|
|
|
rpcAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
2022-12-18 04:13:47 -08:00
|
|
|
description = mdDoc "Address to listen for gRPC connections.";
|
2021-03-01 01:59:23 -08:00
|
|
|
};
|
|
|
|
rpcPort = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 12010;
|
2022-12-18 04:13:47 -08:00
|
|
|
description = mdDoc "Port to listen for gRPC connections.";
|
2021-03-01 01:59:23 -08:00
|
|
|
};
|
|
|
|
restAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = cfg.rpcAddress;
|
2022-12-18 04:13:47 -08:00
|
|
|
description = mdDoc "Address to listen for REST connections.";
|
2021-03-01 01:59:23 -08:00
|
|
|
};
|
|
|
|
restPort = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8281;
|
2022-12-18 04:13:47 -08:00
|
|
|
description = mdDoc "Port to listen for REST connections.";
|
2021-03-01 01:59:23 -08:00
|
|
|
};
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = config.nix-bitcoin.pkgs.lightning-pool;
|
2021-12-07 19:07:28 -08:00
|
|
|
defaultText = "config.nix-bitcoin.pkgs.lightning-pool";
|
2022-12-18 04:13:47 -08:00
|
|
|
description = mdDoc "The package providing lightning-pool binaries.";
|
2021-03-01 01:59:23 -08:00
|
|
|
};
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/lightning-pool";
|
2022-12-18 04:13:47 -08:00
|
|
|
description = mdDoc "The data directory for lightning-pool.";
|
2021-03-01 01:59:23 -08:00
|
|
|
};
|
|
|
|
proxy = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
2021-11-28 12:24:49 -08:00
|
|
|
default = if cfg.tor.proxy then config.nix-bitcoin.torClientAddressWithPort else null;
|
2022-12-18 04:13:47 -08:00
|
|
|
description = mdDoc "host:port of SOCKS5 proxy for connnecting to the pool auction server.";
|
2021-03-01 01:59:23 -08:00
|
|
|
};
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
debuglevel=trace
|
|
|
|
'';
|
2022-12-18 04:13:47 -08:00
|
|
|
description = mdDoc "Extra lines appended to the configuration file.";
|
2021-03-01 01:59:23 -08:00
|
|
|
};
|
|
|
|
cli = mkOption {
|
2022-11-08 13:45:19 -08:00
|
|
|
default = pkgs.writers.writeBashBin "pool" ''
|
2021-03-01 01:59:23 -08:00
|
|
|
exec ${cfg.package}/bin/pool \
|
2021-10-01 02:51:57 -07:00
|
|
|
--rpcserver ${nbLib.addressWithPort cfg.rpcAddress cfg.rpcPort} \
|
2021-03-01 01:59:23 -08:00
|
|
|
--network ${network} \
|
|
|
|
--basedir '${cfg.dataDir}' "$@"
|
|
|
|
'';
|
2021-12-07 19:07:28 -08:00
|
|
|
defaultText = "(See source)";
|
2022-12-18 04:13:47 -08:00
|
|
|
description = mdDoc "Binary to connect with the lightning-pool instance.";
|
2021-03-01 01:59:23 -08:00
|
|
|
};
|
2021-11-28 12:24:49 -08:00
|
|
|
tor = nbLib.tor;
|
2021-03-01 01:59:23 -08:00
|
|
|
};
|
|
|
|
|
2021-09-13 04:40:47 -07:00
|
|
|
cfg = config.services.lightning-pool;
|
|
|
|
nbLib = config.nix-bitcoin.lib;
|
|
|
|
|
|
|
|
lnd = config.services.lnd;
|
|
|
|
|
|
|
|
network = config.services.bitcoind.network;
|
|
|
|
configFile = builtins.toFile "pool.conf" ''
|
2021-10-01 02:51:57 -07:00
|
|
|
rpclisten=${cfg.rpcAddress}:${toString cfg.rpcPort}
|
2021-09-13 04:40:47 -07:00
|
|
|
restlisten=${cfg.restAddress}:${toString cfg.restPort}
|
|
|
|
${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"}
|
|
|
|
|
|
|
|
lnd.host=${lnd.rpcAddress}:${toString lnd.rpcPort}
|
|
|
|
lnd.macaroondir=${lnd.networkDir}
|
|
|
|
lnd.tlspath=${lnd.certPath}
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
inherit options;
|
|
|
|
|
2021-03-01 01:59:23 -08:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.lnd.enable = true;
|
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package (hiPrio cfg.cli) ];
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.dataDir}' 0770 lnd lnd - -"
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.lightning-pool = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "lnd.service" ];
|
|
|
|
after = [ "lnd.service" ];
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p '${cfg.dataDir}/${network}'
|
|
|
|
ln -sfn ${configFile} '${cfg.dataDir}/${network}/poold.conf'
|
|
|
|
'';
|
|
|
|
serviceConfig = nbLib.defaultHardening // {
|
|
|
|
ExecStart = "${cfg.package}/bin/poold --basedir='${cfg.dataDir}' --network=${network}";
|
|
|
|
User = "lnd";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2022-05-07 11:34:21 -07:00
|
|
|
ReadWritePaths = [ cfg.dataDir ];
|
2021-11-28 12:24:49 -08:00
|
|
|
} // (nbLib.allowedIPAddresses cfg.tor.enforce)
|
2021-03-22 05:19:46 -07:00
|
|
|
// nbLib.allowNetlink; # required by gRPC-Go
|
2021-03-01 01:59:23 -08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|