Skip to content

Commit 093aafe

Browse files
committed
faraday: add pkg & module
1 parent 0c9613d commit 093aafe

File tree

8 files changed

+153
-0
lines changed

8 files changed

+153
-0
lines changed

examples/configuration.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@
153153
# Automatically enables lnd.
154154
# services.lightning-loop.enable = true;
155155

156+
### faraday
157+
# Enable this module to use lightninglab's Channel Management & Optimization Tool.
158+
# faraday (faraday daemon) will be started automatically. Users can
159+
# interact with the daemon using `frcli`.
160+
# services.faraday.enable = true;
156161
### Backups
157162
# Enable this module to use nix-bitcoin's own backups module. By default, it
158163
# uses duplicity to incrementally back up all important files in /var/lib to

modules/faraday.nix

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{ config, lib, pkgs, ... }:
2+
3+
with lib;
4+
5+
let
6+
cfg = config.services.faraday;
7+
inherit (config) nix-bitcoin-services;
8+
secretsDir = config.nix-bitcoin.secretsDir;
9+
network = config.services.bitcoind.network;
10+
rpclisten = "${cfg.rpcAddress}:${toString cfg.rpcPort}";
11+
in {
12+
13+
options.services.faraday = {
14+
enable = mkEnableOption "faraday";
15+
package = mkOption {
16+
type = types.package;
17+
default = config.nix-bitcoin.pkgs.faraday;
18+
defaultText = "pkgs.nix-bitcoin.faraday";
19+
description = "The package providing faraday binaries.";
20+
};
21+
rpcAddress = mkOption {
22+
type = types.str;
23+
default = "localhost";
24+
description = "Address to listen for gRPC connections.";
25+
};
26+
rpcPort = mkOption {
27+
type = types.port;
28+
default = 8465;
29+
description = "Port to listen for gRPC connections.";
30+
};
31+
faradayDir = mkOption {
32+
type = types.path;
33+
default = "/var/lib/faraday";
34+
description = "The data directory for faraday.";
35+
};
36+
extraArgs = mkOption {
37+
type = types.separatedString " ";
38+
default = "";
39+
description = "Extra command line arguments passed to faraday.";
40+
};
41+
cli = mkOption {
42+
default = pkgs.writeScriptBin "frcli"
43+
''
44+
${cfg.package}/bin/frcli \
45+
--rpcserver ${rpclisten} \
46+
--faradaydir ${cfg.faradayDir} "$@"
47+
'';
48+
description = "Binary to connect with the faraday instance.";
49+
};
50+
enforceTor = nix-bitcoin-services.enforceTor;
51+
};
52+
53+
config = mkIf cfg.enable {
54+
services.lnd.enable = true;
55+
56+
environment.systemPackages = [ cfg.package (hiPrio cfg.cli) ];
57+
58+
systemd.tmpfiles.rules = [
59+
"d '${cfg.faradayDir}' 0770 lnd lnd - -"
60+
];
61+
62+
63+
systemd.services.faraday = {
64+
description = "Run faraday";
65+
wantedBy = [ "multi-user.target" ];
66+
requires = [ "lnd.service" ];
67+
after = [ "lnd.service" ];
68+
serviceConfig = nix-bitcoin-services.defaultHardening // {
69+
preStart = ''
70+
mkdir -p ${cfg.faradayDir}
71+
chown -R 'lnd:lnd' '${cfg.faradayDir}'
72+
'';
73+
ExecStart = ''
74+
${cfg.package}/bin/faraday \
75+
--faradaydir=${cfg.faradayDir} \
76+
--rpclisten=${rpclisten} \
77+
--lnd.rpcserver=${config.services.lnd.rpcAddress}:${toString config.services.lnd.rpcPort} \
78+
--lnd.macaroondir=${config.services.lnd.networkDir} \
79+
--lnd.tlscertpath=${secretsDir}/lnd-cert
80+
'';
81+
User = "lnd";
82+
Restart = "on-failure";
83+
RestartSec = "10s";
84+
ReadWritePaths = "${cfg.faradayDir}";
85+
} // (if cfg.enforceTor
86+
then nix-bitcoin-services.allowTor
87+
else nix-bitcoin-services.allowAnyIP);
88+
};
89+
};
90+
}

