blob: 72507d0e934c8da212f9d6dd41297664fac795a2 (
plain)
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
|
{ options
, lib
, config
, pkgs
, ...
}:
/*
Urbit Harbor is a supervisor for Urbit ships on the local machine. It does no
orchestration, it just manages systemd services.
Setup process:
<running as user "urbit-harbor">
dir=/var/urbit/harbor
urbit -c $dir/zod -k $dir/zod.key -x # one-time setup
<create $dir/zod.service from some template>
systemctl --user enable $dir/zod.service # nees fullpath
systemctl --user start zod.service
Service Template:
[Service]
ExecStart=urbit -tq /var/urbit/harbor/zod # maybe want -d?
ExecStartPre=mkdir -p /var/urbit/harbor/zod
[Unit]
Description=zod
[Install]
WantedBy=multi-user.target
TODO:
- use systemd.resource-control to limit memory/CPU for ships
- Urbit.Cloud controller will set different limits by reading/editing the
ini file, and change price to customer
- figure out what firewall stuff i need to do
*/
let
cfg = config.services.urbit-harbor;
in {
options.services.urbitharbor = {
enable = lib.mkEnableOption "Enable urbit-harbor";
dataDir = lib.mkOption {
type = lib.types.path;
default = "/var/urbit/harbor";
description = "Where to store piers";
};
ships = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "List of @p's to start up, without the leading ~";
};
package = lib.mkOption {
type = lib.types.package;
default = pkgs.urbit-harbor;
description = "The urbit-harbor package to use";
};
urbitPackage = lib.mkOption {
type = lib.types.package;
default = pkgs.urbit;
description = "The urbit package to use";
};
user = lib.mkOption {
type = lib.types.user;
default = "urbit-harbor";
description = "User to run as";
};
};
config = lib.mkIf cfg.enable {
systemd.services.urbit-harbor = {
path = [ cfg.package cfg.urbitPackage ];
wantedBy = [ "multi-user.target" ];
preStart = ''
mkdir -p ${cfg.dataDir}
'';
script = "${cfg.package}/bin/urbit-harbor ${cfg.dataDir}";
description = "Urbit harbor";
serviceConfig = {
User = cfg.user;
Type = "simple";
Restart = "always";
RestartSec = "3";
};
};
};
}
|