add standalone clightning-rest service
- Rename `services.rtl.cl-rest` to `services.clightning-rest`. `clightning-rest` is generally useful for connecting external REST clients to clightning. - Add a dedicated network namespace in netns-isolation. - Add nodeinfo entry. - Add datadir (which contains REST auth data) to backups.
This commit is contained in:
parent
c30aa33c15
commit
acf5fe69ad
12 changed files with 166 additions and 86 deletions
|
|
@ -70,36 +70,6 @@ let
|
|||
default = cfg.user;
|
||||
description = "The group as which to run RTL.";
|
||||
};
|
||||
cl-rest = {
|
||||
enable = mkOption {
|
||||
readOnly = true;
|
||||
type = types.bool;
|
||||
default = cfg.nodes.clightning;
|
||||
description = ''
|
||||
Enable c-lightning-REST server. This service is required for
|
||||
clightning support and is automatically enabled.
|
||||
'';
|
||||
};
|
||||
address = mkOption {
|
||||
readOnly = true;
|
||||
default = "0.0.0.0";
|
||||
description = ''
|
||||
Rest server address.
|
||||
Not configurable. The server always listens on all interfaces:
|
||||
https://github.com/Ride-The-Lightning/c-lightning-REST/issues/84
|
||||
'';
|
||||
};
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 3001;
|
||||
description = "REST server port.";
|
||||
};
|
||||
docPort = mkOption {
|
||||
type = types.port;
|
||||
default = 4001;
|
||||
description = "Swagger API documentation server port.";
|
||||
};
|
||||
};
|
||||
tor.enforce = nbLib.tor.enforce;
|
||||
};
|
||||
|
||||
|
|
@ -119,7 +89,7 @@ let
|
|||
}
|
||||
"macaroonPath": "${if isLnd
|
||||
then "${cfg.dataDir}/macaroons"
|
||||
else "${cl-rest.dataDir}/certs"
|
||||
else "${clightning-rest.dataDir}/certs"
|
||||
}"
|
||||
},
|
||||
"Settings": {
|
||||
|
|
@ -140,7 +110,7 @@ let
|
|||
"lnServerUrl": "https://${
|
||||
if isLnd
|
||||
then nbLib.addressWithPort lnd.restAddress lnd.restPort
|
||||
else nbLib.addressWithPort cfg.cl-rest.address cfg.cl-rest.port
|
||||
else nbLib.addressWithPort clightning-rest.address clightning-rest.port
|
||||
}"
|
||||
}
|
||||
}
|
||||
|
|
@ -165,25 +135,10 @@ let
|
|||
}
|
||||
'';
|
||||
|
||||
cl-rest = {
|
||||
configFile = builtins.toFile "config" ''
|
||||
{
|
||||
"PORT": ${toString cfg.cl-rest.port},
|
||||
"DOCPORT": ${toString cfg.cl-rest.docPort},
|
||||
"LNRPCPATH": "${clightning.dataDir}/${bitcoind.makeNetworkName "bitcoin" "regtest"}/lightning-rpc",
|
||||
"PROTOCOL": "https",
|
||||
"EXECMODE": "production",
|
||||
"RPCCOMMANDS": ["*"]
|
||||
}
|
||||
'';
|
||||
# serviceConfig.StateDirectory
|
||||
dataDir = "/var/lib/cl-rest";
|
||||
};
|
||||
|
||||
inherit (config.services)
|
||||
bitcoind
|
||||
lnd
|
||||
clightning
|
||||
clightning-rest
|
||||
lightning-loop;
|
||||
in {
|
||||
inherit options;
|
||||
|
|
@ -199,7 +154,7 @@ in {
|
|||
|
||||
services.lnd.enable = mkIf cfg.nodes.lnd true;
|
||||
services.lightning-loop.enable = mkIf cfg.loop true;
|
||||
services.clightning.enable = mkIf cfg.nodes.clightning true;
|
||||
services.clightning-rest.enable = mkIf cfg.nodes.clightning true;
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
|
||||
|
|
@ -209,7 +164,7 @@ in {
|
|||
|
||||
systemd.services.rtl = rec {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requires = optional cfg.nodes.clightning "cl-rest.service" ++
|
||||
requires = optional cfg.nodes.clightning "clightning-rest.service" ++
|
||||
optional cfg.nodes.lnd "lnd.service";
|
||||
after = requires;
|
||||
environment.RTL_CONFIG_PATH = cfg.dataDir;
|
||||
|
|
@ -235,35 +190,12 @@ in {
|
|||
// nbLib.nodejs;
|
||||
};
|
||||
|
||||
systemd.services.cl-rest = mkIf cfg.cl-rest.enable {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requires = [ "clightning.service" ];
|
||||
after = [ "clightning.service" ];
|
||||
path = [ pkgs.openssl ];
|
||||
preStart = ''
|
||||
ln -sfn ${cl-rest.configFile} cl-rest-config.json
|
||||
'';
|
||||
environment.CL_REST_STATE_DIR = cl-rest.dataDir;
|
||||
serviceConfig = nbLib.defaultHardening // {
|
||||
StateDirectory = "cl-rest";
|
||||
# cl-rest reads the config file from the working directory
|
||||
WorkingDirectory = cl-rest.dataDir;
|
||||
ExecStart = "${nbPkgs.clightning-rest}/bin/cl-rest";
|
||||
# Show "cl-rest" instead of "node" in the journal
|
||||
SyslogIdentifier = "cl-rest";
|
||||
User = cfg.user;
|
||||
Restart = "on-failure";
|
||||
RestartSec = "10s";
|
||||
} // nbLib.allowLocalIPAddresses
|
||||
// nbLib.nodejs;
|
||||
};
|
||||
|
||||
users.users.${cfg.user} = {
|
||||
isSystemUser = true;
|
||||
group = cfg.group;
|
||||
extraGroups =
|
||||
# Enable clightning RPC access for cl-rest
|
||||
optional cfg.cl-rest.enable clightning.group ++
|
||||
# Reads cert and macaroon from the clightning-rest datadir
|
||||
optional cfg.nodes.clightning clightning-rest.group ++
|
||||
optional cfg.loop lnd.group;
|
||||
};
|
||||
users.groups.${cfg.group} = {};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue