Skip to content

Commit c89b698

Browse files
catwith1hataldoborrero
authored andcommitted
nimbus: Init module.
1 parent af7f825 commit c89b698

File tree

4 files changed

+142
-0
lines changed

4 files changed

+142
-0
lines changed

modules/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
./prysm-validator
2020
./restore
2121
./reth
22+
./nimbus
2223
];
2324
};
2425
}

modules/nimbus/args.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
lib:
2+
with lib; {
3+
port = mkOption {
4+
type = types.int;
5+
description = "Port to open";
6+
};
7+
network = mkOption {
8+
type = types.str;
9+
description = "Network";
10+
};
11+
jwtsecret = mkOption {
12+
type = types.nullOr types.str;
13+
default = null;
14+
description = "Path to the token that ensures safe connection between CL and EL.";
15+
};
16+
}

modules/nimbus/default.nix

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
config,
3+
lib,
4+
pkgs,
5+
...
6+
}: let
7+
inherit
8+
(builtins)
9+
toString
10+
;
11+
inherit
12+
(lib)
13+
filterAttrs
14+
flatten
15+
mapAttrs'
16+
mapAttrsToList
17+
mkIf
18+
mkMerge
19+
nameValuePair
20+
zipAttrsWith
21+
;
22+
23+
modulesLib = import ../lib.nix lib;
24+
inherit (modulesLib) baseServiceConfig;
25+
26+
eachNimbus = config.services.ethereum.nimbus;
27+
in {
28+
###### interface
29+
inherit (import ./options.nix {inherit lib pkgs;}) options;
30+
31+
###### implementation
32+
33+
config = mkIf (eachNimbus != {}) {
34+
# configure the firewall for each service
35+
networking.firewall = let
36+
openFirewall = filterAttrs (_: cfg: cfg.openFirewall) eachNimbus;
37+
perService =
38+
mapAttrsToList
39+
(
40+
_: cfg:
41+
with cfg.args; {
42+
allowedUDPPorts = [port];
43+
allowedTCPPorts = [port];
44+
}
45+
)
46+
openFirewall;
47+
in
48+
zipAttrsWith (_name: flatten) perService;
49+
50+
# create a service for each instance
51+
systemd.services =
52+
mapAttrs' (
53+
nimbusName: let
54+
serviceName = "nimbus-${nimbusName}";
55+
in
56+
cfg:
57+
nameValuePair serviceName (mkIf cfg.enable {
58+
after = ["network.target"];
59+
wantedBy = ["multi-user.target"];
60+
description = "Nimbus Node (${nimbusName})";
61+
62+
# create service config by merging with the base config
63+
serviceConfig = mkMerge [
64+
baseServiceConfig
65+
{
66+
User =
67+
if cfg.user != null
68+
then cfg.user
69+
else serviceName;
70+
StateDirectory = serviceName;
71+
ExecStart = "${cfg.package}/bin/nimbus_beacon_node --tcp-port=${builtins.toString cfg.args.port} --network=${cfg.args.network} --jwt-secret=${cfg.args.jwtsecret} --udp-port=${builtins.toString cfg.args.port} ${lib.escapeShellArgs cfg.extraArgs}";
72+
MemoryDenyWriteExecute = "false";
73+
}
74+
];
75+
})
76+
)
77+
eachNimbus;
78+
};
79+
}

modules/nimbus/options.nix

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
lib,
3+
pkgs,
4+
...
5+
}: let
6+
args = import ./args.nix lib;
7+
8+
nimbusOpts = with lib; {
9+
options = {
10+
enable = mkEnableOption "Nimbus Ethereum Node.";
11+
12+
package = mkOption {
13+
type = types.package;
14+
default = pkgs.nimbus;
15+
defaultText = literalExpression "pkgs.nimbus";
16+
description = "Package to use as Nimbus.";
17+
};
18+
19+
inherit args;
20+
21+
extraArgs = mkOption {
22+
type = types.listOf types.str;
23+
description = "Additional arguments to pass to Nimbus.";
24+
default = [];
25+
};
26+
27+
user = mkOption {
28+
type = types.nullOr types.str;
29+
description = "Service user";
30+
};
31+
32+
openFirewall = mkOption {
33+
type = types.bool;
34+
default = false;
35+
description = "Open ports in the firewall for any enabled networking services";
36+
};
37+
};
38+
};
39+
in {
40+
options.services.ethereum.nimbus = with lib;
41+
mkOption {
42+
type = types.attrsOf (types.submodule nimbusOpts);
43+
default = {};
44+
description = "Specification of one or more Nimbus instances.";
45+
};
46+
}

0 commit comments

Comments
 (0)