2022-11-21 17:40:18 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.lighthouse;
|
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.lighthouse = {
|
2024-09-19 14:19:46 +00:00
|
|
|
beacon = lib.mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Beacon node";
|
2022-11-21 17:40:18 +00:00
|
|
|
default = {};
|
2024-09-19 14:19:46 +00:00
|
|
|
type = lib.types.submodule {
|
2022-11-21 17:40:18 +00:00
|
|
|
options = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = lib.mkEnableOption "Lightouse Beacon node";
|
2022-11-21 17:40:18 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
dataDir = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = "/var/lib/lighthouse-beacon";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Directory where data will be stored. Each chain will be stored under it's own specific subdirectory.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
address = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = "0.0.0.0";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Listen address of Beacon node.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
port = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = 9000;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Port number the Beacon node will be listening on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
openFirewall = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Open the port in the firewall
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
disableDepositContractSync = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-12-28 21:21:41 +00:00
|
|
|
Explicitly disables syncing of deposit logs from the execution node.
|
2022-11-21 17:40:18 +00:00
|
|
|
This overrides any previous option that depends on it.
|
|
|
|
Useful if you intend to run a non-validating beacon node.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
execution = {
|
2024-09-19 14:19:46 +00:00
|
|
|
address = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = "127.0.0.1";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Listen address for the execution layer.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
port = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = 8551;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Port number the Beacon node will be listening on for the execution layer.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
jwtPath = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Path for the jwt secret required to connect to the execution layer.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
http = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = lib.mkEnableOption "Beacon node http api";
|
2024-09-19 14:19:46 +00:00
|
|
|
port = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = 5052;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Port number of Beacon node RPC service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
address = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = "127.0.0.1";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Listen address of Beacon node RPC service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
metrics = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = lib.mkEnableOption "Beacon node prometheus metrics";
|
2024-09-19 14:19:46 +00:00
|
|
|
address = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = "127.0.0.1";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Listen address of Beacon node metrics service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
port = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = 5054;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Port number of Beacon node metrics service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Additional arguments passed to the lighthouse beacon command.
|
|
|
|
'';
|
|
|
|
default = "";
|
|
|
|
example = "";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
validator = lib.mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Validator node";
|
2022-11-21 17:40:18 +00:00
|
|
|
default = {};
|
2024-09-19 14:19:46 +00:00
|
|
|
type = lib.types.submodule {
|
2022-11-21 17:40:18 +00:00
|
|
|
options = {
|
2024-09-19 14:19:46 +00:00
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Enable Lightouse Validator node.";
|
2022-11-21 17:40:18 +00:00
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
dataDir = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = "/var/lib/lighthouse-validator";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Directory where data will be stored. Each chain will be stored under it's own specific subdirectory.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
beaconNodes = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = ["http://localhost:5052"];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Beacon nodes to connect to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
metrics = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = lib.mkEnableOption "Validator node prometheus metrics";
|
2024-09-19 14:19:46 +00:00
|
|
|
address = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = "127.0.0.1";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Listen address of Validator node metrics service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
port = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
2022-11-21 17:40:18 +00:00
|
|
|
default = 5056;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Port number of Validator node metrics service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Additional arguments passed to the lighthouse validator command.
|
|
|
|
'';
|
|
|
|
default = "";
|
|
|
|
example = "";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
network = lib.mkOption {
|
|
|
|
type = lib.types.enum [ "mainnet" "gnosis" "chiado" "sepolia" "holesky" ];
|
2022-11-21 17:40:18 +00:00
|
|
|
default = "mainnet";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
The network to connect to. Mainnet is the default ethereum network.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
Additional arguments passed to every lighthouse command.
|
|
|
|
'';
|
|
|
|
default = "";
|
|
|
|
example = "";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
config = lib.mkIf (cfg.beacon.enable || cfg.validator.enable) {
|
2022-11-21 17:40:18 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.lighthouse ] ;
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
networking.firewall = lib.mkIf cfg.beacon.enable {
|
|
|
|
allowedTCPPorts = lib.mkIf cfg.beacon.openFirewall [ cfg.beacon.port ];
|
|
|
|
allowedUDPPorts = lib.mkIf cfg.beacon.openFirewall [ cfg.beacon.port ];
|
2022-11-21 17:40:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
systemd.services.lighthouse-beacon = lib.mkIf cfg.beacon.enable {
|
2022-11-21 17:40:18 +00:00
|
|
|
description = "Lighthouse beacon node (connect to P2P nodes and verify blocks)";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
# make sure the chain data directory is created on first run
|
|
|
|
mkdir -p ${cfg.beacon.dataDir}/${cfg.network}
|
|
|
|
|
|
|
|
${pkgs.lighthouse}/bin/lighthouse beacon_node \
|
|
|
|
--disable-upnp \
|
|
|
|
${lib.optionalString cfg.beacon.disableDepositContractSync "--disable-deposit-contract-sync"} \
|
|
|
|
--port ${toString cfg.beacon.port} \
|
|
|
|
--listen-address ${cfg.beacon.address} \
|
|
|
|
--network ${cfg.network} \
|
|
|
|
--datadir ${cfg.beacon.dataDir}/${cfg.network} \
|
|
|
|
--execution-endpoint http://${cfg.beacon.execution.address}:${toString cfg.beacon.execution.port} \
|
|
|
|
--execution-jwt ''${CREDENTIALS_DIRECTORY}/LIGHTHOUSE_JWT \
|
|
|
|
${lib.optionalString cfg.beacon.http.enable '' --http --http-address ${cfg.beacon.http.address} --http-port ${toString cfg.beacon.http.port}''} \
|
|
|
|
${lib.optionalString cfg.beacon.metrics.enable '' --metrics --metrics-address ${cfg.beacon.metrics.address} --metrics-port ${toString cfg.beacon.metrics.port}''} \
|
|
|
|
${cfg.extraArgs} ${cfg.beacon.extraArgs}
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
LoadCredential = "LIGHTHOUSE_JWT:${cfg.beacon.execution.jwtPath}";
|
|
|
|
DynamicUser = true;
|
|
|
|
Restart = "on-failure";
|
|
|
|
StateDirectory = "lighthouse-beacon";
|
2022-11-27 09:42:12 +00:00
|
|
|
ReadWritePaths = [ cfg.beacon.dataDir ];
|
2022-11-21 17:40:18 +00:00
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectProc = "noaccess";
|
|
|
|
ProcSubset = "pid";
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
LockPersonality = true;
|
|
|
|
RemoveIPC = true;
|
|
|
|
SystemCallFilter = [ "@system-service" "~@privileged" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
systemd.services.lighthouse-validator = lib.mkIf cfg.validator.enable {
|
2022-11-21 17:40:18 +00:00
|
|
|
description = "Lighthouse validtor node (manages validators, using data obtained from the beacon node via a HTTP API)";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
# make sure the chain data directory is created on first run
|
|
|
|
mkdir -p ${cfg.validator.dataDir}/${cfg.network}
|
|
|
|
|
|
|
|
${pkgs.lighthouse}/bin/lighthouse validator_client \
|
|
|
|
--network ${cfg.network} \
|
|
|
|
--beacon-nodes ${lib.concatStringsSep "," cfg.validator.beaconNodes} \
|
2022-12-28 21:21:41 +00:00
|
|
|
--datadir ${cfg.validator.dataDir}/${cfg.network} \
|
2024-09-19 14:19:46 +00:00
|
|
|
${lib.optionalString cfg.validator.metrics.enable ''--metrics --metrics-address ${cfg.validator.metrics.address} --metrics-port ${toString cfg.validator.metrics.port}''} \
|
2022-11-21 17:40:18 +00:00
|
|
|
${cfg.extraArgs} ${cfg.validator.extraArgs}
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = "on-failure";
|
|
|
|
StateDirectory = "lighthouse-validator";
|
2022-11-27 09:42:12 +00:00
|
|
|
ReadWritePaths = [ cfg.validator.dataDir ];
|
2022-11-21 17:40:18 +00:00
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
DynamicUser = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectProc = "noaccess";
|
|
|
|
ProcSubset = "pid";
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
LockPersonality = true;
|
|
|
|
RemoveIPC = true;
|
|
|
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
|
|
|
|
SystemCallFilter = [ "@system-service" "~@privileged" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|