Skip to content

Commit 3b0aacf

Browse files
committed
feat: Support and test lair keystore in proc
1 parent 0bc3f0c commit 3b0aacf

11 files changed

+290
-990
lines changed

flake.lock

+36-951
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+12
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,26 @@
258258
inherit self system;
259259
holonix = holonix-0_3;
260260
});
261+
holochain-0_3-with-in-proc-lair = pkgs.testers.runNixOSTest (import ./tests/holochain-0_3-with-in-proc-lair.nix {
262+
inherit self system;
263+
holonix = holonix-0_3;
264+
});
261265
holochain-0_4-with-lair = pkgs.testers.runNixOSTest (import ./tests/holochain-0_4-with-lair.nix {
262266
inherit self system;
263267
holonix = holonix-0_4;
264268
});
269+
holochain-0_4-with-in-proc-lair = pkgs.testers.runNixOSTest (import ./tests/holochain-0_4-with-in-proc-lair.nix {
270+
inherit self system;
271+
holonix = holonix-0_4;
272+
});
265273
holochain-0_5-with-lair = pkgs.testers.runNixOSTest (import ./tests/holochain-0_5-with-lair.nix {
266274
inherit self system;
267275
holonix = holonix-0_5;
268276
});
277+
holochain-0_5-with-in-proc-lair = pkgs.testers.runNixOSTest (import ./tests/holochain-0_5-with-in-proc-lair.nix {
278+
inherit self system;
279+
holonix = holonix-0_5;
280+
});
269281
holochain-and-lair-side-by-side = pkgs.testers.runNixOSTest (import ./tests/holochain-and-lair-side-by-side.nix {
270282
inherit self system;
271283
holonix-0_3 = holonix-0_3;

modules/conductor-0_3.nix

+43-13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
with lib; let
88
# The input config for this service
99
cfg = config.services.conductor-0_3;
10+
11+
keystore_type = (cfg.config.keystore or {}).type or "lair_server";
1012
in {
1113
options.services.conductor-0_3 = {
1214
enable = mkEnableOption "Holochain conductor";
@@ -40,11 +42,26 @@ in {
4042
config = mkIf cfg.enable {
4143
systemd.services.conductor-0_3 = {
4244
wantedBy = ["multi-user.target"]; # Start on boot
43-
after = [
44-
"network.target"
45-
"lair-keystore-for-0_3.service"
46-
]; # Waits for network and lair started
47-
bindsTo = ["lair-keystore-for-0_3.service"]; # Requires Lair, stop if Lair stops
45+
after =
46+
[
47+
# Wait for the network to be ready before starting this service
48+
"network.target"
49+
]
50+
++ (
51+
if keystore_type == "lair_server"
52+
then [
53+
# When Lair is running as a separate service, wait for it to start
54+
"lair-keystore-for-0_3.service"
55+
]
56+
else []
57+
);
58+
bindsTo =
59+
if keystore_type == "lair_server"
60+
then [
61+
# When Lair us running as a separate service, require Lair to be running, stop if Lair stops
62+
"lair-keystore-for-0_3.service"
63+
]
64+
else [];
4865
description = "Holochain conductor: ${cfg.id}";
4966
path = [cfg.package pkgs.yq];
5067
restartIfChanged = true;
@@ -56,10 +73,15 @@ in {
5673
};
5774

5875
# TODO should be able to pass this to Holochain as an arg rather than needing to modify the file
59-
preStart = ''
60-
lair_connection_url=$(yq -r .connectionUrl /var/lib/lair-${cfg.lairId}/lair-keystore-config.yaml)
61-
yq -y "(.keystore.connection_url) = \"$lair_connection_url\"" /etc/holochain-${cfg.id}/conductor.yaml > /var/lib/conductor-${cfg.id}/conductor.yaml
62-
'';
76+
preStart =
77+
if keystore_type == "lair_server"
78+
then ''
79+
lair_connection_url=$(yq -r .connectionUrl /var/lib/lair-${cfg.lairId}/lair-keystore-config.yaml)
80+
yq -y "(.keystore.connection_url) = \"$lair_connection_url\"" /etc/holochain-${cfg.id}/conductor.yaml > /var/lib/conductor-${cfg.id}/conductor.yaml
81+
''
82+
else ''
83+
cp /etc/holochain-${cfg.id}/conductor.yaml /var/lib/conductor-${cfg.id}/conductor.yaml
84+
'';
6385

6486
script = ''
6587
echo -n "${cfg.keystorePassphrase}" | holochain -c /var/lib/conductor-${cfg.id}/conductor.yaml --piped
@@ -100,10 +122,18 @@ in {
100122
];
101123
tuning_params = {gossip_strategy = "sharded-gossip";};
102124
};
125+
keystore =
126+
{
127+
type = keystore_type;
128+
}
129+
// (
130+
if keystore_type == "lair_server_in_proc"
131+
then {
132+
lair_root = "/var/lib/conductor-${cfg.id}/keystore/";
133+
}
134+
else {}
135+
);
103136
}
104-
// cfg.config
105-
// {
106-
keystore.type = "lair_server";
107-
});
137+
// cfg.config);
108138
};
109139
}

