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. # Set this to add a clightning node interface.
# Automatically enables clightning. # Automatically enables clightning.
# services.rtl.nodes.clightning = true; # services.rtl.nodes.clightning.enable = true;
# #
# Set this to add a lnd node interface. # Set this to add a lnd node interface.
# Automatically enables lnd. # Automatically enables lnd.
# services.rtl.nodes.lnd = true; # services.rtl.nodes.lnd.enable = true;
# #
# You can enable both nodes simultaneously. # You can enable both nodes simultaneously.
# #
# Set this option to enable swaps with lightning-loop. # Set this option to enable swaps with lightning-loop.
# Automatically enables lightning-loop. # Automatically enables lightning-loop.
# services.rtl.loop = true; # services.rtl.nodes.lnd.loop = true;
### SPARK WALLET ### SPARK WALLET
# Set this to enable spark-wallet, a minimalistic wallet GUI for # Set this to enable spark-wallet, a minimalistic wallet GUI for

View File

@ -283,10 +283,12 @@ in {
}; };
rtl = { rtl = {
id = 29; id = 29;
connections = connections = let
optional config.services.rtl.nodes.lnd "lnd" ++ nodes = config.services.rtl.nodes;
optional config.services.rtl.loop "lightning-loop" ++ in
optional config.services.rtl.nodes.clightning "clightning-rest"; optional nodes.lnd.enable "lnd" ++
optional (nodes.lnd.enable && nodes.lnd.loop) "lightning-loop" ++
optional nodes.clightning.enable "clightning-rest";
}; };
clightning-rest = { clightning-rest = {
id = 30; id = 30;

View File

@ -20,15 +20,24 @@ let
description = "The data directory for RTL."; description = "The data directory for RTL.";
}; };
nodes = { nodes = {
clightning = mkOption { clightning = {
type = types.bool; enable = mkOption {
default = false; type = types.bool;
description = "Enable the clightning node interface."; default = false;
description = "Enable the clightning node interface.";
};
}; };
lnd = mkOption { lnd = {
type = types.bool; enable = mkOption {
default = false; type = types.bool;
description = "Enable the lnd node interface."; default = false;
description = "Enable the lnd node interface.";
};
loop = mkOption {
type = types.bool;
default = false;
description = "Enable swaps with lightning-loop.";
};
}; };
reverseOrder = mkOption { reverseOrder = mkOption {
type = types.bool; 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 { nightTheme = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
@ -84,7 +88,7 @@ let
"lnNode": "Node", "lnNode": "Node",
"lnImplementation": "${if isLnd then "LND" else "CLT"}", "lnImplementation": "${if isLnd then "LND" else "CLT"}",
"Authentication": { "Authentication": {
${optionalString (isLnd && cfg.loop) ${optionalString (isLnd && lndLoopEnabled)
''"swapMacaroonPath": "${lightning-loop.dataDir}/${bitcoind.network}",'' ''"swapMacaroonPath": "${lightning-loop.dataDir}/${bitcoind.network}",''
} }
"macaroonPath": "${if isLnd "macaroonPath": "${if isLnd
@ -104,7 +108,7 @@ let
${optionalString (cfg.extraCurrency != null) ${optionalString (cfg.extraCurrency != null)
''"currencyUnit": "${cfg.extraCurrency}",'' ''"currencyUnit": "${cfg.extraCurrency}",''
} }
${optionalString (isLnd && cfg.loop) ${optionalString (isLnd && lndLoopEnabled)
''"swapServerUrl": "https://${nbLib.addressWithPort lightning-loop.restAddress lightning-loop.restPort}",'' ''"swapServerUrl": "https://${nbLib.addressWithPort lightning-loop.restAddress lightning-loop.restPort}",''
} }
"lnServerUrl": "https://${ "lnServerUrl": "https://${
@ -116,8 +120,8 @@ let
} }
''; '';
nodes' = optional cfg.nodes.clightning (node { isLnd = false; index = 1; }) ++ nodes' = optional cfg.nodes.clightning.enable (node { isLnd = false; index = 1; }) ++
optional cfg.nodes.lnd (node { isLnd = true; index = 2; }); optional cfg.nodes.lnd.enable (node { isLnd = true; index = 2; });
nodes = if cfg.nodes.reverseOrder then reverseList nodes' else nodes'; nodes = if cfg.nodes.reverseOrder then reverseList nodes' else nodes';
@ -140,21 +144,23 @@ let
lnd lnd
clightning-rest clightning-rest
lightning-loop; lightning-loop;
lndLoopEnabled = cfg.nodes.lnd.enable && cfg.nodes.lnd.loop;
in { in {
inherit options; inherit options;
config = mkIf cfg.enable { config = mkIf cfg.enable {
assertions = [ assertions = [
{ assertion = cfg.nodes.clightning || cfg.nodes.lnd; { assertion = cfg.nodes.clightning.enable || cfg.nodes.lnd.enable;
message = '' 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.lnd.enable = mkIf cfg.nodes.lnd.enable true;
services.lightning-loop.enable = mkIf cfg.loop true; services.lightning-loop.enable = mkIf lndLoopEnabled true;
services.clightning-rest.enable = mkIf cfg.nodes.clightning true; services.clightning-rest.enable = mkIf cfg.nodes.clightning.enable true;
systemd.tmpfiles.rules = [ systemd.tmpfiles.rules = [
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -" "d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
@ -164,8 +170,8 @@ in {
systemd.services.rtl = rec { systemd.services.rtl = rec {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
requires = optional cfg.nodes.clightning "clightning-rest.service" ++ requires = optional cfg.nodes.clightning.enable "clightning-rest.service" ++
optional cfg.nodes.lnd "lnd.service"; optional cfg.nodes.lnd.enable "lnd.service";
after = requires; after = requires;
environment.RTL_CONFIG_PATH = cfg.dataDir; environment.RTL_CONFIG_PATH = cfg.dataDir;
serviceConfig = nbLib.defaultHardening // { serviceConfig = nbLib.defaultHardening // {
@ -174,7 +180,7 @@ in {
<${configFile} sed "s|@multiPass@|$(cat ${secretsDir}/rtl-password)|" \ <${configFile} sed "s|@multiPass@|$(cat ${secretsDir}/rtl-password)|" \
> '${cfg.dataDir}/RTL-Config.json' > '${cfg.dataDir}/RTL-Config.json'
'') '')
] ++ optional cfg.nodes.lnd ] ++ optional cfg.nodes.lnd.enable
(nbLib.rootScript "rtl-copy-macaroon" '' (nbLib.rootScript "rtl-copy-macaroon" ''
install -D -o ${cfg.user} -g ${cfg.group} ${lnd.networkDir}/admin.macaroon \ install -D -o ${cfg.user} -g ${cfg.group} ${lnd.networkDir}/admin.macaroon \
'${cfg.dataDir}/macaroons/admin.macaroon' '${cfg.dataDir}/macaroons/admin.macaroon'
@ -195,8 +201,8 @@ in {
group = cfg.group; group = cfg.group;
extraGroups = extraGroups =
# Reads cert and macaroon from the clightning-rest datadir # Reads cert and macaroon from the clightning-rest datadir
optional cfg.nodes.clightning clightning-rest.group ++ optional cfg.nodes.clightning.enable clightning-rest.group ++
optional cfg.loop lnd.group; optional lndLoopEnabled lnd.group;
}; };
users.groups.${cfg.group} = {}; users.groups.${cfg.group} = {};

View File

@ -62,14 +62,20 @@ let
tests.clightning-rest = cfg.clightning-rest.enable; tests.clightning-rest = cfg.clightning-rest.enable;
tests.rtl = cfg.rtl.enable; tests.rtl = cfg.rtl.enable;
services.rtl.nodes.lnd = mkDefault true; services.rtl = {
services.rtl.nodes.clightning = mkDefault true; nodes = {
services.rtl.loop = mkIf cfg.rtl.nodes.lnd (mkDefault true); 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 # Use a simple, non-random password for manual web interface tests
nix-bitcoin.generateSecretsCmds.rtl = mkIf cfg.rtl.enable (mkForce '' nix-bitcoin.generateSecretsCmds.rtl = mkIf cfg.rtl.enable (mkForce ''
echo a > rtl-password echo a > rtl-password
''); '');
services.rtl.extraCurrency = mkDefault "CHF";
tests.spark-wallet = cfg.spark-wallet.enable; tests.spark-wallet = cfg.spark-wallet.enable;