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; default = false;
description = "Enable the clightning node interface."; 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 = { lnd = {
enable = mkOption { enable = mkOption {
@ -38,6 +51,19 @@ let
default = false; default = false;
description = "Enable swaps with lightning-loop."; 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 { reverseOrder = mkOption {
type = types.bool; type = types.bool;
@ -82,62 +108,53 @@ let
nbPkgs = config.nix-bitcoin.pkgs; nbPkgs = config.nix-bitcoin.pkgs;
secretsDir = config.nix-bitcoin.secretsDir; secretsDir = config.nix-bitcoin.secretsDir;
node = { isLnd, index }: '' inherit (nbLib) optionalAttr;
{
"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
}"
}
}
'';
nodes' = optional cfg.nodes.clightning.enable (node { isLnd = false; index = 1; }) ++ node = { isLnd, index }: {
optional cfg.nodes.lnd.enable (node { isLnd = true; index = 2; }); 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'; nodes = if cfg.nodes.reverseOrder then reverseList nodes' else nodes';
configFile = builtins.toFile "config" '' rtlConfig = {
{ multiPass = "@multiPass@";
"multiPass": "@multiPass@", host = cfg.address;
"host": "${cfg.address}", port = cfg.port;
"port": "${toString cfg.port}", SSO.rtlSSO = 0;
"SSO": { inherit nodes;
"rtlSSO": 0 };
},
"nodes": [ configFile = builtins.toFile "config" (builtins.toJSON rtlConfig);
${builtins.concatStringsSep ",\n" nodes}
]
}
'';
inherit (config.services) inherit (config.services)
bitcoind bitcoind

View File

@ -107,4 +107,6 @@ let self = {
addressWithPort = addr: port: "${self.address addr}:${toString port}"; addressWithPort = addr: port: "${self.address addr}:${toString port}";
optionalAttr = cond: name: if cond then name else null;
}; in self }; in self

View File

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