diff options
Diffstat (limited to 'lib/default.nix')
-rw-r--r-- | lib/default.nix | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/default.nix b/lib/default.nix index f1f0007..3bbd754 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -28,13 +28,20 @@ let { # This function's return value can be used as pkgs.populate input. source: sanitize (eval source).config.source; - getHostName = let + maybeHostName = default: let # We're parsing /etc/hostname here because reading # /proc/sys/kernel/hostname yields "" - y = lib.filter lib.types.label.check (lib.splitString "\n" (lib.readFile /etc/hostname)); + path = "/etc/hostname"; + lines = lib.splitString "\n" (lib.readFile path); + hostNames = lib.filter lib.types.label.check lines; in - if lib.length y != 1 then throw "malformed /etc/hostname" else - lib.elemAt y 0; + if lib.pathExists path then + if lib.length hostNames == 1 then + lib.head hostNames + else + lib.trace "malformed ${path}" default + else + default; firstWord = s: lib.head (lib.match "^([^[:space:]]*).*" s); @@ -50,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"; - host = lib.maybeEnv "HOSTNAME" lib.getHostName; - port = "22"; + user = lib.maybeEnv "LOGNAME" null; + host = lib.maybeEnv "HOSTNAME" (lib.maybeHostName "localhost"); + port = null; path = "/var/src"; sudo = false; extraOptions = []; @@ -63,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: |