From 29e9b42022b6cf20b2ca7bc0b6b841c51428fc96 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Fri, 29 Nov 2024 10:14:43 +0000 Subject: [PATCH] nixos-rebuild-ng: fix --build-host and --target-host case --- .../by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py | 9 ++++++++- pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py b/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py index 11d13502e13c..317c04467a5d 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py +++ b/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py @@ -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, ) diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py b/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py index 5a5ee01cb974..712bd09b8704 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py +++ b/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py @@ -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"}, )