-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.nix
102 lines (86 loc) · 3.51 KB
/
module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.ethereum.rocketpool;
in {
options.services.ethereum.rocketpool = {
enable = mkEnableOption "Rocketpool node and watchtower services";
dataDir = mkOption {
type = types.path;
default = "/srv/rocketpool";
description = "Rocketpool data directory.";
};
user = mkOption {
type = types.str;
default = "rp";
description = "User under which the services run.";
};
group = mkOption {
type = types.str;
default = "rp";
description = "Group under which the services run.";
};
validatorServiceName = mkOption {
type = types.str;
default = "prysm-validator";
description = "Name of the validator client service, for running systemctl commands";
};
};
config = mkIf cfg.enable {
users.users.${cfg.user} = {
isSystemUser = true;
group = cfg.group;
home = cfg.dataDir;
};
users.groups.${cfg.group} = {};
systemd.tmpfiles.rules = [
"d ${cfg.dataDir} 0755 ${cfg.user} ${cfg.group} - -"
"d ${cfg.dataDir}/data 0755 ${cfg.user} ${cfg.group} - -"
"d ${cfg.dataDir}/data/validators 0775 ${cfg.user} ${cfg.group} - -"
"d ${cfg.dataDir}/data/rewards-trees 0755 ${cfg.user} ${cfg.group} - -"
"d ${cfg.dataDir}/data/custom-keys 0755 ${cfg.user} ${cfg.group} - -"
"d ${cfg.dataDir}/data/validators/prysm-non-hd 0755 ${cfg.user} ${cfg.group} - -"
"d ${cfg.dataDir}/data/validators/prysm-non-hd/direct 0755 ${cfg.user} ${cfg.group} - -"
"d ${cfg.dataDir}/data/validators/prysm-non-hd/direct/accounts 0755 ${cfg.user} ${cfg.group} - -"
"f+ ${cfg.dataDir}/restart-vc.sh 0755 ${cfg.user} ${cfg.group} - #!/usr/bin/env bash\\n\\n"
"w+ ${cfg.dataDir}/restart-vc.sh 0755 ${cfg.user} ${cfg.group} - sudo /run/current-system/sw/bin/systemctl restart ${cfg.validatorServiceName}"
"f+ ${cfg.dataDir}/stop-validator.sh 0755 ${cfg.user} ${cfg.group} - #!/usr/bin/env bash\\n\\n"
"w+ ${cfg.dataDir}/stop-validator.sh 0755 ${cfg.user} ${cfg.group} - sudo /run/current-system/sw/bin/systemctl stop ${cfg.validatorServiceName}"
];
systemd.services.rocketpool = {
description = "Rocketpool Node";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = cfg.user;
Group = cfg.group;
ExecStart = "${pkgs.rocketpool}/bin/rocketpool --settings ${cfg.dataDir}/user-settings.yml node";
Restart = "always";
RestartSec = "5s";
UMask = "0002";
};
};
systemd.services.rocketpool-watchtower = {
description = "Rocketpool Watchtower";
after = [ "network.target" "rocketpool.service" ];
requires = [ "rocketpool.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = cfg.user;
Group = cfg.group;
ExecStart = "${pkgs.rocketpool}/bin/rocketpool --settings ${cfg.dataDir}/user-settings.yml watchtower";
Restart = "always";
RestartSec = "5s";
};
};
systemd.services."${cfg.validatorServiceName}" = {
serviceConfig.EnvironmentFile =
"${cfg.dataDir}/data/validators/rp-fee-recipient-env.txt";
};
security.sudo.extraConfig = ''
Cmnd_Alias RP_RESTART = /run/current-system/sw/bin/systemctl restart ${cfg.validatorServiceName}
Cmnd_Alias RP_STOP = /run/current-system/sw/bin/systemctl stop ${cfg.validatorServiceName}
${cfg.user} ALL=(ALL) NOPASSWD: RP_RESTART, RP_STOP
'';
};
}