nixos-rebuild-ng: fix --build-host and --target-host case

This commit is contained in:
Thiago Kenji Okada 2024-11-29 10:14:43 +00:00
parent 2ac1f78a11
commit 29e9b42022
2 changed files with 11 additions and 3 deletions

View File

@ -46,7 +46,14 @@ def copy_closure(
host.host,
closure,
],
extra_env={"NIX_SSHOPTS": " ".join(host.opts)},
extra_env={
# for the remote to remote case, we can't use host.opts because it
# includes the ControlPane opts that will not work in the remote,
# because the temporary directory that we created will not exist
"NIX_SSHOPTS": os.environ.get("NIX_SSHOPTS", "")
if from_host and to_host
else " ".join(host.opts)
},
remote=from_host if to_host else None,
)

View File

@ -13,7 +13,7 @@ from .helpers import get_qualified_name
@patch(get_qualified_name(n.run_wrapper, n), autospec=True)
def test_copy_closure(mock_run: Any) -> None:
def test_copy_closure(mock_run: Any, monkeypatch: Any) -> None:
closure = Path("/path/to/closure")
n.copy_closure(closure, None)
mock_run.assert_not_called()
@ -35,11 +35,12 @@ def test_copy_closure(mock_run: Any) -> None:
remote=None,
)
monkeypatch.setenv("NIX_SSHOPTS", "--ssh build-target-opt")
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,
extra_env={"NIX_SSHOPTS": "--ssh build-target-opt"},
)