nixos-rebuild-ng: add from_host in nix.copy_closure
This commit is contained in:
@@ -210,7 +210,7 @@ def execute(argv: list[str]) -> None:
|
||||
no_out_link=True,
|
||||
**build_flags,
|
||||
)
|
||||
nix.copy_closure(path_to_config, target_host, **copy_flags)
|
||||
nix.copy_closure(path_to_config, target_host, None, **copy_flags)
|
||||
nix.set_profile(profile, path_to_config, target_host, sudo=args.sudo)
|
||||
nix.switch_to_configuration(
|
||||
path_to_config,
|
||||
@@ -253,7 +253,7 @@ def execute(argv: list[str]) -> None:
|
||||
nix.switch_to_configuration(
|
||||
path_to_config,
|
||||
action,
|
||||
target_host,
|
||||
target_host=None,
|
||||
sudo=args.sudo,
|
||||
specialisation=args.specialisation,
|
||||
)
|
||||
|
||||
@@ -27,10 +27,14 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def copy_closure(
|
||||
closure: Path,
|
||||
target_host: Remote | None,
|
||||
to_host: Remote | None,
|
||||
from_host: Remote | None = None,
|
||||
**copy_flags: Args,
|
||||
) -> None:
|
||||
host = target_host
|
||||
"""Copy a nix closure to or from host to localhost.
|
||||
|
||||
Also supports copying a closure from a remote to another remote."""
|
||||
host = to_host or from_host
|
||||
if not host:
|
||||
return
|
||||
|
||||
@@ -38,11 +42,12 @@ def copy_closure(
|
||||
[
|
||||
"nix-copy-closure",
|
||||
*dict_to_flags(copy_flags),
|
||||
"--to",
|
||||
"--to" if to_host else "--from",
|
||||
host.host,
|
||||
closure,
|
||||
],
|
||||
extra_env={"NIX_SSHOPTS": " ".join(host.opts)},
|
||||
remote=from_host if to_host else None,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -18,11 +18,28 @@ def test_copy_closure(mock_run: Any) -> None:
|
||||
n.copy_closure(closure, None)
|
||||
mock_run.assert_not_called()
|
||||
|
||||
target_host = m.Remote("user@host", ["--ssh", "opt"], None)
|
||||
target_host = m.Remote("user@target.host", ["--ssh", "target-opt"], None)
|
||||
build_host = m.Remote("user@build.host", ["--ssh", "build-opt"], None)
|
||||
|
||||
n.copy_closure(closure, target_host)
|
||||
mock_run.assert_called_with(
|
||||
["nix-copy-closure", "--to", "user@host", closure],
|
||||
extra_env={"NIX_SSHOPTS": "--ssh opt"},
|
||||
["nix-copy-closure", "--to", "user@target.host", closure],
|
||||
extra_env={"NIX_SSHOPTS": "--ssh target-opt"},
|
||||
remote=None,
|
||||
)
|
||||
|
||||
n.copy_closure(closure, None, build_host)
|
||||
mock_run.assert_called_with(
|
||||
["nix-copy-closure", "--from", "user@build.host", closure],
|
||||
extra_env={"NIX_SSHOPTS": "--ssh build-opt"},
|
||||
remote=None,
|
||||
)
|
||||
|
||||
n.copy_closure(closure, target_host, build_host)
|
||||
mock_run.assert_called_with(
|
||||
["nix-copy-closure", "--to", "user@target.host", closure],
|
||||
extra_env={"NIX_SSHOPTS": "--ssh target-opt"},
|
||||
remote=build_host,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user