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

Update RTL #484

Merged
merged 4 commits into from
May 25, 2022
Merged
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
6 changes: 3 additions & 3 deletions examples/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@
#
# Set this to add a clightning node interface.
# Automatically enables clightning.
# services.rtl.nodes.clightning = true;
# services.rtl.nodes.clightning.enable = true;
#
# Set this to add a lnd node interface.
# Automatically enables lnd.
# services.rtl.nodes.lnd = true;
# services.rtl.nodes.lnd.enable = true;
#
# You can enable both nodes simultaneously.
#
# Set this option to enable swaps with lightning-loop.
# Automatically enables lightning-loop.
# services.rtl.loop = true;
# services.rtl.nodes.lnd.loop = true;

### SPARK WALLET
# Set this to enable spark-wallet, a minimalistic wallet GUI for
Expand Down
10 changes: 6 additions & 4 deletions modules/netns-isolation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,12 @@ in {
};
rtl = {
id = 29;
connections =
optional config.services.rtl.nodes.lnd "lnd" ++
optional config.services.rtl.loop "lightning-loop" ++
optional config.services.rtl.nodes.clightning "clightning-rest";
connections = let
nodes = config.services.rtl.nodes;
in
optional nodes.lnd.enable "lnd" ++
optional (nodes.lnd.enable && nodes.lnd.loop) "lightning-loop" ++
optional nodes.clightning.enable "clightning-rest";
};
clightning-rest = {
id = 30;
Expand Down
173 changes: 98 additions & 75 deletions modules/rtl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,50 @@ let
description = "The data directory for RTL.";
};
nodes = {
clightning = mkOption {
type = types.bool;
default = false;
description = "Enable the clightning node interface.";
clightning = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable the clightning node interface.";
};
extraConfig = mkOption {
type = types.attrs;
default = {};
example = {
Settings.userPersona = "MERCHANT";
Settings.logLevel = "DEBUG";
};
description = ''
Extra clightning node configuration.
See here for all available options:
https://github.com/Ride-The-Lightning/RTL/blob/master/.github/docs/Application_configurations.md
'';
};
};
lnd = mkOption {
type = types.bool;
default = false;
description = "Enable the lnd node interface.";
lnd = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable the lnd node interface.";
};
loop = mkOption {
type = types.bool;
default = false;
description = "Enable swaps with lightning-loop.";
};
extraConfig = mkOption {
type = types.attrs;
default = {};
example = {
Settings.userPersona = "MERCHANT";
Settings.logLevel = "DEBUG";
};
description = ''
Extra lnd node configuration.
See here for all available options:
https://github.com/Ride-The-Lightning/RTL/blob/master/.github/docs/Application_configurations.md
'';
};
};
reverseOrder = mkOption {
type = types.bool;
Expand All @@ -39,11 +74,6 @@ let
'';
};
};
loop = mkOption {
type = types.bool;
default = false;
description = "Whether to enable swaps with lightning-loop.";
};
nightTheme = mkOption {
type = types.bool;
default = false;
Expand Down Expand Up @@ -78,83 +108,76 @@ let
nbPkgs = config.nix-bitcoin.pkgs;
secretsDir = config.nix-bitcoin.secretsDir;

node = { isLnd, index }: ''
{
"index": ${toString index},
"lnNode": "Node",
"lnImplementation": "${if isLnd then "LND" else "CLT"}",
"Authentication": {
${optionalString (isLnd && cfg.loop)
''"swapMacaroonPath": "${lightning-loop.dataDir}/${bitcoind.network}",''
}
"macaroonPath": "${if isLnd
then "${cfg.dataDir}/macaroons"
else "${clightning-rest.dataDir}/certs"
}"
},
"Settings": {
"userPersona": "OPERATOR",
"themeMode": "${if cfg.nightTheme then "NIGHT" else "DAY"}",
"themeColor": "PURPLE",
${optionalString isLnd
''"channelBackupPath": "${cfg.dataDir}/backup/lnd",''
}
"logLevel": "INFO",
"fiatConversion": ${if cfg.extraCurrency == null then "false" else "true"},
${optionalString (cfg.extraCurrency != null)
''"currencyUnit": "${cfg.extraCurrency}",''
}
${optionalString (isLnd && cfg.loop)
''"swapServerUrl": "https://${nbLib.addressWithPort lightning-loop.restAddress lightning-loop.restPort}",''
}
"lnServerUrl": "https://${
if isLnd
then nbLib.addressWithPort lnd.restAddress lnd.restPort
else nbLib.addressWithPort clightning-rest.address clightning-rest.port
}"
}
}
'';
inherit (nbLib) optionalAttr;

