From 6175188591f13d8bbcfab928acb5958b0504f59d Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Thu, 7 Apr 2022 18:41:08 -0300 Subject: [PATCH 1/8] nixos/shellhub-agent: reformat code using nixpkgs-fmt Signed-off-by: Otavio Salvador --- nixos/modules/services/networking/shellhub-agent.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/networking/shellhub-agent.nix b/nixos/modules/services/networking/shellhub-agent.nix index a45ef148544..c7f3f9184c4 100644 --- a/nixos/modules/services/networking/shellhub-agent.nix +++ b/nixos/modules/services/networking/shellhub-agent.nix @@ -1,10 +1,11 @@ { config, lib, pkgs, ... }: with lib; + let cfg = config.services.shellhub-agent; -in { - +in +{ ###### interface options = { @@ -89,3 +90,4 @@ in { environment.systemPackages = [ cfg.package ]; }; } + From a62471fc65888bb0ba7b6d8b79352a560cb1629f Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Thu, 7 Apr 2022 18:35:43 -0300 Subject: [PATCH 2/8] nixos/shellhub-agent: use mkEnableOption to simplify code Signed-off-by: Otavio Salvador --- nixos/modules/services/networking/shellhub-agent.nix | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/nixos/modules/services/networking/shellhub-agent.nix b/nixos/modules/services/networking/shellhub-agent.nix index c7f3f9184c4..7a92636b5e3 100644 --- a/nixos/modules/services/networking/shellhub-agent.nix +++ b/nixos/modules/services/networking/shellhub-agent.nix @@ -12,14 +12,7 @@ in services.shellhub-agent = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Whether to enable the ShellHub Agent daemon, which allows - secure remote logins. - ''; - }; + enable = mkEnableOption "ShellHub Agent daemon"; package = mkOption { type = types.package; From 60158bfc22a50d90919ee647b3a36e4f5f255428 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Thu, 7 Apr 2022 18:36:38 -0300 Subject: [PATCH 3/8] nixos/shellhub-agent: use new configuration variables The old variables still work but will eventually stop to be supported so move to the new ones. Signed-off-by: Otavio Salvador --- nixos/modules/services/networking/shellhub-agent.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/networking/shellhub-agent.nix b/nixos/modules/services/networking/shellhub-agent.nix index 7a92636b5e3..d4344272988 100644 --- a/nixos/modules/services/networking/shellhub-agent.nix +++ b/nixos/modules/services/networking/shellhub-agent.nix @@ -68,9 +68,9 @@ in "time-sync.target" ]; - environment.SERVER_ADDRESS = cfg.server; - environment.PRIVATE_KEY = cfg.privateKey; - environment.TENANT_ID = cfg.tenantId; + environment.SHELLHUB_SERVER_ADDRESS = cfg.server; + environment.SHELLHUB_PRIVATE_KEY = cfg.privateKey; + environment.SHELLHUB_TENANT_ID = cfg.tenantId; serviceConfig = { # The service starts sessions for different users. From 6729653309e636401ea880acffa17866f18f320d Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Thu, 7 Apr 2022 18:39:48 -0300 Subject: [PATCH 4/8] nixos/shellhub-agent: allow setting the keepAliveInterval Signed-off-by: Otavio Salvador --- nixos/modules/services/networking/shellhub-agent.nix | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nixos/modules/services/networking/shellhub-agent.nix b/nixos/modules/services/networking/shellhub-agent.nix index d4344272988..fa237a44d69 100644 --- a/nixos/modules/services/networking/shellhub-agent.nix +++ b/nixos/modules/services/networking/shellhub-agent.nix @@ -23,6 +23,16 @@ in ''; }; + keepAliveInterval = mkOption { + type = types.int; + default = 30; + description = '' + Determine the interval to send the keep alive message to + the server. This has a direct impact of the bandwidth + used by the device. + ''; + }; + tenantId = mkOption { type = types.str; example = "ba0a880c-2ada-11eb-a35e-17266ef329d6"; @@ -71,6 +81,7 @@ in environment.SHELLHUB_SERVER_ADDRESS = cfg.server; environment.SHELLHUB_PRIVATE_KEY = cfg.privateKey; environment.SHELLHUB_TENANT_ID = cfg.tenantId; + environment.SHELLHUB_KEEPALIVE_INTERVAL = toString cfg.keepAliveInterval; serviceConfig = { # The service starts sessions for different users. From 8c4bc7f62c912d7828568492b8715a3006133907 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Thu, 7 Apr 2022 18:40:16 -0300 Subject: [PATCH 5/8] nixos/shellhub-agent: allow setting the preferredHostname Signed-off-by: Otavio Salvador --- nixos/modules/services/networking/shellhub-agent.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nixos/modules/services/networking/shellhub-agent.nix b/nixos/modules/services/networking/shellhub-agent.nix index fa237a44d69..ffab9fb69d2 100644 --- a/nixos/modules/services/networking/shellhub-agent.nix +++ b/nixos/modules/services/networking/shellhub-agent.nix @@ -23,6 +23,15 @@ in ''; }; + preferredHostname = mkOption { + type = types.str; + default = ""; + description = '' + Set the device preferred hostname. This provides a hint to + the server to use this as hostname if it is available. + ''; + }; + keepAliveInterval = mkOption { type = types.int; default = 30; @@ -81,6 +90,7 @@ in environment.SHELLHUB_SERVER_ADDRESS = cfg.server; environment.SHELLHUB_PRIVATE_KEY = cfg.privateKey; environment.SHELLHUB_TENANT_ID = cfg.tenantId; + environment.SHELLHUB_PREFERRED_HOSTNAME = cfg.preferredHostname; environment.SHELLHUB_KEEPALIVE_INTERVAL = toString cfg.keepAliveInterval; serviceConfig = { From bd3b046ac85758208b362e0b4234fb0466cd5cbd Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Fri, 8 Apr 2022 09:32:33 -0300 Subject: [PATCH 6/8] nixos/shellhub-agent: use mkPackageOption to simplify code Signed-off-by: Otavio Salvador --- nixos/modules/services/networking/shellhub-agent.nix | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/nixos/modules/services/networking/shellhub-agent.nix b/nixos/modules/services/networking/shellhub-agent.nix index ffab9fb69d2..ce0a6d99927 100644 --- a/nixos/modules/services/networking/shellhub-agent.nix +++ b/nixos/modules/services/networking/shellhub-agent.nix @@ -14,14 +14,7 @@ in enable = mkEnableOption "ShellHub Agent daemon"; - package = mkOption { - type = types.package; - default = pkgs.shellhub-agent; - defaultText = literalExpression "pkgs.shellhub-agent"; - description = '' - Which ShellHub Agent package to use. - ''; - }; + package = mkPackageOption pkgs "shellhub-agent" { }; preferredHostname = mkOption { type = types.str; From d7a0f56c6a2a19c9e6a61716ce5315412b61c2f6 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Fri, 8 Apr 2022 09:33:02 -0300 Subject: [PATCH 7/8] nixos/shellhub-agent: avoid code duplication for environment Signed-off-by: Otavio Salvador --- nixos/modules/services/networking/shellhub-agent.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/nixos/modules/services/networking/shellhub-agent.nix b/nixos/modules/services/networking/shellhub-agent.nix index ce0a6d99927..4ec59754bfb 100644 --- a/nixos/modules/services/networking/shellhub-agent.nix +++ b/nixos/modules/services/networking/shellhub-agent.nix @@ -80,11 +80,13 @@ in "time-sync.target" ]; - environment.SHELLHUB_SERVER_ADDRESS = cfg.server; - environment.SHELLHUB_PRIVATE_KEY = cfg.privateKey; - environment.SHELLHUB_TENANT_ID = cfg.tenantId; - environment.SHELLHUB_PREFERRED_HOSTNAME = cfg.preferredHostname; - environment.SHELLHUB_KEEPALIVE_INTERVAL = toString cfg.keepAliveInterval; + environment = { + SHELLHUB_SERVER_ADDRESS = cfg.server; + SHELLHUB_PRIVATE_KEY = cfg.privateKey; + SHELLHUB_TENANT_ID = cfg.tenantId; + SHELLHUB_KEEPALIVE_INTERVAL = toString cfg.keepAliveInterval; + SHELLHUB_PREFERRED_HOSTNAME = cfg.preferredHostname; + }; serviceConfig = { # The service starts sessions for different users. From fcb69a858359f7b7fe453c06697f6e4200a4d2d4 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Fri, 8 Apr 2022 09:33:52 -0300 Subject: [PATCH 8/8] nixos/shellhub-agent: use package internally, avoiding it in PATH Signed-off-by: Otavio Salvador --- nixos/modules/services/networking/shellhub-agent.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/nixos/modules/services/networking/shellhub-agent.nix b/nixos/modules/services/networking/shellhub-agent.nix index 4ec59754bfb..57825945d9f 100644 --- a/nixos/modules/services/networking/shellhub-agent.nix +++ b/nixos/modules/services/networking/shellhub-agent.nix @@ -95,8 +95,6 @@ in ExecStart = "${cfg.package}/bin/agent"; }; }; - - environment.systemPackages = [ cfg.package ]; }; }