Skip to content

Commit 7d2c301

Browse files
catwith1hataldoborrero
authored andcommitted
nimbus-validator: Init module.
1 parent c89b698 commit 7d2c301

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

modules/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
./restore
2121
./reth
2222
./nimbus
23+
./nimbus-validator
2324
];
2425
};
2526
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
config,
3+
lib,
4+
pkgs,
5+
...
6+
}: let
7+
inherit
8+
(lib)
9+
mapAttrs'
10+
mkIf
11+
mkMerge
12+
nameValuePair
13+
;
14+
15+
modulesLib = import ../lib.nix lib;
16+
inherit (modulesLib) baseServiceConfig;
17+
18+
eachNimbusValidator = config.services.ethereum.nimbus-validator;
19+
in {
20+
###### interface
21+
inherit (import ./options.nix {inherit lib pkgs;}) options;
22+
23+
###### implementation
24+
25+
config = mkIf (eachNimbusValidator != {}) {
26+
# create a service for each instance
27+
systemd.services =
28+
mapAttrs' (
29+
nimbusValidatorName: let
30+
serviceName = "nimbus-validator-${nimbusValidatorName}";
31+
in
32+
cfg:
33+
nameValuePair serviceName (mkIf cfg.enable {
34+
after = ["network.target"];
35+
wantedBy = ["multi-user.target"];
36+
description = "Nimbus Validator Client (${nimbusValidatorName})";
37+
38+
# create service config by merging with the base config
39+
serviceConfig = mkMerge [
40+
baseServiceConfig
41+
{
42+
User =
43+
if cfg.user != null
44+
then cfg.user
45+
else serviceName;
46+
StateDirectory = serviceName;
47+
ExecStart = "${cfg.package}/bin/nimbus_validator_client ${lib.escapeShellArgs cfg.extraArgs}";
48+
MemoryDenyWriteExecute = "false";
49+
}
50+
];
51+
})
52+
)
53+
eachNimbusValidator;
54+
};
55+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
lib,
3+
pkgs,
4+
...
5+
}: let
6+
nimbusValidatorOpts = with lib; {
7+
options = {
8+
enable = mkEnableOption "Nimbus Validator Client.";
9+
10+
package = mkOption {
11+
type = types.package;
12+
default = pkgs.nimbus;
13+
defaultText = literalExpression "pkgs.nimbus";
14+
description = "Package to use as Nimbus Validator Client.";
15+
};
16+
17+
extraArgs = mkOption {
18+
type = types.listOf types.str;
19+
description = "Additional arguments to pass to Nimbus Validator Client.";
20+
default = [];
21+
};
22+
23+
user = mkOption {
24+
type = types.nullOr types.str;
25+
description = "Service user";
26+
};
27+
};
28+
};
29+
in {
30+
options.services.ethereum.nimbus-validator = with lib;
31+
mkOption {
32+
type = types.attrsOf (types.submodule nimbusValidatorOpts);
33+
default = {};
34+
description = "Specification of one or more Nimbus Validator Client instances.";
35+
};
36+
}

0 commit comments

Comments
 (0)