nodes' = optional cfg.nodes.clightning (node { isLnd = false; index = 1; }) ++
optional cfg.nodes.lnd (node { isLnd = true; index = 2; });
node = { isLnd, index }: {
inherit index;
lnNode = "Node";
lnImplementation = if isLnd then "LND" else "CLT";
Authentication = {
${optionalAttr (isLnd && lndLoopEnabled) "swapMacaroonPath"} = "${lightning-loop.dataDir}/${bitcoind.network}";
macaroonPath = if isLnd
then "${cfg.dataDir}/macaroons"
else "${clightning-rest.dataDir}/certs";
};
Settings = {
userPersona = "OPERATOR";
themeMode = if cfg.nightTheme then "NIGHT" else "DAY";
themeColor = "PURPLE";
${optionalAttr isLnd "channelBackupPath"} = "${cfg.dataDir}/backup/lnd";
logLevel = "INFO";
fiatConversion = cfg.extraCurrency != null;
${optionalAttr (cfg.extraCurrency != null) "currencyUnit"} = cfg.extraCurrency;
${optionalAttr (isLnd && lndLoopEnabled) "swapServerUrl"} =
"https://${nbLib.addressWithPort lightning-loop.restAddress lightning-loop.restPort}";
lnServerUrl = "https://${
if isLnd
then nbLib.addressWithPort lnd.restAddress lnd.restPort
else nbLib.addressWithPort clightning-rest.address clightning-rest.port
}";
};
};

nodes' =
optional cfg.nodes.clightning.enable
(recursiveUpdate (node { isLnd = false; index = 1; }) cfg.nodes.clightning.extraConfig) ++
optional cfg.nodes.lnd.enable
(recursiveUpdate (node { isLnd = true; index = 2; }) cfg.nodes.lnd.extraConfig);

nodes = if cfg.nodes.reverseOrder then reverseList nodes' else nodes';

configFile = builtins.toFile "config" ''
{
"multiPass": "@multiPass@",
"host": "${cfg.address}",
"port": "${toString cfg.port}",
"SSO": {
"rtlSSO": 0
},
"nodes": [
${builtins.concatStringsSep ",\n" nodes}
]
}
'';
rtlConfig = {
multiPass = "@multiPass@";
host = cfg.address;
port = cfg.port;
SSO.rtlSSO = 0;
inherit nodes;
};

configFile = builtins.toFile "config" (builtins.toJSON rtlConfig);

inherit (config.services)
bitcoind
lnd
clightning-rest
lightning-loop;

