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
This commit is contained in:
Erik Arvstedt 2022-05-14 15:21:36 +02:00
parent beae9f8df7
commit ff228a604d
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
4 changed files with 52 additions and 38 deletions

View File

@ -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

View File

@ -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;

View File

@ -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} = {};

View File

@ -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;