fix build host with sudo

This commit is contained in:
Jörg Thalheim
2025-07-08 12:59:27 +02:00
parent b84df095a2
commit b42395234d

View File

@@ -119,11 +119,9 @@ def run_machine_deploy(
with ExitStack() as stack: with ExitStack() as stack:
target_host = stack.enter_context(target_host.ssh_control_master()) target_host = stack.enter_context(target_host.ssh_control_master())
if build_host is not None: if build_host:
build_host = stack.enter_context(build_host.ssh_control_master()) build_host = stack.enter_context(build_host.ssh_control_master())
host = build_host or target_host
sudo_host = stack.enter_context(target_host.become_root()) sudo_host = stack.enter_context(target_host.become_root())
generate_facts([machine], service=None, regenerate=False) generate_facts([machine], service=None, regenerate=False)
@@ -132,7 +130,10 @@ def run_machine_deploy(
upload_secrets(machine, sudo_host) upload_secrets(machine, sudo_host)
upload_secret_vars(machine, sudo_host) upload_secret_vars(machine, sudo_host)
path = upload_sources(machine, sudo_host) if build_host:
path = upload_sources(machine, build_host)
else:
path = upload_sources(machine, target_host)
nix_options = machine.flake.nix_options if machine.flake.nix_options else [] nix_options = machine.flake.nix_options if machine.flake.nix_options else []
@@ -174,11 +175,13 @@ def run_machine_deploy(
*nix_options, *nix_options,
] ]
if become_root: if become_root and not build_host:
host = sudo_host target_host = sudo_host
remote_env = host.nix_ssh_env(control_master=False) deploy_host = build_host if build_host else target_host
ret = host.run(
remote_env = deploy_host.nix_ssh_env(control_master=False)
ret = deploy_host.run(
switch_cmd, switch_cmd,
RunOpts( RunOpts(
check=False, check=False,
@@ -205,7 +208,7 @@ def run_machine_deploy(
machine.info( machine.info(
"Mobile machine detected, applying workaround deployment method" "Mobile machine detected, applying workaround deployment method"
) )
ret = host.run( ret = deploy_host.run(
["nixos--rebuild", "test", *nix_options] if is_mobile else switch_cmd, ["nixos--rebuild", "test", *nix_options] if is_mobile else switch_cmd,
RunOpts( RunOpts(
log=Log.BOTH, log=Log.BOTH,