From 3dbf54decb8c368e9568743271cf5fe0eacb4d9f Mon Sep 17 00:00:00 2001 From: Jacek Galowicz Date: Mon, 29 Jan 2024 06:27:30 +0100 Subject: [PATCH 1/2] nixos-rebuild: Fix "too long for Unix domain socket" errors due to long TMPDIR --- pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh index bde6ff9d959b..2051368a49f6 100755 --- a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh +++ b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh @@ -407,6 +407,13 @@ fi 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() { for ctrl in "$tmpDir"/ssh-*; do ssh -o ControlPath="$ctrl" -O exit dummyhost 2>/dev/null || true From d45acb5457503a8d0b82fed1f8aeb68ea3a4cd8e Mon Sep 17 00:00:00 2001 From: Jacek Galowicz Date: Mon, 29 Jan 2024 06:28:11 +0100 Subject: [PATCH 2/2] nixos-rebuilt-target-host test: Add long TMPDIR to verify that fix works --- nixos/tests/nixos-rebuild-target-host.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nixos/tests/nixos-rebuild-target-host.nix b/nixos/tests/nixos-rebuild-target-host.nix index 8d60b788abf3..bf80b2fa6606 100644 --- a/nixos/tests/nixos-rebuild-target-host.nix +++ b/nixos/tests/nixos-rebuild-target-host.nix @@ -132,5 +132,10 @@ import ./make-test-python.nix ({ pkgs, ... }: { deployer.succeed("passh -c 3 -C -p ${nodes.target.users.users.bob.password} -P \"\[sudo\] password\" nixos-rebuild switch -I nixos-config=/root/configuration-3.nix --target-host bob@target --use-remote-sudo &>/dev/console") target_hostname = deployer.succeed("ssh alice@target cat /etc/hostname").rstrip() assert target_hostname == "config-3-deployed", f"{target_hostname=}" + + with subtest("Deploy works with very long TMPDIR"): + tmp_dir = "/var/folder/veryveryveryveryverylongpathnamethatdoesnotworkwithcontrolpath" + deployer.succeed(f"mkdir -p {tmp_dir}") + deployer.succeed(f"TMPDIR={tmp_dir} nixos-rebuild switch -I nixos-config=/root/configuration-1.nix --target-host root@target &>/dev/console") ''; })