Skip to content

Commit e913fbb

Browse files
committed
feat(tacchain): Add Tac Node module with configuration and systemd services
1 parent a304bee commit e913fbb

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

modules/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
./random-alerts
88
./host-info.nix
99
./secrets.nix
10+
./tacchain
1011
];
1112
}

modules/tacchain/default.nix

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{ withSystem, ... }:
2+
{
3+
flake.modules.nixos.tacchain =
4+
{
5+
pkgs,
6+
config,
7+
lib,
8+
...
9+
}:
10+
let
11+
cfg = config.services.tacchain;
12+
package = withSystem pkgs.stdenv.hostPlatform.system ({ config, ... }: config.packages.tacchain);
13+
persistent_peers = "[email protected]:45130,[email protected]:45140,[email protected]:45110,[email protected]:45120";
14+
genesis = pkgs.fetchurl {
15+
url = "https://raw.githubusercontent.com/TacBuild/tacchain/refs/heads/main/networks/tacchain_2391-1/genesis.json";
16+
hash = "sha256-ZGz5KtMX1Xx70/h7+VRAPtuPD+Xs5Y01Lv5d/bZF91c=";
17+
};
18+
in
19+
{
20+
options.services.tacchain = with lib; {
21+
enable = mkEnableOption (lib.mdDoc "Tacchain");
22+
nodeName = mkOption {
23+
type = types.str;
24+
default = "tacchain";
25+
description = "The name of the tacchain node.";
26+
};
27+
home = mkOption {
28+
type = types.path;
29+
default = "/var/lib/tacchain";
30+
description = "The home directory for the tacchain node.";
31+
};
32+
};
33+
config = lib.mkIf cfg.enable {
34+
mcl.secrets.services.tacchain.secrets = {
35+
validator-private-key = { };
36+
};
37+
systemd.tmpfiles.rules = [
38+
"d ${cfg.home} 0755 root root - - -"
39+
];
40+
systemd.services.tacchain_setup = {
41+
description = "tacchain_setup";
42+
wantedBy = [ "multi-user.target" ];
43+
serviceConfig = {
44+
Type = "oneshot";
45+
Environment = "HOME=${cfg.home}";
46+
ConditionPathExists = "!${cfg.home}/config/genesis.json";
47+
ExecStart = [
48+
''${lib.getExe package} init ${cfg.nodeName} --chain-id tacchain_2391-1 --home ${cfg.home}''
49+
''${pkgs.gnused}/bin/sed -i 's/timeout_commit = "5s"/timeout_commit = "2s"/' ${cfg.home}/config/config.toml''
50+
''${pkgs.gnused}/bin/sed -i 's/persistent_peers = ".*"/persistent_peers = "${persistent_peers}"/' ${cfg.home}/config/config.toml''
51+
''${pkgs.coreutils}/bin/cp ${genesis} ${cfg.home}/config/genesis.json''
52+
''${lib.getExe package} keys import validator ${
53+
config.age.secrets."tacchain/validator-private-key".path
54+
} --home ${cfg.home} --keyring-backend test''
55+
];
56+
57+
};
58+
};
59+
systemd.services.tacchain = {
60+
description = "tacchain";
61+
wantedBy = [ "multi-user.target" ];
62+
serviceConfig = {
63+
Environment = "HOME=${cfg.home}";
64+
After = "tacchain_setup.service";
65+
ExecStart = ''${lib.getExe package} start --chain-id tacchain_2391-1 --home ${cfg.home}'';
66+
};
67+
};
68+
};
69+
};
70+
}

0 commit comments

Comments
 (0)