From 6b3b48cb7cc072c3213b7ef51d126bf84231d6e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rolf=20Schr=C3=B6der?= Date: Tue, 30 Jan 2024 14:52:45 +0100 Subject: [PATCH 1/5] lighthouse: add `package` option to service --- .../services/blockchain/ethereum/lighthouse.nix | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/blockchain/ethereum/lighthouse.nix b/nixos/modules/services/blockchain/ethereum/lighthouse.nix index 863e737d908a..586cde61e50f 100644 --- a/nixos/modules/services/blockchain/ethereum/lighthouse.nix +++ b/nixos/modules/services/blockchain/ethereum/lighthouse.nix @@ -207,12 +207,19 @@ in { default = ""; example = ""; }; + + package = mkOption { + type = types.package; + default = pkgs.lighthouse; + defaultText = literalExpression "pkgs.lighthouse"; + description = lib.mdDoc "The lighthouse package that should be used."; + }; }; }; config = mkIf (cfg.beacon.enable || cfg.validator.enable) { - environment.systemPackages = [ pkgs.lighthouse ] ; + environment.systemPackages = [ cfg.package ] ; networking.firewall = mkIf cfg.beacon.enable { allowedTCPPorts = mkIf cfg.beacon.openFirewall [ cfg.beacon.port ]; @@ -229,7 +236,7 @@ in { # make sure the chain data directory is created on first run mkdir -p ${cfg.beacon.dataDir}/${cfg.network} - ${pkgs.lighthouse}/bin/lighthouse beacon_node \ + ${cfg.package}/bin/lighthouse beacon_node \ --disable-upnp \ ${lib.optionalString cfg.beacon.disableDepositContractSync "--disable-deposit-contract-sync"} \ --port ${toString cfg.beacon.port} \ @@ -277,7 +284,7 @@ in { # make sure the chain data directory is created on first run mkdir -p ${cfg.validator.dataDir}/${cfg.network} - ${pkgs.lighthouse}/bin/lighthouse validator_client \ + ${cfg.package}/bin/lighthouse validator_client \ --network ${cfg.network} \ --beacon-nodes ${lib.concatStringsSep "," cfg.validator.beaconNodes} \ --datadir ${cfg.validator.dataDir}/${cfg.network} \ From c2aa335f5fa5344690256b03be9b6b787cb45cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rolf=20Schr=C3=B6der?= Date: Thu, 31 Oct 2024 06:57:25 +0100 Subject: [PATCH 2/5] nixos/lighthouse: appply nixfmt --- .../blockchain/ethereum/lighthouse.nix | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/nixos/modules/services/blockchain/ethereum/lighthouse.nix b/nixos/modules/services/blockchain/ethereum/lighthouse.nix index 8e0afa7a7ce7..31de6113a5d7 100644 --- a/nixos/modules/services/blockchain/ethereum/lighthouse.nix +++ b/nixos/modules/services/blockchain/ethereum/lighthouse.nix @@ -1,14 +1,18 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: let - cfg = config.services.lighthouse; -in { - +in +{ options = { services.lighthouse = { beacon = lib.mkOption { description = "Beacon node"; - default = {}; + default = { }; type = lib.types.submodule { options = { enable = lib.mkEnableOption "Lightouse Beacon node"; @@ -133,7 +137,7 @@ in { validator = lib.mkOption { description = "Validator node"; - default = {}; + default = { }; type = lib.types.submodule { options = { enable = lib.mkOption { @@ -152,7 +156,7 @@ in { beaconNodes = lib.mkOption { type = lib.types.listOf lib.types.str; - default = ["http://localhost:5052"]; + default = [ "http://localhost:5052" ]; description = '' Beacon nodes to connect to. ''; @@ -190,7 +194,13 @@ in { }; network = lib.mkOption { - type = lib.types.enum [ "mainnet" "gnosis" "chiado" "sepolia" "holesky" ]; + type = lib.types.enum [ + "mainnet" + "gnosis" + "chiado" + "sepolia" + "holesky" + ]; default = "mainnet"; description = '' The network to connect to. Mainnet is the default ethereum network. @@ -216,15 +226,13 @@ in { }; config = lib.mkIf (cfg.beacon.enable || cfg.validator.enable) { - - environment.systemPackages = [ cfg.package ] ; + environment.systemPackages = [ cfg.package ]; 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 ]; }; - systemd.services.lighthouse-beacon = lib.mkIf cfg.beacon.enable { description = "Lighthouse beacon node (connect to P2P nodes and verify blocks)"; wantedBy = [ "multi-user.target" ]; @@ -243,8 +251,8 @@ in { --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}''} \ + ${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 = { @@ -269,7 +277,10 @@ in { RestrictNamespaces = true; LockPersonality = true; RemoveIPC = true; - SystemCallFilter = [ "@system-service" "~@privileged" ]; + SystemCallFilter = [ + "@system-service" + "~@privileged" + ]; }; }; @@ -312,8 +323,14 @@ in { RestrictNamespaces = true; LockPersonality = true; RemoveIPC = true; - RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ]; - SystemCallFilter = [ "@system-service" "~@privileged" ]; + RestrictAddressFamilies = [ + "AF_INET" + "AF_INET6" + ]; + SystemCallFilter = [ + "@system-service" + "~@privileged" + ]; }; }; }; From b6a0bf0b6259843f43cd8019546cb0d5e7dfffe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rolf=20Schr=C3=B6der?= Date: Thu, 31 Oct 2024 06:57:51 +0100 Subject: [PATCH 3/5] nixos/lighthouse: use mkPackageOption --- nixos/modules/services/blockchain/ethereum/lighthouse.nix | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/nixos/modules/services/blockchain/ethereum/lighthouse.nix b/nixos/modules/services/blockchain/ethereum/lighthouse.nix index 31de6113a5d7..7fa36bc659e8 100644 --- a/nixos/modules/services/blockchain/ethereum/lighthouse.nix +++ b/nixos/modules/services/blockchain/ethereum/lighthouse.nix @@ -216,12 +216,7 @@ in example = ""; }; - package = mkOption { - type = types.package; - default = pkgs.lighthouse; - defaultText = literalExpression "pkgs.lighthouse"; - description = lib.mdDoc "The lighthouse package that should be used."; - }; + package = lib.mkPackageOption pkgs "lighthouse" { }; }; }; From 498a3fb8740db1089e1c30ef5e31f5e2485c89d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rolf=20Schr=C3=B6der?= Date: Thu, 31 Oct 2024 06:58:10 +0100 Subject: [PATCH 4/5] nixos/lighthouse: use lib.getExe --- nixos/modules/services/blockchain/ethereum/lighthouse.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/blockchain/ethereum/lighthouse.nix b/nixos/modules/services/blockchain/ethereum/lighthouse.nix index 7fa36bc659e8..c7c7b75db62c 100644 --- a/nixos/modules/services/blockchain/ethereum/lighthouse.nix +++ b/nixos/modules/services/blockchain/ethereum/lighthouse.nix @@ -237,7 +237,7 @@ in # make sure the chain data directory is created on first run mkdir -p ${cfg.beacon.dataDir}/${cfg.network} - ${cfg.package}/bin/lighthouse beacon_node \ + ${lib.getExe cfg.package} beacon_node \ --disable-upnp \ ${lib.optionalString cfg.beacon.disableDepositContractSync "--disable-deposit-contract-sync"} \ --port ${toString cfg.beacon.port} \ From 6b5d6b760e8ffa11cacc26c00a18acb89059b067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rolf=20Schr=C3=B6der?= Date: Thu, 31 Oct 2024 07:00:37 +0100 Subject: [PATCH 5/5] nixos/lighthouse: use lib.getExe (validator_client) --- nixos/modules/services/blockchain/ethereum/lighthouse.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/blockchain/ethereum/lighthouse.nix b/nixos/modules/services/blockchain/ethereum/lighthouse.nix index c7c7b75db62c..247174028adc 100644 --- a/nixos/modules/services/blockchain/ethereum/lighthouse.nix +++ b/nixos/modules/services/blockchain/ethereum/lighthouse.nix @@ -288,7 +288,7 @@ in # make sure the chain data directory is created on first run mkdir -p ${cfg.validator.dataDir}/${cfg.network} - ${cfg.package}/bin/lighthouse validator_client \ + ${lib.getExe cfg.package} validator_client \ --network ${cfg.network} \ --beacon-nodes ${lib.concatStringsSep "," cfg.validator.beaconNodes} \ --datadir ${cfg.validator.dataDir}/${cfg.network} \