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