nixos-rebuild: set SSHOPTS earlier so that we resolve the correct hostname (#354283)
This commit is contained in:
@@ -427,6 +427,25 @@ if [[ -z $flake && -e /etc/nixos/flake.nix && -z $noFlake ]]; then
|
|||||||
flake="$(dirname "$(readlink -f /etc/nixos/flake.nix)")"
|
flake="$(dirname "$(readlink -f /etc/nixos/flake.nix)")"
|
||||||
fi
|
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
|
||||||
|
done
|
||||||
|
rm -rf "$tmpDir"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
SSHOPTS="$NIX_SSHOPTS -o ControlMaster=auto -o ControlPath=$tmpDir/ssh-%n -o ControlPersist=60"
|
||||||
|
|
||||||
# For convenience, use the hostname as the default configuration to
|
# For convenience, use the hostname as the default configuration to
|
||||||
# build from the flake.
|
# build from the flake.
|
||||||
if [[ -n $flake ]]; then
|
if [[ -n $flake ]]; then
|
||||||
@@ -450,23 +469,6 @@ if [[ ! -z "$specialisation" && ! "$action" = switch && ! "$action" = test ]]; t
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
|
||||||
done
|
|
||||||
rm -rf "$tmpDir"
|
|
||||||
}
|
|
||||||
trap cleanup EXIT
|
|
||||||
|
|
||||||
|
|
||||||
# Re-execute nixos-rebuild from the Nixpkgs tree.
|
# Re-execute nixos-rebuild from the Nixpkgs tree.
|
||||||
if [[ -z $_NIXOS_REBUILD_REEXEC && -n $canRun && -z $fast ]]; then
|
if [[ -z $_NIXOS_REBUILD_REEXEC && -n $canRun && -z $fast ]]; then
|
||||||
@@ -510,8 +512,6 @@ if [ "$action" = edit ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SSHOPTS="$NIX_SSHOPTS -o ControlMaster=auto -o ControlPath=$tmpDir/ssh-%n -o ControlPersist=60"
|
|
||||||
|
|
||||||
# First build Nix, since NixOS may require a newer version than the
|
# First build Nix, since NixOS may require a newer version than the
|
||||||
# current one.
|
# current one.
|
||||||
if [[ -n "$rollback" || "$action" = dry-build ]]; then
|
if [[ -n "$rollback" || "$action" = dry-build ]]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user