From 9fc8cbf8e826d4c8a118f37202ab3f335341082a Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Fri, 19 Nov 2021 23:42:56 +0100 Subject: target: use default port from SSH config This is the expected behavior. The SSH config is also implicitly used for other SSH-related settings. --- lib/default.nix | 8 ++++++-- pkgs/krops/default.nix | 3 +-- pkgs/populate/default.nix | 3 +-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index 357f5b5..3bbd754 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -57,9 +57,9 @@ let { elemAt' = xs: i: if lib.length xs > i then lib.elemAt xs i else null; filterNull = lib.filterAttrs (n: v: v != null); in { - user = lib.getEnv "LOGNAME"; + user = lib.maybeEnv "LOGNAME" null; host = lib.maybeEnv "HOSTNAME" (lib.maybeHostName "localhost"); - port = "22"; + port = null; path = "/var/src"; sudo = false; extraOptions = []; @@ -70,6 +70,10 @@ let { path = elemAt' parse 6; } else s); + mkUserPortSSHOpts = target: + (lib.optionals (target.user != null) ["-l" target.user]) ++ + (lib.optionals (target.port != null) ["-p" target.port]); + shell = let isSafeChar = lib.testString "[-+./0-9:=A-Z_a-z]"; quoteChar = c: diff --git a/pkgs/krops/default.nix b/pkgs/krops/default.nix index d092307..7fe8370 100644 --- a/pkgs/krops/default.nix +++ b/pkgs/krops/default.nix @@ -20,8 +20,7 @@ in else writers.writeDash "krops.${target.host}.${lib.firstWord command}" '' exec ${openssh}/bin/ssh ${lib.escapeShellArgs (lib.flatten [ - (lib.optionals (target.user != "") ["-l" target.user]) - "-p" target.port + (lib.mkUserPortSSHOpts target) (if allocateTTY then "-t" else "-T") target.extraOptions target.host diff --git a/pkgs/populate/default.nix b/pkgs/populate/default.nix index ee2e5db..bf6f76d 100644 --- a/pkgs/populate/default.nix +++ b/pkgs/populate/default.nix @@ -224,8 +224,7 @@ let ssh' = target: concatMapStringsSep " " quote (flatten [ "${openssh}/bin/ssh" - (optionals (target.user != "") ["-l" target.user]) - "-p" target.port + (mkUserPortSSHOpts target) "-T" target.extraOptions ]); -- cgit v1.2.3