diff options
author | Erik Arvstedt <erik.arvstedt@gmail.com> | 2020-04-18 23:36:53 +0200 |
---|---|---|
committer | Erik Arvstedt <erik.arvstedt@gmail.com> | 2020-04-18 23:38:43 +0200 |
commit | 8a8b2cf86197d4550c3bf2bee5f57ac1036c5ceb (patch) | |
tree | 4b22fdcbaf03db8fd2ed6c9d2b6844b9cdf6d02d | |
parent | 2cafddd78dc127ec3e66255808c5044893b261d3 (diff) |
support default target attrs for attrSets
-rw-r--r-- | lib/default.nix | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/default.nix b/lib/default.nix index 912a1c9..5829250 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -43,17 +43,22 @@ let { lib.elem target.host [origin.host "localhost"]; mkTarget = s: let - default = defVal: val: if val != null then val else defVal; parse = lib.match "(([^@]*)@)?(([^:/]+))?(:([^/]+))?(/.*)?" s; elemAt' = xs: i: if lib.length xs > i then lib.elemAt xs i else null; - in if lib.isString s then { - user = default (lib.getEnv "LOGNAME") (elemAt' parse 1); - host = default (lib.maybeEnv "HOSTNAME" lib.getHostName) (elemAt' parse 3); - port = default "22" /* "ssh"? */ (elemAt' parse 5); - path = default "/var/src" /* no default? */ (elemAt' parse 6); + filterNull = lib.filterAttrs (n: v: v != null); + in { + user = lib.getEnv "LOGNAME"; + host = lib.maybeEnv "HOSTNAME" lib.getHostName; + port = "22"; + path = "/var/src"; sudo = false; extraOptions = []; - } else s; + } // (if lib.isString s then filterNull { + user = elemAt' parse 1; + host = elemAt' parse 3; + port = elemAt' parse 5; + path = elemAt' parse 6; + } else s); shell = let isSafeChar = lib.testString "[-+./0-9:=A-Z_a-z]"; |