modules/conductor-0_4.nix

+43-13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
with lib; let
88
# The input config for this service
99
cfg = config.services.conductor-0_4;
10+
11+
keystore_type = (cfg.config.keystore or {}).type or "lair_server";
1012
in {
1113
options.services.conductor-0_4 = {
1214
enable = mkEnableOption "Holochain conductor";
@@ -40,11 +42,26 @@ in {
4042
config = mkIf cfg.enable {
4143
systemd.services.conductor-0_4 = {
4244
wantedBy = ["multi-user.target"]; # Start on boot
43-
after = [
44-
"network.target"
45-
"lair-keystore-for-0_4.service"
46-
]; # Waits for network and lair started
47-
bindsTo = ["lair-keystore-for-0_4.service"]; # Requires Lair, stop if Lair stops
45+
after =
46+
[
47+
# Wait for the network to be ready before starting this service
48+
"network.target"
49+
]
50+
++ (
51+
if keystore_type == "lair_server"
52+
then [
53+
# When Lair is running as a separate service, wait for it to start
54+
"lair-keystore-for-0_4.service"
55+
]
56+
else []
57+
);
58+
bindsTo =
59+
if keystore_type == "lair_server"
60+
then [
61+
# When Lair us running as a separate service, require Lair to be running, stop if Lair stops
62+
"lair-keystore-for-0_4.service"
63+
]
64+
else [];
4865
description = "Holochain conductor";
4966
path = [cfg.package pkgs.yq];
5067
restartIfChanged = true;
@@ -56,10 +73,15 @@ in {
5673
};
5774

5875
# TODO should be able to pass this to Holochain as an arg rather than needing to modify the file
59-
preStart = ''
60-
lair_connection_url=$(yq -r .connectionUrl /var/lib/lair-${cfg.lairId}/lair-keystore-config.yaml)
61-
yq -y "(.keystore.connection_url) = \"$lair_connection_url\"" /etc/holochain-${cfg.id}/conductor.yaml > /var/lib/conductor-${cfg.id}/conductor.yaml
62-
'';
76+
preStart =
77+
if keystore_type == "lair_server"
78+
then ''
79+
lair_connection_url=$(yq -r .connectionUrl /var/lib/lair-${cfg.lairId}/lair-keystore-config.yaml)
80+
yq -y "(.keystore.connection_url) = \"$lair_connection_url\"" /etc/holochain-${cfg.id}/conductor.yaml > /var/lib/conductor-${cfg.id}/conductor.yaml
81+
''
82+
else ''
83+
cp /etc/holochain-${cfg.id}/conductor.yaml /var/lib/conductor-${cfg.id}/conductor.yaml
84+
'';
6385

6486
script = ''
6587
echo -n "${cfg.keystorePassphrase}" | holochain -c /var/lib/conductor-${cfg.id}/conductor.yaml --piped
@@ -107,10 +129,18 @@ in {
107129
no_dpki = true;
108130
network_seed = "deepkey-main";
109131
};
132+
keystore =
133+
{
134+
type = keystore_type;
135+
}
136+
// (
137+
if keystore_type == "lair_server_in_proc"
138+
then {
139+
lair_root = "/var/lib/conductor-${cfg.id}/keystore/";
140+
}
141+
else {}
142+
);
110143
}
111-
// cfg.config
112-
// {
113-
keystore.type = "lair_server";
114-
});
144+
// cfg.config);
115145
};
116146
}

modules/conductor-0_5.nix

