From afb621a98eef006c555a4b817d7b95dd3c373c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Mon, 29 Dec 2025 13:32:13 +0100 Subject: [PATCH] try-connect: check localhost first --- packages/try-connect.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/try-connect.nix b/packages/try-connect.nix index cca52f8..f716d31 100644 --- a/packages/try-connect.nix +++ b/packages/try-connect.nix @@ -28,6 +28,19 @@ lib.mapAttrs ( writers.writeBashBin "try-connect" '' port=${toString machines.${name}.sshPort} + hostname=$(hostname) + if [[ "$hostname" == "${name}" ]]; then + echo "Target is localhost, using ::1 or 127.0.0.1" >&2 + if ${netcat}/bin/nc -z -w 2 ::1 "$port" 2>/dev/null; then + echo "::1" + exit 0 + fi + if ${netcat}/bin/nc -z -w 2 127.0.0.1 "$port" 2>/dev/null; then + echo "127.0.0.1" + exit 0 + fi + fi + for addr in ${lib.concatStringsSep " " addresses.${name}}; do # Check if it's an onion address if [[ "$addr" == *.onion ]]; then