aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2021-01-16 14:12:45 +0100
committertv <tv@krebsco.de>2021-01-16 14:12:45 +0100
commitc2fa48550f2bb46009b9cecdb9ac838dc402ce19 (patch)
tree6da62ae554701d0d1b88ddec65f6dab7ecd81918
parentefe400d87c39bcf518f4f6e49d1fd243a44c0d19 (diff)
isLocalTarget: use "localhost" as defaultv1.24.1
This fixes an issue when trying to deploy using sudo from systems that don't provide means to determine the real host name.
-rw-r--r--lib/default.nix17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/default.nix b/lib/default.nix
index f1f0007..357f5b5 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);
@@ -51,7 +58,7 @@ let {
filterNull = lib.filterAttrs (n: v: v != null);
in {
user = lib.getEnv "LOGNAME";
- host = lib.maybeEnv "HOSTNAME" lib.getHostName;
+ host = lib.maybeEnv "HOSTNAME" (lib.maybeHostName "localhost");
port = "22";
path = "/var/src";
sudo = false;