update/upload_sources remove ssh_control_master again from upload_sources
This commit is contained in:
@@ -44,68 +44,63 @@ def is_local_input(node: dict[str, dict[str, str]]) -> bool:
|
|||||||
return local
|
return local
|
||||||
|
|
||||||
|
|
||||||
def upload_sources(machine: Machine, host: Remote) -> str:
|
def upload_sources(machine: Machine, ssh: Remote) -> str:
|
||||||
with host.ssh_control_master() as ssh:
|
env = ssh.nix_ssh_env(os.environ.copy())
|
||||||
env = ssh.nix_ssh_env(os.environ.copy())
|
|
||||||
|
|
||||||
flake_url = (
|
flake_url = (
|
||||||
str(machine.flake.path)
|
str(machine.flake.path) if machine.flake.is_local else machine.flake.identifier
|
||||||
if machine.flake.is_local
|
)
|
||||||
else machine.flake.identifier
|
flake_data = nix_metadata(flake_url)
|
||||||
)
|
has_path_inputs = any(
|
||||||
flake_data = nix_metadata(flake_url)
|
is_local_input(node) for node in flake_data["locks"]["nodes"].values()
|
||||||
has_path_inputs = any(
|
)
|
||||||
is_local_input(node) for node in flake_data["locks"]["nodes"].values()
|
|
||||||
)
|
|
||||||
|
|
||||||
if not has_path_inputs:
|
if not has_path_inputs:
|
||||||
# Just copy the flake to the remote machine, we can substitute other inputs there.
|
# Just copy the flake to the remote machine, we can substitute other inputs there.
|
||||||
path = flake_data["path"]
|
path = flake_data["path"]
|
||||||
cmd = nix_command(
|
|
||||||
[
|
|
||||||
"copy",
|
|
||||||
"--to",
|
|
||||||
f"ssh://{host.target}",
|
|
||||||
"--no-check-sigs",
|
|
||||||
path,
|
|
||||||
]
|
|
||||||
)
|
|
||||||
run(
|
|
||||||
cmd,
|
|
||||||
RunOpts(
|
|
||||||
env=env,
|
|
||||||
needs_user_terminal=True,
|
|
||||||
error_msg="failed to upload sources",
|
|
||||||
prefix=machine.name,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
return path
|
|
||||||
|
|
||||||
# Slow path: we need to upload all sources to the remote machine
|
|
||||||
cmd = nix_command(
|
cmd = nix_command(
|
||||||
[
|
[
|
||||||
"flake",
|
"copy",
|
||||||
"archive",
|
|
||||||
"--to",
|
"--to",
|
||||||
f"ssh://{host.target}",
|
f"ssh://{ssh.target}",
|
||||||
"--json",
|
"--no-check-sigs",
|
||||||
flake_url,
|
path,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
proc = run(
|
run(
|
||||||
cmd,
|
cmd,
|
||||||
RunOpts(
|
RunOpts(
|
||||||
env=env, needs_user_terminal=True, error_msg="failed to upload sources"
|
env=env,
|
||||||
|
needs_user_terminal=True,
|
||||||
|
error_msg="failed to upload sources",
|
||||||
|
prefix=machine.name,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
return path
|
||||||
|
|
||||||
try:
|
# Slow path: we need to upload all sources to the remote machine
|
||||||
return json.loads(proc.stdout)["path"]
|
cmd = nix_command(
|
||||||
except (json.JSONDecodeError, OSError) as e:
|
[
|
||||||
msg = (
|
"flake",
|
||||||
f"failed to parse output of {shlex.join(cmd)}: {e}\nGot: {proc.stdout}"
|
"archive",
|
||||||
)
|
"--to",
|
||||||
raise ClanError(msg) from e
|
f"ssh://{ssh.target}",
|
||||||
|
"--json",
|
||||||
|
flake_url,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
proc = run(
|
||||||
|
cmd,
|
||||||
|
RunOpts(
|
||||||
|
env=env, needs_user_terminal=True, error_msg="failed to upload sources"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
return json.loads(proc.stdout)["path"]
|
||||||
|
except (json.JSONDecodeError, OSError) as e:
|
||||||
|
msg = f"failed to parse output of {shlex.join(cmd)}: {e}\nGot: {proc.stdout}"
|
||||||
|
raise ClanError(msg) from e
|
||||||
|
|
||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
|
|||||||
Reference in New Issue
Block a user