1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8with lib;
9
10let
11 cfg = config.services.shellhub-agent;
12in
13{
14 ###### interface
15
16 options = {
17
18 services.shellhub-agent = {
19
20 enable = mkEnableOption "ShellHub Agent daemon";
21
22 package = mkPackageOption pkgs "shellhub-agent" { };
23
24 preferredHostname = mkOption {
25 type = types.str;
26 default = "";
27 description = ''
28 Set the device preferred hostname. This provides a hint to
29 the server to use this as hostname if it is available.
30 '';
31 };
32
33 keepAliveInterval = mkOption {
34 type = types.int;
35 default = 30;
36 description = ''
37 Determine the interval to send the keep alive message to
38 the server. This has a direct impact of the bandwidth
39 used by the device.
40 '';
41 };
42
43 tenantId = mkOption {
44 type = types.str;
45 example = "ba0a880c-2ada-11eb-a35e-17266ef329d6";
46 description = ''
47 The tenant ID to use when connecting to the ShellHub
48 Gateway.
49 '';
50 };
51
52 server = mkOption {
53 type = types.str;
54 default = "https://cloud.shellhub.io";
55 description = ''
56 Server address of ShellHub Gateway to connect.
57 '';
58 };
59
60 privateKey = mkOption {
61 type = types.path;
62 default = "/var/lib/shellhub-agent/private.key";
63 description = ''
64 Location where to store the ShellHub Agent private
65 key.
66 '';
67 };
68 };
69 };
70
71 ###### implementation
72
73 config = mkIf cfg.enable {
74
75 systemd.services.shellhub-agent = {
76 description = "ShellHub Agent";
77
78 wantedBy = [ "multi-user.target" ];
79 requires = [ "local-fs.target" ];
80 wants = [ "network-online.target" ];
81 after = [
82 "local-fs.target"
83 "network.target"
84 "network-online.target"
85 "time-sync.target"
86 ];
87
88 environment = {
89 SHELLHUB_SERVER_ADDRESS = cfg.server;
90 SHELLHUB_PRIVATE_KEY = cfg.privateKey;
91 SHELLHUB_TENANT_ID = cfg.tenantId;
92 SHELLHUB_KEEPALIVE_INTERVAL = toString cfg.keepAliveInterval;
93 SHELLHUB_PREFERRED_HOSTNAME = cfg.preferredHostname;
94 };
95
96 serviceConfig = {
97 # The service starts sessions for different users.
98 User = "root";
99 Restart = "on-failure";
100 ExecStart = "${cfg.package}/bin/agent";
101 };
102 };
103 };
104}