Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faraday #219

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@
# Automatically enables lnd.
# services.lightning-loop.enable = true;

### faraday
# Enable this module to use lightninglab's Channel Management & Optimization Tool.
# faraday (faraday daemon) will be started automatically. Users can
# interact with the daemon using `frcli`.
# services.faraday.enable = true;
### Backups
# Enable this module to use nix-bitcoin's own backups module. By default, it
# uses duplicity to incrementally back up all important files in /var/lib to
Expand Down
90 changes: 90 additions & 0 deletions modules/faraday.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.services.faraday;
inherit (config) nix-bitcoin-services;
secretsDir = config.nix-bitcoin.secretsDir;
network = config.services.bitcoind.network;
rpclisten = "${cfg.rpcAddress}:${toString cfg.rpcPort}";
in {

options.services.faraday = {
enable = mkEnableOption "faraday";
package = mkOption {
type = types.package;
default = config.nix-bitcoin.pkgs.faraday;
defaultText = "pkgs.nix-bitcoin.faraday";
description = "The package providing faraday binaries.";
};
rpcAddress = mkOption {
type = types.str;
default = "localhost";
description = "Address to listen for gRPC connections.";
};
rpcPort = mkOption {
type = types.port;
default = 8465;
description = "Port to listen for gRPC connections.";
};
faradayDir = mkOption {
type = types.path;
default = "/var/lib/faraday";
description = "The data directory for faraday.";
};
extraArgs = mkOption {
type = types.separatedString " ";
default = "";
description = "Extra command line arguments passed to faraday.";
};
cli = mkOption {
default = pkgs.writeScriptBin "frcli"
''
${cfg.package}/bin/frcli \
--rpcserver ${rpclisten} \
--faradaydir ${cfg.faradayDir} "$@"
'';
description = "Binary to connect with the faraday instance.";
};
enforceTor = nix-bitcoin-services.enforceTor;
};

config = mkIf cfg.enable {
services.lnd.enable = true;

environment.systemPackages = [ cfg.package (hiPrio cfg.cli) ];

systemd.tmpfiles.rules = [
"d '${cfg.faradayDir}' 0770 lnd lnd - -"
];


systemd.services.faraday = {
description = "Run faraday";
wantedBy = [ "multi-user.target" ];
requires = [ "lnd.service" ];
after = [ "lnd.service" ];
serviceConfig = nix-bitcoin-services.defaultHardening // {
preStart = ''
mkdir -p ${cfg.faradayDir}
chown -R 'lnd:lnd' '${cfg.faradayDir}'
'';
ExecStart = ''
${cfg.package}/bin/faraday \
--faradaydir=${cfg.faradayDir} \
--rpclisten=${rpclisten} \
--lnd.rpcserver=${config.services.lnd.rpcAddress}:${toString config.services.lnd.rpcPort} \
--lnd.macaroondir=${config.services.lnd.networkDir} \
--lnd.tlscertpath=${secretsDir}/lnd-cert
'';
User = "lnd";
Restart = "on-failure";
RestartSec = "10s";
ReadWritePaths = "${cfg.faradayDir}";
} // (if cfg.enforceTor
then nix-bitcoin-services.allowTor
else nix-bitcoin-services.allowAnyIP);
};
};
}
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ with lib;
./spark-wallet.nix
./lnd.nix
./lightning-loop.nix
./faraday.nix
./btcpayserver.nix
./electrs.nix
./liquid.nix
Expand Down
4 changes: 4 additions & 0 deletions modules/netns-isolation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ in {
joinmarket-ob-watcher = {
id = 26;
};
faraday = {
id = 28;
connections = [ "lnd" ];
};
};

services.bitcoind = {
Expand Down
1 change: 1 addition & 0 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let self = {
nixops19_09 = pkgs.callPackage ./nixops { };
netns-exec = pkgs.callPackage ./netns-exec { };
lightning-loop = pkgs.callPackage ./lightning-loop { };
faraday = pkgs.callPackage ./faraday { };
extra-container = pkgs.callPackage ./extra-container { };
clightning-plugins = import ./clightning-plugins pkgs self.nbPython3Packages;
clboss = pkgs.callPackage ./clboss { };
Expand Down
22 changes: 22 additions & 0 deletions pkgs/faraday/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{ pkgs, buildGoModule, fetchurl, lib }:

buildGoModule rec {
pname = "faraday";
version = "0.2.3-alpha";

src = fetchurl {
url = "https://github.com/lightninglabs/faraday/archive/v${version}.tar.gz";
# Use ./get-sha256.sh to fetch latest (verified) sha256
sha256 = "c016e2b16160f24abdfce0f71cdb848da3e3d78cff450fb353017d4104bd616e";
};

subPackages = [ "cmd/faraday" "cmd/frcli" ];

vendorSha256 = "1hh99nfprlmhkc36arg3w1kxby59i2l7n258cp40niv7bjn37hrq";

meta = with lib; {
description = " Faraday: Lightning Channel Management & Optimization Tool";
homepage = "https://github.com/lightninglabs/faraday";
license = lib.licenses.mit;
};
}
26 changes: 26 additions & 0 deletions pkgs/faraday/get-sha256.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p git gnupg
set -euo pipefail

TMPDIR="$(mktemp -d -p /tmp)"
trap "rm -rf $TMPDIR" EXIT
cd $TMPDIR

echo "Fetching latest release"
git clone https://github.com/lightninglabs/faraday 2> /dev/null
cd faraday
latest=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "Latest release is ${latest}"


# GPG verification
export GNUPGHOME=$TMPDIR
echo "Fetching Calra Kirk Cohen's Key"
gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys 15E7ECF257098A4EF91655EB4CA7FE54A6213C91 2> /dev/null

echo "Verifying latest release"
git verify-tag ${latest}

echo "tag: ${latest}"
# The prefix option is necessary because GitHub prefixes the archive contents in this format
echo "sha256: $(git archive --format tar.gz --prefix=faraday-${latest//v}/ ${latest} | sha256sum | cut -d\ -f1)"
4 changes: 4 additions & 0 deletions pkgs/pinned.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ in
lnd
nbxplorer
btcpayserver;
inherit (nixBitcoinPkgsUnstable)
electrs
lightning-loop
faraday;

stable = nixBitcoinPkgsStable;
unstable = nixBitcoinPkgsUnstable;
Expand Down
3 changes: 3 additions & 0 deletions test/tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ let testEnv = rec {

tests.lightning-loop = cfg.lightning-loop.enable;

tests.faraday = cfg.faraday.enable;

tests.electrs = cfg.electrs.enable;

tests.liquidd = cfg.liquidd.enable;
Expand Down Expand Up @@ -116,6 +118,7 @@ let testEnv = rec {
services.spark-wallet.enable = true;
services.lnd.enable = true;
services.lightning-loop.enable = true;
services.faraday.enable = true;
services.electrs.enable = true;
services.liquidd.enable = true;
services.btcpayserver.enable = true;
Expand Down
9 changes: 9 additions & 0 deletions test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ def _():
)


@test("faraday")
def _():
assert_running("faraday")
assert_matches("su operator -c 'frcli --version'", "version")
# Check that lightning-loop fails with the right error, making sure
# lightning-loop can connect to lnd
machine.wait_until_succeeds(log_has_string("faraday", "gRPC",))


@test("btcpayserver")
def _():
assert_running("nbxplorer")
Expand Down