nixos-rebuild: Fix "too long for Unix domain socket" errors due to long

TMPDIR
This commit is contained in:
Jacek Galowicz 2024-01-29 06:27:30 +01:00
parent d6c182f2ae
commit 3dbf54decb

View file

@ -407,6 +407,13 @@ fi
tmpDir=$(mktemp -t -d nixos-rebuild.XXXXXX) tmpDir=$(mktemp -t -d nixos-rebuild.XXXXXX)
if [[ ${#tmpDir} -ge 60 ]]; then
# Very long tmp dirs lead to "too long for Unix domain socket"
# SSH ControlPath errors. Especially macOS sets long TMPDIR paths.
rmdir "$tmpDir"
tmpDir=$(TMPDIR= mktemp -t -d nixos-rebuild.XXXXXX)
fi
cleanup() { cleanup() {
for ctrl in "$tmpDir"/ssh-*; do for ctrl in "$tmpDir"/ssh-*; do
ssh -o ControlPath="$ctrl" -O exit dummyhost 2>/dev/null || true ssh -o ControlPath="$ctrl" -O exit dummyhost 2>/dev/null || true