+43-13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
with lib; let
88
# The input config for this service
99
cfg = config.services.conductor-0_5;
10+
11+
keystore_type = (cfg.config.keystore or {}).type or "lair_server";
1012
in {
1113
options.services.conductor-0_5 = {
1214
enable = mkEnableOption "Holochain conductor";
@@ -40,11 +42,26 @@ in {
4042
config = mkIf cfg.enable {
4143
systemd.services.conductor-0_5 = {
4244
wantedBy = ["multi-user.target"]; # Start on boot
43-
after = [
44-
"network.target"
45-
"lair-keystore-for-0_5.service"
46-
]; # Waits for network and lair started
47-
bindsTo = ["lair-keystore-for-0_5.service"]; # Requires Lair, stop if Lair stops
45+
after =
46+
[
47+
# Wait for the network to be ready before starting this service
48+
"network.target"
49+
]
50+
++ (
51+
if keystore_type == "lair_server"
52+
then [
53+
# When Lair is running as a separate service, wait for it to start
54+
"lair-keystore-for-0_5.service"
55+
]
56+
else []
57+
);
58+
bindsTo =
59+
if keystore_type == "lair_server"
60+
then [
61+
# When Lair us running as a separate service, require Lair to be running, stop if Lair stops
62+
"lair-keystore-for-0_5.service"
63+
]
64+
else [];
4865
description = "Holochain conductor";
4966
path = [cfg.package pkgs.yq];
5067
restartIfChanged = true;
@@ -56,10 +73,15 @@ in {
5673
};
5774

5875
# TODO should be able to pass this to Holochain as an arg rather than needing to modify the file
59-
preStart = ''
60-
lair_connection_url=$(yq -r .connectionUrl /var/lib/lair-${cfg.lairId}/lair-keystore-config.yaml)
61-
yq -y "(.keystore.connection_url) = \"$lair_connection_url\"" /etc/holochain-${cfg.id}/conductor.yaml > /var/lib/conductor-${cfg.id}/conductor.yaml
62-
'';
76+
preStart =
77+
if keystore_type == "lair_server"
78+
then ''
79+
lair_connection_url=$(yq -r .connectionUrl /var/lib/lair-${cfg.lairId}/lair-keystore-config.yaml)
80+
yq -y "(.keystore.connection_url) = \"$lair_connection_url\"" /etc/holochain-${cfg.id}/conductor.yaml > /var/lib/conductor-${cfg.id}/conductor.yaml
81+
''
82+
else ''
83+
cp /etc/holochain-${cfg.id}/conductor.yaml /var/lib/conductor-${cfg.id}/conductor.yaml
84+
'';
6385

6486
script = ''
6587
echo -n "${cfg.keystorePassphrase}" | holochain -c /var/lib/conductor-${cfg.id}/conductor.yaml --piped
@@ -107,10 +129,18 @@ in {
107129
no_dpki = true;
108130
network_seed = "deepkey-main";
109131
};
132+
keystore =
133+
{
134+
type = keystore_type;
135+
}
136+
// (
137+
if keystore_type == "lair_server_in_proc"
138+
then {
139+
lair_root = "/var/lib/conductor-${cfg.id}/keystore/";
140+
}
141+
else {}
142+
);
110143
}
111-
// cfg.config
112-
// {
113-
keystore.type = "lair_server";
114-
});
144+
// cfg.config);
115145
};
116146
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
self,
3+
system,
4+
holonix,
5+
...
6+
}: {
7+
name = "Holochain 0.3 With In Process Lair";
8+
9+
nodes = {
10+
machine = {pkgs, ...}: {
11+
imports = [
12+
self.outputs.nixosModules.hcCommon
13+
self.outputs.nixosModules.conductor-0_3
14+
];
15+
16+
services.conductor-0_3 = {
17+
enable = true;
18+
id = "test";
19+
lairId = "test";
20+
package = holonix.packages.${system}.holochain;
21+
keystorePassphrase = "password";
22+
config = {
23+
keystore = {
24+
type = "lair_server_in_proc";
25+
};
26+
};
27+
};
28+
29+
system.stateVersion = "24.11";
30+
};
31+
};
32+
33+
# https://nixos.org/manual/nixos/stable/index.html#ssec-machine-objects
34+
testScript = builtins.readFile ./holochain-0_3-with-in-proc-lair.py;
35+
}
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
machine.wait_for_unit("default.target")
2+
machine.wait_for_unit("conductor-0_3.service")
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
self,
3+
system,
4+
holonix,
5+
...
6+
}: {
7+
name = "Holochain 0.4 With Lair";
8+
9+
nodes = {
10+
machine = {pkgs, ...}: {
11+
imports = [
12+
self.outputs.nixosModules.hcCommon
13+
self.outputs.nixosModules.lair-keystore-for-0_4
14+
self.outputs.nixosModules.conductor-0_4
15+
];
16+
17+
services.conductor-0_4 = {
18+
enable = true;
19+
id = "test";
20+
lairId = "test";
21+
package = holonix.packages.${system}.holochain;
22+
keystorePassphrase = "password";
23+
config = {
24+
keystore = {
25+
type = "lair_server_in_proc";
26+
};
27+
};
28+
};
29+
30+
system.stateVersion = "24.11";
31+
};
32+
};
33+
34+
# https://nixos.org/manual/nixos/stable/index.html#ssec-machine-objects
35+
testScript = builtins.readFile ./holochain-0_4-with-in-proc-lair.py;
36+
}
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
machine.wait_for_unit("default.target")
2+
machine.wait_for_unit("conductor-0_4.service")
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
self,
3+
system,
4+
holonix,
5+
...
6+
}: {
7+
name = "Holochain 0.5 With Lair";
8+
9+
nodes = {
10+
machine = {pkgs, ...}: {
11+
imports = [
12+
self.outputs.nixosModules.hcCommon
13+
self.outputs.nixosModules.lair-keystore-for-0_5
14+
self.outputs.nixosModules.conductor-0_5
15+
];
16+
17+
services.conductor-0_5 = {
18+
enable = true;
19+
id = "test";
20+
lairId = "test";
21+
package = holonix.packages.${system}.holochain;
22+
keystorePassphrase = "password";
23+
config = {
24+
keystore = {
25+
type = "lair_server_in_proc";
26+
};
27+
};
28+
};
29+
30+
system.stateVersion = "24.11";
31+
};
32+
};
33+
34+
# https://nixos.org/manual/nixos/stable/index.html#ssec-machine-objects
35+
testScript = builtins.readFile ./holochain-0_5-with-in-proc-lair.py;
36+
}
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
machine.wait_for_unit("default.target")
2+
machine.wait_for_unit("conductor-0_5.service")

0 commit comments

Comments
 (0)