modules/modules.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ with lib;
1414
./spark-wallet.nix
1515
./lnd.nix
1616
./lightning-loop.nix
17+
./faraday.nix
1718
./btcpayserver.nix
1819
./electrs.nix
1920
./liquid.nix

modules/netns-isolation.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ in {
245245
joinmarket-ob-watcher = {
246246
id = 26;
247247
};
248+
faraday = {
249+
id = 28;
250+
connections = [ "lnd" ];
251+
};
248252
};
249253

250254
services.bitcoind = {

pkgs/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ let self = {
1010
nixops19_09 = pkgs.callPackage ./nixops { };
1111
netns-exec = pkgs.callPackage ./netns-exec { };
1212
lightning-loop = pkgs.callPackage ./lightning-loop { };
13+
faraday = pkgs.callPackage ./faraday { };
1314
extra-container = pkgs.callPackage ./extra-container { };
1415
clightning-plugins = import ./clightning-plugins pkgs self.nbPython3Packages;
1516
clboss = pkgs.callPackage ./clboss { };

pkgs/faraday/default.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{ pkgs, buildGoModule, fetchurl, lib }:
2+
3+
buildGoModule rec {
4+
pname = "faraday";
5+
version = "0.2.3-alpha";
6+
7+
src = fetchurl {
8+
url = "https://github.com/lightninglabs/faraday/archive/v${version}.tar.gz";
9+
# Use ./get-sha256.sh to fetch latest (verified) sha256
10+
sha256 = "c016e2b16160f24abdfce0f71cdb848da3e3d78cff450fb353017d4104bd616e";
11+
};
12+
13+
subPackages = [ "cmd/faraday" "cmd/frcli" ];
14+
15+
vendorSha256 = "1hh99nfprlmhkc36arg3w1kxby59i2l7n258cp40niv7bjn37hrq";
16+
17+
meta = with lib; {
18+
description = " Faraday: Lightning Channel Management & Optimization Tool";
19+
homepage = "https://github.com/lightninglabs/faraday";
20+
license = lib.licenses.mit;
21+
};
22+
}

pkgs/faraday/get-sha256.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#! /usr/bin/env nix-shell
2+
#! nix-shell -i bash -p git gnupg
3+
set -euo pipefail
4+
5+
TMPDIR="$(mktemp -d -p /tmp)"
6+
trap "rm -rf $TMPDIR" EXIT
7+
cd $TMPDIR
8+
9+
echo "Fetching latest release"
10+
git clone https://github.com/lightninglabs/faraday 2> /dev/null
11+
cd faraday
12+
latest=$(git describe --tags `git rev-list --tags --max-count=1`)
13+
echo "Latest release is ${latest}"
14+
15+
16+
# GPG verification
17+
export GNUPGHOME=$TMPDIR
18+
echo "Fetching Calra Kirk Cohen's Key"
19+
gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys 15E7ECF257098A4EF91655EB4CA7FE54A6213C91 2> /dev/null
20+
21+
echo "Verifying latest release"
22+
git verify-tag ${latest}
23+
24+
echo "tag: ${latest}"
25+
# The prefix option is necessary because GitHub prefixes the archive contents in this format
26+
echo "sha256: $(git archive --format tar.gz --prefix=faraday-${latest//v}/ ${latest} | sha256sum | cut -d\ -f1)"

pkgs/pinned.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ in
1313
lnd
1414
nbxplorer
1515
btcpayserver;
16+
inherit (nixBitcoinPkgsUnstable)
17+
electrs
18+
lightning-loop
19+
faraday;
1620

1721
stable = nixBitcoinPkgsStable;
1822
unstable = nixBitcoinPkgsUnstable;

0 commit comments

Comments
 (0)