at 21.11-pre 2.1 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4let 5 cfg = config.services.shellhub-agent; 6in { 7 8 ###### interface 9 10 options = { 11 12 services.shellhub-agent = { 13 14 enable = mkOption { 15 type = types.bool; 16 default = false; 17 description = '' 18 Whether to enable the ShellHub Agent daemon, which allows 19 secure remote logins. 20 ''; 21 }; 22 23 package = mkOption { 24 type = types.package; 25 default = pkgs.shellhub-agent; 26 defaultText = "pkgs.shellhub-agent"; 27 description = '' 28 Which ShellHub Agent package to use. 29 ''; 30 }; 31 32 tenantId = mkOption { 33 type = types.str; 34 example = "ba0a880c-2ada-11eb-a35e-17266ef329d6"; 35 description = '' 36 The tenant ID to use when connecting to the ShellHub 37 Gateway. 38 ''; 39 }; 40 41 server = mkOption { 42 type = types.str; 43 default = "https://cloud.shellhub.io"; 44 description = '' 45 Server address of ShellHub Gateway to connect. 46 ''; 47 }; 48 49 privateKey = mkOption { 50 type = types.path; 51 default = "/var/lib/shellhub-agent/private.key"; 52 description = '' 53 Location where to store the ShellHub Agent private 54 key. 55 ''; 56 }; 57 }; 58 }; 59 60 ###### implementation 61 62 config = mkIf cfg.enable { 63 64 systemd.services.shellhub-agent = { 65 description = "ShellHub Agent"; 66 67 wantedBy = [ "multi-user.target" ]; 68 requires = [ "local-fs.target" ]; 69 wants = [ "network-online.target" ]; 70 after = [ 71 "local-fs.target" 72 "network.target" 73 "network-online.target" 74 "time-sync.target" 75 ]; 76 77 environment.SERVER_ADDRESS = cfg.server; 78 environment.PRIVATE_KEY = cfg.privateKey; 79 environment.TENANT_ID = cfg.tenantId; 80 81 serviceConfig = { 82 # The service starts sessions for different users. 83 User = "root"; 84 Restart = "on-failure"; 85 ExecStart = "${cfg.package}/bin/agent"; 86 }; 87 }; 88 89 environment.systemPackages = [ cfg.package ]; 90 }; 91}