lndLoopEnabled = cfg.nodes.lnd.enable && cfg.nodes.lnd.loop;
in {
inherit options;

config = mkIf cfg.enable {
assertions = [
{ assertion = cfg.nodes.clightning || cfg.nodes.lnd;
{ assertion = cfg.nodes.clightning.enable || cfg.nodes.lnd.enable;
message = ''
RTL: At least one of `nodes.lnd` or `nodes.clightning` must be `true`.
RTL: At least one of `nodes.lnd.enable` or `nodes.clightning.enable` must be `true`.
'';
}
];

services.lnd.enable = mkIf cfg.nodes.lnd true;
services.lightning-loop.enable = mkIf cfg.loop true;
services.clightning-rest.enable = mkIf cfg.nodes.clightning true;
services.lnd.enable = mkIf cfg.nodes.lnd.enable true;
services.lightning-loop.enable = mkIf lndLoopEnabled true;
services.clightning-rest.enable = mkIf cfg.nodes.clightning.enable true;

systemd.tmpfiles.rules = [
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
Expand All @@ -164,8 +187,8 @@ in {

systemd.services.rtl = rec {
wantedBy = [ "multi-user.target" ];
requires = optional cfg.nodes.clightning "clightning-rest.service" ++
optional cfg.nodes.lnd "lnd.service";
requires = optional cfg.nodes.clightning.enable "clightning-rest.service" ++
optional cfg.nodes.lnd.enable "lnd.service";
after = requires;
environment.RTL_CONFIG_PATH = cfg.dataDir;
serviceConfig = nbLib.defaultHardening // {
Expand All @@ -174,7 +197,7 @@ in {
<${configFile} sed "s|@multiPass@|$(cat ${secretsDir}/rtl-password)|" \
> '${cfg.dataDir}/RTL-Config.json'
'')
] ++ optional cfg.nodes.lnd
] ++ optional cfg.nodes.lnd.enable
(nbLib.rootScript "rtl-copy-macaroon" ''
install -D -o ${cfg.user} -g ${cfg.group} ${lnd.networkDir}/admin.macaroon \
'${cfg.dataDir}/macaroons/admin.macaroon'
Expand All @@ -195,8 +218,8 @@ in {
group = cfg.group;
extraGroups =
# Reads cert and macaroon from the clightning-rest datadir
optional cfg.nodes.clightning clightning-rest.group ++
optional cfg.loop lnd.group;
optional cfg.nodes.clightning.enable clightning-rest.group ++
optional lndLoopEnabled lnd.group;
};
users.groups.${cfg.group} = {};

Expand Down
2 changes: 1 addition & 1 deletion pkgs/clightning-rest/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
TMPDIR="$(mktemp -d -p /tmp)"
trap "rm -rf $TMPDIR" EXIT

version="0.7.0"
version="0.7.2"
repo=https://github.com/Ride-The-Lightning/c-lightning-REST

# Fetch and verify source tarball
Expand Down
16 changes: 8 additions & 8 deletions pkgs/clightning-rest/node-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ let
sha1 = "1b681c21ff84033c826543090689420d187151dc";
};
};
"clightningjs-0.1.1" = {
"clightningjs-0.2.2" = {
name = "clightningjs";
packageName = "clightningjs";
version = "0.1.1";
version = "0.2.2";
src = fetchurl {
url = "https://registry.npmjs.org/clightningjs/-/clightningjs-0.1.1.tgz";
sha512 = "r/poNODgYDJQZVU1X3lMirDCOD2Bw9XyPdjRXcOXAnHtSihf4OnO1c7iB82ots+2aExQnKuBk9JOE3QwY6FHOw==";
url = "https://registry.npmjs.org/clightningjs/-/clightningjs-0.2.2.tgz";
sha512 = "9fdWYNxe/IUe0uG0b1XdxWGlev1IPlWZpN6Hrsr3uTOZe1kSR+ySBMzdsgD73Rc3LeX7DfdKhT3uuT8B77HIqg==";
};
};
"combined-stream-1.0.8" = {
Expand Down Expand Up @@ -1277,10 +1277,10 @@ let
args = {
name = "c-lightning-rest";
packageName = "c-lightning-rest";
version = "0.7.0";
version = "0.7.2";
src = fetchurl {
url = "https://github.com/Ride-The-Lightning/c-lightning-REST/archive/refs/tags/v0.7.0.tar.gz";
hash = "sha256-NeeG4WyXWPZv5u5HuMwVhIgDgHStgah3YNtk4bKvNoY=";
url = "https://github.com/Ride-The-Lightning/c-lightning-REST/archive/refs/tags/v0.7.2.tar.gz";
hash = "sha256-G3PWoOW69B+so7sDiAcZNgaAWtmp/H5U9I6vh5YeUEQ=";
};
dependencies = [
sources."accepts-1.3.7"
Expand All @@ -1300,7 +1300,7 @@ let
sources."bytes-3.1.0"
sources."call-me-maybe-1.0.1"
sources."caseless-0.12.0"
sources."clightningjs-0.1.1"
sources."clightningjs-0.2.2"
sources."combined-stream-1.0.8"
sources."commander-2.20.0"
sources."concat-map-0.0.1"
Expand Down
2 changes: 2 additions & 0 deletions pkgs/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,6 @@ let self = {

addressWithPort = addr: port: "${self.address addr}:${toString port}";

optionalAttr = cond: name: if cond then name else null;

}; in self
2 changes: 1 addition & 1 deletion pkgs/rtl/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
TMPDIR="$(mktemp -d -p /tmp)"
trap "rm -rf $TMPDIR" EXIT

version="0.12.2"
version="0.12.3"
repo=https://github.com/Ride-The-Lightning/RTL

# Fetch and verify source tarball
Expand Down
16 changes: 8 additions & 8 deletions pkgs/rtl/node-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2389,13 +2389,13 @@ let
sha512 = "6cP692WwGIs9XXdOO4++N+7qjqv0rqxxVvJ3VHPh/Sc9mVZcQP+ZGhkKiTvWMQRr2tbHkJP/Yn7Y0npb3ZBs4A==";
};
};
"minimist-1.2.5" = {
"minimist-1.2.6" = {
name = "minimist";
packageName = "minimist";
version = "1.2.5";
version = "1.2.6";
src = fetchurl {
url = "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz";
sha512 = "FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==";
url = "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz";
sha512 = "Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==";
};
};
"ms-2.0.0" = {
Expand Down Expand Up @@ -3590,10 +3590,10 @@ let
args = {
name = "rtl";
packageName = "rtl";
version = "0.12.2-beta";
version = "0.12.3-beta";
src = fetchurl {
url = "https://github.com/Ride-The-Lightning/RTL/archive/refs/tags/v0.12.2.tar.gz";
hash = "sha256-xvW6zq/mBsuRy8AwoAPJ2RR7iqhKrC57SVWyFTjq6aw=";
url = "https://github.com/Ride-The-Lightning/RTL/archive/refs/tags/v0.12.3.tar.gz";
hash = "sha256-2X5Bf9rniiN/NNEqnNJYF/YQ0v+EwnwQHB5VXVfS9to=";
};
dependencies = [
sources."@angular/animations-13.0.3"
Expand Down Expand Up @@ -3943,7 +3943,7 @@ let
sources."methods-1.1.2"
sources."mime-db-1.51.0"
sources."mime-types-2.1.34"
sources."minimist-1.2.5"
sources."minimist-1.2.6"
sources."ms-2.1.2"
sources."negotiator-0.6.2"
sources."next-tick-1.0.0"
Expand Down
Loading