From 5bd607a8ad22b42dfe5a5a655695a952e87e5e13 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Tue, 8 Oct 2024 03:02:59 +0200 Subject: [PATCH] clan-cli: Fix bug where --host-key-check is not applied to build-host --- pkgs/clan-cli/clan_cli/machines/update.py | 10 +++++----- pkgs/clan-cli/clan_cli/ssh/__init__.py | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/update.py b/pkgs/clan-cli/clan_cli/machines/update.py index ee641fcd9..f8d0fe2e1 100644 --- a/pkgs/clan-cli/clan_cli/machines/update.py +++ b/pkgs/clan-cli/clan_cli/machines/update.py @@ -1,7 +1,6 @@ import argparse import json import logging -import os import shlex import sys @@ -33,8 +32,7 @@ def is_path_input(node: dict[str, dict[str, str]]) -> bool: def upload_sources(machine: Machine, always_upload_source: bool = False) -> str: host = machine.build_host - env = os.environ.copy() - env["NIX_SSHOPTS"] = " ".join(host.ssh_cmd_opts()) + env = host.nix_ssh_env() if not always_upload_source: flake_url = ( @@ -121,6 +119,8 @@ def deploy_machine(machines: MachineGroup) -> None: machine, ) + env = host.nix_ssh_env() + cmd = [ "nixos-rebuild", "switch", @@ -142,10 +142,10 @@ def deploy_machine(machines: MachineGroup) -> None: target_host = f"{target_host.user or 'root'}@{target_host.host}" cmd.extend(["--target-host", target_host]) - ret = host.run(cmd, check=False) + ret = host.run(cmd, extra_env=env, check=False) # re-retry switch if the first time fails if ret.returncode != 0: - ret = host.run(cmd) + ret = host.run(cmd, extra_env=env) machines.run_function(deploy) diff --git a/pkgs/clan-cli/clan_cli/ssh/__init__.py b/pkgs/clan-cli/clan_cli/ssh/__init__.py index 8defcf1c3..8304bfdd0 100644 --- a/pkgs/clan-cli/clan_cli/ssh/__init__.py +++ b/pkgs/clan-cli/clan_cli/ssh/__init__.py @@ -143,6 +143,9 @@ class HostKeyCheck(Enum): description = "Choose from: " + ", ".join(HostKeyCheck.__members__) raise ClanError(msg, description=description) + def __str__(self) -> str: + return self.name.lower() + def to_ssh_opt(self) -> list[str]: match self: case HostKeyCheck.STRICT: @@ -510,6 +513,11 @@ class Host: timeout=timeout, ) + def nix_ssh_env(self) -> dict[str, str]: + env = os.environ.copy() + env["NIX_SSHOPTS"] = " ".join(self.ssh_cmd_opts()) + return env + def ssh_cmd_opts( self, verbose_ssh: bool = False,