2020-07-07 14:22:17 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.lightning-loop;
|
2021-02-03 21:44:41 +00:00
|
|
|
nbLib = config.nix-bitcoin.lib;
|
2020-07-07 14:22:17 +00:00
|
|
|
secretsDir = config.nix-bitcoin.secretsDir;
|
2020-10-16 13:46:01 +00:00
|
|
|
network = config.services.bitcoind.network;
|
2020-10-29 20:20:36 +00:00
|
|
|
rpclisten = "${cfg.rpcAddress}:${toString cfg.rpcPort}";
|
2020-09-15 08:46:15 +00:00
|
|
|
configFile = builtins.toFile "loop.conf" ''
|
|
|
|
datadir=${cfg.dataDir}
|
2020-10-16 13:46:01 +00:00
|
|
|
network=${network}
|
2020-10-29 20:20:36 +00:00
|
|
|
rpclisten=${rpclisten}
|
|
|
|
restlisten=${cfg.restAddress}:${toString cfg.restPort}
|
2020-09-15 08:46:15 +00:00
|
|
|
logdir=${cfg.dataDir}/logs
|
|
|
|
tlscertpath=${secretsDir}/loop-cert
|
|
|
|
tlskeypath=${secretsDir}/loop-key
|
|
|
|
|
2021-01-14 12:24:03 +00:00
|
|
|
lnd.host=${config.services.lnd.rpcAddress}:${toString config.services.lnd.rpcPort}
|
2021-03-07 18:28:08 +00:00
|
|
|
lnd.macaroonpath=${config.services.lnd.networkDir}/admin.macaroon
|
2020-09-15 08:46:15 +00:00
|
|
|
lnd.tlspath=${secretsDir}/lnd-cert
|
|
|
|
|
|
|
|
${optionalString (cfg.proxy != null) "server.proxy=${cfg.proxy}"}
|
2020-07-07 14:22:17 +00:00
|
|
|
|
2020-09-15 08:46:15 +00:00
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
in {
|
2020-07-07 14:22:17 +00:00
|
|
|
options.services.lightning-loop = {
|
|
|
|
enable = mkEnableOption "lightning-loop";
|
2020-10-29 20:20:36 +00:00
|
|
|
rpcAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
|
|
|
description = "Address to listen for gRPC connections.";
|
|
|
|
};
|
|
|
|
rpcPort = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 11010;
|
|
|
|
description = "Port to listen for gRPC connections.";
|
|
|
|
};
|
|
|
|
restAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = cfg.rpcAddress;
|
|
|
|
description = "Address to listen for REST connections.";
|
|
|
|
};
|
|
|
|
restPort = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8081;
|
|
|
|
description = "Port to listen for REST connections.";
|
|
|
|
};
|
2020-07-07 14:22:17 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2020-11-09 21:09:09 +00:00
|
|
|
default = config.nix-bitcoin.pkgs.lightning-loop;
|
2020-07-07 14:22:17 +00:00
|
|
|
description = "The package providing lightning-loop binaries.";
|
|
|
|
};
|
2020-09-15 08:46:15 +00:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/lightning-loop";
|
|
|
|
description = "The data directory for lightning-loop.";
|
|
|
|
};
|
2020-07-07 14:22:17 +00:00
|
|
|
proxy = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
2021-08-04 22:49:00 +00:00
|
|
|
default = if cfg.enforceTor then config.nix-bitcoin.torClientAddressWithPort else null;
|
2020-09-15 08:46:15 +00:00
|
|
|
description = "host:port of SOCKS5 proxy for connnecting to the loop server.";
|
2020-07-07 14:22:17 +00:00
|
|
|
};
|
2020-09-15 08:46:15 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
2020-07-07 14:22:17 +00:00
|
|
|
default = "";
|
2020-09-15 08:46:15 +00:00
|
|
|
example = ''
|
|
|
|
debuglevel=trace
|
|
|
|
'';
|
|
|
|
description = "Extra lines appended to the configuration file.";
|
2020-07-07 14:22:17 +00:00
|
|
|
};
|
|
|
|
cli = mkOption {
|
2020-09-15 08:46:15 +00:00
|
|
|
default = pkgs.writeScriptBin "loop" ''
|
2020-10-29 20:20:37 +00:00
|
|
|
${cfg.package}/bin/loop \
|
2020-10-29 20:20:36 +00:00
|
|
|
--rpcserver ${rpclisten} \
|
2020-10-16 13:46:01 +00:00
|
|
|
--macaroonpath '${cfg.dataDir}/${network}/loop.macaroon' \
|
|
|
|
--tlscertpath '${secretsDir}/loop-cert' "$@"
|
2020-07-07 14:22:17 +00:00
|
|
|
'';
|
2020-09-15 08:46:15 +00:00
|
|
|
description = "Binary to connect with the lightning-loop instance.";
|
2020-07-07 14:22:17 +00:00
|
|
|
};
|
2021-02-03 21:44:41 +00:00
|
|
|
enforceTor = nbLib.enforceTor;
|
2020-07-07 14:22:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2020-10-18 12:49:20 +00:00
|
|
|
services.lnd.enable = true;
|
2020-07-07 14:22:17 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package (hiPrio cfg.cli) ];
|
|
|
|
|
2020-09-15 08:46:15 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
2021-02-16 16:52:45 +00:00
|
|
|
"d '${cfg.dataDir}' 0770 ${config.services.lnd.user} ${config.services.lnd.group} - -"
|
2020-09-15 08:46:15 +00:00
|
|
|
];
|
|
|
|
|
2020-07-07 14:22:17 +00:00
|
|
|
systemd.services.lightning-loop = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "lnd.service" ];
|
|
|
|
after = [ "lnd.service" ];
|
2021-02-03 21:44:41 +00:00
|
|
|
serviceConfig = nbLib.defaultHardening // {
|
2020-09-15 08:46:15 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/loopd --configfile=${configFile}";
|
2021-02-16 16:52:45 +00:00
|
|
|
User = config.services.lnd.user;
|
2020-07-07 14:22:17 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2021-02-01 21:53:12 +00:00
|
|
|
ReadWritePaths = cfg.dataDir;
|
2021-03-22 12:19:45 +00:00
|
|
|
} // nbLib.allowedIPAddresses cfg.enforceTor;
|
2020-07-07 14:22:17 +00:00
|
|
|
};
|
2020-09-15 08:46:15 +00:00
|
|
|
|
|
|
|
nix-bitcoin.secrets = {
|
2021-02-16 16:52:45 +00:00
|
|
|
loop-key.user = config.services.lnd.user;
|
|
|
|
loop-cert.user = config.services.lnd.user;
|
2020-09-15 08:46:15 +00:00
|
|
|
};
|
2020-07-07 14:22:17 +00:00
|
|
|
};
|
|
|
|
}
|