From 4c2d908a38539b0fe2bfc7520fbec0afe588c267 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Sat, 14 May 2022 15:21:34 +0200 Subject: [PATCH 1/4] rtl: 0.12.2-beta -> 0.12.3-beta --- pkgs/rtl/generate.sh | 2 +- pkgs/rtl/node-packages.nix | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkgs/rtl/generate.sh b/pkgs/rtl/generate.sh index 239a5a8..0ffbd1a 100755 --- a/pkgs/rtl/generate.sh +++ b/pkgs/rtl/generate.sh @@ -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 diff --git a/pkgs/rtl/node-packages.nix b/pkgs/rtl/node-packages.nix index f58dce7..9ee4017 100644 --- a/pkgs/rtl/node-packages.nix +++ b/pkgs/rtl/node-packages.nix @@ -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" = { @@ -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" @@ -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" From beae9f8df7dd727d05be98311d03c84689679611 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Sat, 14 May 2022 15:21:35 +0200 Subject: [PATCH 2/4] clightning-rest: 0.7.0 -> 0.7.2 --- pkgs/clightning-rest/generate.sh | 2 +- pkgs/clightning-rest/node-packages.nix | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkgs/clightning-rest/generate.sh b/pkgs/clightning-rest/generate.sh index 8d58c75..4537f44 100755 --- a/pkgs/clightning-rest/generate.sh +++ b/pkgs/clightning-rest/generate.sh @@ -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 diff --git a/pkgs/clightning-rest/node-packages.nix b/pkgs/clightning-rest/node-packages.nix index 0239111..09bb36c 100644 --- a/pkgs/clightning-rest/node-packages.nix +++ b/pkgs/clightning-rest/node-packages.nix @@ -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" = { @@ -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" @@ -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" From ff228a604d6265f7ecc4eea1b8e468b502647861 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Sat, 14 May 2022 15:21:36 +0200 Subject: [PATCH 3/4] rtl: change `nodes` options - Move option `rtl.nodes.{lnd,clightning}` -> `rtl.nodes.{lnd,clightning}.enable` This is required by the next commit. - Move option `rtl.loop` -> `rtl.nodes.lnd.loop` - Only enable loop when `nodes.lnd` is enabled --- examples/configuration.nix | 6 ++-- modules/netns-isolation.nix | 10 ++++--- modules/rtl.nix | 60 ++++++++++++++++++++----------------- test/tests.nix | 14 ++++++--- 4 files changed, 52 insertions(+), 38 deletions(-) diff --git a/examples/configuration.nix b/examples/configuration.nix index bc1c990..535a967 100644 --- a/examples/configuration.nix +++ b/examples/configuration.nix @@ -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 diff --git a/modules/netns-isolation.nix b/modules/netns-isolation.nix index 8159481..97b32d0 100644 --- a/modules/netns-isolation.nix +++ b/modules/netns-isolation.nix @@ -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; diff --git a/modules/rtl.nix b/modules/rtl.nix index 8dbab0c..49c8dc2 100644 --- a/modules/rtl.nix +++ b/modules/rtl.nix @@ -20,15 +20,24 @@ 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."; + }; }; - 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."; + }; }; reverseOrder = mkOption { type = types.bool; @@ -39,11 +48,6 @@ let ''; }; }; - loop = mkOption { - type = types.bool; - default = false; - description = "Whether to enable swaps with lightning-loop."; - }; nightTheme = mkOption { type = types.bool; default = false; @@ -84,7 +88,7 @@ let "lnNode": "Node", "lnImplementation": "${if isLnd then "LND" else "CLT"}", "Authentication": { - ${optionalString (isLnd && cfg.loop) + ${optionalString (isLnd && lndLoopEnabled) ''"swapMacaroonPath": "${lightning-loop.dataDir}/${bitcoind.network}",'' } "macaroonPath": "${if isLnd @@ -104,7 +108,7 @@ let ${optionalString (cfg.extraCurrency != null) ''"currencyUnit": "${cfg.extraCurrency}",'' } - ${optionalString (isLnd && cfg.loop) + ${optionalString (isLnd && lndLoopEnabled) ''"swapServerUrl": "https://${nbLib.addressWithPort lightning-loop.restAddress lightning-loop.restPort}",'' } "lnServerUrl": "https://${ @@ -116,8 +120,8 @@ let } ''; - nodes' = optional cfg.nodes.clightning (node { isLnd = false; index = 1; }) ++ - optional cfg.nodes.lnd (node { isLnd = true; index = 2; }); + nodes' = optional cfg.nodes.clightning.enable (node { isLnd = false; index = 1; }) ++ + optional cfg.nodes.lnd.enable (node { isLnd = true; index = 2; }); nodes = if cfg.nodes.reverseOrder then reverseList nodes' else nodes'; @@ -140,21 +144,23 @@ let 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} - -" @@ -164,8 +170,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 // { @@ -174,7 +180,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' @@ -195,8 +201,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} = {}; diff --git a/test/tests.nix b/test/tests.nix index dceb56d..be0852d 100644 --- a/test/tests.nix +++ b/test/tests.nix @@ -62,14 +62,20 @@ let tests.clightning-rest = cfg.clightning-rest.enable; tests.rtl = cfg.rtl.enable; - services.rtl.nodes.lnd = mkDefault true; - services.rtl.nodes.clightning = mkDefault true; - services.rtl.loop = mkIf cfg.rtl.nodes.lnd (mkDefault true); + services.rtl = { + nodes = { + lnd = { + enable = mkDefault true; + loop = mkDefault true; + }; + clightning.enable = mkDefault true; + }; + extraCurrency = mkDefault "CHF"; + }; # Use a simple, non-random password for manual web interface tests nix-bitcoin.generateSecretsCmds.rtl = mkIf cfg.rtl.enable (mkForce '' echo a > rtl-password ''); - services.rtl.extraCurrency = mkDefault "CHF"; tests.spark-wallet = cfg.spark-wallet.enable; From 3755b3ebea57e0cadd941d39e40002186159e769 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Sat, 14 May 2022 15:21:37 +0200 Subject: [PATCH 4/4] rtl: add option `extraConfig` for nodes Also define rtl config as a Nix attrset that is converted to JSON --- modules/rtl.nix | 121 +++++++++++++++++++++++++++--------------------- pkgs/lib.nix | 2 + test/tests.nix | 1 + 3 files changed, 72 insertions(+), 52 deletions(-) diff --git a/modules/rtl.nix b/modules/rtl.nix index 49c8dc2..33a3e06 100644 --- a/modules/rtl.nix +++ b/modules/rtl.nix @@ -26,6 +26,19 @@ let 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 = { enable = mkOption { @@ -38,6 +51,19 @@ let 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; @@ -82,62 +108,53 @@ 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 && 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", - ${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 && 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 - }" - } - } - ''; + inherit (nbLib) optionalAttr; - nodes' = optional cfg.nodes.clightning.enable (node { isLnd = false; index = 1; }) ++ - optional cfg.nodes.lnd.enable (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 diff --git a/pkgs/lib.nix b/pkgs/lib.nix index 6b058fd..ff4d44f 100644 --- a/pkgs/lib.nix +++ b/pkgs/lib.nix @@ -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 diff --git a/test/tests.nix b/test/tests.nix index be0852d..7f3e420 100644 --- a/test/tests.nix +++ b/test/tests.nix @@ -67,6 +67,7 @@ let lnd = { enable = mkDefault true; loop = mkDefault true; + extraConfig.Settings.userPersona = "MERCHANT"; }; clightning.enable = mkDefault true; };