clan-cli: Fix breakage if machines update

This commit is contained in:
Qubasa
2024-10-08 03:38:41 +02:00
parent 2efe5daeab
commit 528f9f9684
2 changed files with 6 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
import argparse import argparse
import json import json
import logging import logging
import os
import shlex import shlex
import sys import sys
@@ -32,7 +33,7 @@ def is_path_input(node: dict[str, dict[str, str]]) -> bool:
def upload_sources(machine: Machine, always_upload_source: bool = False) -> str: def upload_sources(machine: Machine, always_upload_source: bool = False) -> str:
host = machine.build_host host = machine.build_host
env = host.nix_ssh_env() env = host.nix_ssh_env(os.environ.copy())
if not always_upload_source: if not always_upload_source:
flake_url = ( flake_url = (
@@ -119,8 +120,6 @@ def deploy_machine(machines: MachineGroup) -> None:
machine, machine,
) )
env = host.nix_ssh_env()
cmd = [ cmd = [
"nixos-rebuild", "nixos-rebuild",
"switch", "switch",
@@ -142,6 +141,7 @@ def deploy_machine(machines: MachineGroup) -> None:
target_host = f"{target_host.user or 'root'}@{target_host.host}" target_host = f"{target_host.user or 'root'}@{target_host.host}"
cmd.extend(["--target-host", target_host]) cmd.extend(["--target-host", target_host])
env = host.nix_ssh_env(None)
ret = host.run(cmd, extra_env=env, check=False) ret = host.run(cmd, extra_env=env, check=False)
# re-retry switch if the first time fails # re-retry switch if the first time fails
if ret.returncode != 0: if ret.returncode != 0:

View File

@@ -513,8 +513,9 @@ class Host:
timeout=timeout, timeout=timeout,
) )
def nix_ssh_env(self) -> dict[str, str]: def nix_ssh_env(self, env: dict[str, str] | None) -> dict[str, str]:
env = os.environ.copy() if env is None:
env = {}
env["NIX_SSHOPTS"] = " ".join(self.ssh_cmd_opts()) env["NIX_SSHOPTS"] = " ".join(self.ssh_cmd_opts())
return env return env