2020-07-07 07:22:17 -07:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.lightning-loop;
|
|
|
|
inherit (config) nix-bitcoin-services;
|
|
|
|
secretsDir = config.nix-bitcoin.secretsDir;
|
2020-10-16 06:46:01 -07:00
|
|
|
network = config.services.bitcoind.network;
|
2020-09-15 01:46:15 -07:00
|
|
|
configFile = builtins.toFile "loop.conf" ''
|
|
|
|
datadir=${cfg.dataDir}
|
2020-10-16 06:46:01 -07:00
|
|
|
network=${network}
|
2020-09-15 01:46:15 -07:00
|
|
|
logdir=${cfg.dataDir}/logs
|
|
|
|
tlscertpath=${secretsDir}/loop-cert
|
|
|
|
tlskeypath=${secretsDir}/loop-key
|
|
|
|
|
|
|
|
lnd.host=${builtins.elemAt config.services.lnd.rpclisten 0}:${toString config.services.lnd.rpcPort}
|
2020-10-16 08:43:08 -07:00
|
|
|
lnd.macaroondir=${config.services.lnd.networkDir}
|
2020-09-15 01:46:15 -07:00
|
|
|
lnd.tlspath=${secretsDir}/lnd-cert
|
|
|
|
|
|
|
|
${optionalString (cfg.proxy != null) "server.proxy=${cfg.proxy}"}
|
2020-07-07 07:22:17 -07:00
|
|
|
|
2020-09-15 01:46:15 -07:00
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
in {
|
2020-07-07 07:22:17 -07:00
|
|
|
options.services.lightning-loop = {
|
|
|
|
enable = mkEnableOption "lightning-loop";
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.nix-bitcoin.lightning-loop;
|
|
|
|
defaultText = "pkgs.nix-bitcoin.lightning-loop";
|
|
|
|
description = "The package providing lightning-loop binaries.";
|
|
|
|
};
|
2020-09-15 01:46:15 -07:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/lightning-loop";
|
|
|
|
description = "The data directory for lightning-loop.";
|
|
|
|
};
|
2020-07-07 07:22:17 -07:00
|
|
|
proxy = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2020-09-15 01:46:15 -07:00
|
|
|
description = "host:port of SOCKS5 proxy for connnecting to the loop server.";
|
2020-07-07 07:22:17 -07:00
|
|
|
};
|
2020-09-15 01:46:15 -07:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
2020-07-07 07:22:17 -07:00
|
|
|
default = "";
|
2020-09-15 01:46:15 -07:00
|
|
|
example = ''
|
|
|
|
debuglevel=trace
|
|
|
|
'';
|
|
|
|
description = "Extra lines appended to the configuration file.";
|
2020-07-07 07:22:17 -07:00
|
|
|
};
|
|
|
|
cli = mkOption {
|
2020-09-15 01:46:15 -07:00
|
|
|
default = pkgs.writeScriptBin "loop" ''
|
2020-10-16 06:46:01 -07:00
|
|
|
${cfg.cliExec} ${cfg.package}/bin/loop \
|
|
|
|
--macaroonpath '${cfg.dataDir}/${network}/loop.macaroon' \
|
|
|
|
--tlscertpath '${secretsDir}/loop-cert' "$@"
|
2020-07-07 07:22:17 -07:00
|
|
|
'';
|
2020-09-15 01:46:15 -07:00
|
|
|
description = "Binary to connect with the lightning-loop instance.";
|
2020-07-07 07:22:17 -07:00
|
|
|
};
|
2020-08-21 13:36:00 -07:00
|
|
|
inherit (nix-bitcoin-services) cliExec;
|
2020-09-15 01:46:15 -07:00
|
|
|
enforceTor = nix-bitcoin-services.enforceTor;
|
2020-07-07 07:22:17 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2020-10-18 05:49:20 -07:00
|
|
|
services.lnd.enable = true;
|
2020-07-07 07:22:17 -07:00
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package (hiPrio cfg.cli) ];
|
|
|
|
|
2020-09-15 01:46:15 -07:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.dataDir}' 0770 lnd lnd - -"
|
|
|
|
];
|
|
|
|
|
2020-07-07 07:22:17 -07:00
|
|
|
systemd.services.lightning-loop = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "lnd.service" ];
|
|
|
|
after = [ "lnd.service" ];
|
|
|
|
serviceConfig = nix-bitcoin-services.defaultHardening // {
|
2020-09-15 01:46:15 -07:00
|
|
|
ExecStart = "${cfg.package}/bin/loopd --configfile=${configFile}";
|
2020-07-07 07:22:17 -07:00
|
|
|
User = "lnd";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2020-09-15 01:46:15 -07:00
|
|
|
ReadWritePaths = "${cfg.dataDir}";
|
2020-07-07 07:22:17 -07:00
|
|
|
} // (if cfg.enforceTor
|
2020-09-15 01:46:15 -07:00
|
|
|
then nix-bitcoin-services.allowTor
|
|
|
|
else nix-bitcoin-services.allowAnyIP);
|
2020-07-07 07:22:17 -07:00
|
|
|
};
|
2020-09-15 01:46:15 -07:00
|
|
|
|
|
|
|
nix-bitcoin.secrets = {
|
|
|
|
loop-key.user = "lnd";
|
|
|
|
loop-cert.user = "lnd";
|
|
|
|
};
|
2020-07-07 07:22:17 -07:00
|
|
|
};
|
|
|
|
}
|