1
0
Fork 0
mirror of https://cgit.krebsco.de/krops synced 2024-11-23 03:29:48 +01:00

isLocalTarget: use "localhost" as default

This fixes an issue when trying to deploy using sudo from systems that
don't provide means to determine the real host name.
This commit is contained in:
tv 2021-01-16 14:12:45 +01:00
parent efe400d87c
commit c2fa48550f

View file

@ -28,13 +28,20 @@ let {
# This function's return value can be used as pkgs.populate input. # This function's return value can be used as pkgs.populate input.
source: sanitize (eval source).config.source; source: sanitize (eval source).config.source;
getHostName = let maybeHostName = default: let
# We're parsing /etc/hostname here because reading # We're parsing /etc/hostname here because reading
# /proc/sys/kernel/hostname yields "" # /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 in
if lib.length y != 1 then throw "malformed /etc/hostname" else if lib.pathExists path then
lib.elemAt y 0; if lib.length hostNames == 1 then
lib.head hostNames
else
lib.trace "malformed ${path}" default
else
default;
firstWord = s: firstWord = s:
lib.head (lib.match "^([^[:space:]]*).*" s); lib.head (lib.match "^([^[:space:]]*).*" s);
@ -51,7 +58,7 @@ let {
filterNull = lib.filterAttrs (n: v: v != null); filterNull = lib.filterAttrs (n: v: v != null);
in { in {
user = lib.getEnv "LOGNAME"; user = lib.getEnv "LOGNAME";
host = lib.maybeEnv "HOSTNAME" lib.getHostName; host = lib.maybeEnv "HOSTNAME" (lib.maybeHostName "localhost");
port = "22"; port = "22";
path = "/var/src"; path = "/var/src";
sudo = false; sudo = false;