rtl: add option extraConfig for nodes

Also define rtl config as a Nix attrset that is converted to JSON
This commit is contained in:
Erik Arvstedt 2022-05-14 15:21:37 +02:00
parent ff228a604d
commit 3755b3ebea
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
3 changed files with 72 additions and 52 deletions

View File

@ -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
inherit (nbLib) optionalAttr;
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",
${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://${
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 (node { isLnd = false; index = 1; }) ++
optional cfg.nodes.lnd.enable (node { isLnd = true; index = 2; });
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

View File

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

View File

@ -67,6 +67,7 @@ let
lnd = {
enable = mkDefault true;
loop = mkDefault true;
extraConfig.Settings.userPersona = "MERCHANT";
};
clightning.enable = mkDefault true;
};