nixos-rebuild-ng: do not try to copy closure when running dry-build (#444166)
This commit is contained in:
@@ -192,12 +192,15 @@ def _build_system(
|
||||
build_flags=build_flags | {"no_out_link": no_link, "dry_run": dry_run},
|
||||
)
|
||||
|
||||
nix.copy_closure(
|
||||
path_to_config,
|
||||
to_host=target_host,
|
||||
from_host=build_host,
|
||||
copy_flags=copy_flags,
|
||||
)
|
||||
# In dry_run mode there is nothing to copy
|
||||
# https://github.com/NixOS/nixpkgs/issues/444156
|
||||
if not dry_run:
|
||||
nix.copy_closure(
|
||||
path_to_config,
|
||||
to_host=target_host,
|
||||
from_host=build_host,
|
||||
copy_flags=copy_flags,
|
||||
)
|
||||
|
||||
return path_to_config
|
||||
|
||||
|
||||
@@ -985,6 +985,74 @@ def test_execute_build(mock_run: Mock, tmp_path: Path) -> None:
|
||||
)
|
||||
|
||||
|
||||
@patch("subprocess.run", autospec=True)
|
||||
def test_execute_build_dry_run_build_and_target_remote(
|
||||
mock_run: Mock, tmp_path: Path
|
||||
) -> None:
|
||||
config_path = tmp_path / "test"
|
||||
config_path.touch()
|
||||
mock_run.side_effect = [
|
||||
CompletedProcess([], 0, str(config_path)),
|
||||
CompletedProcess([], 0),
|
||||
CompletedProcess([], 0, str(config_path)),
|
||||
]
|
||||
|
||||
nr.execute(
|
||||
[
|
||||
"nixos-rebuild",
|
||||
"dry-build",
|
||||
"--flake",
|
||||
"/path/to/config#hostname",
|
||||
"--build-host",
|
||||
"user@build-host",
|
||||
"--target-host",
|
||||
"user@target-host",
|
||||
]
|
||||
)
|
||||
|
||||
assert mock_run.call_count == 3
|
||||
mock_run.assert_has_calls(
|
||||
[
|
||||
call(
|
||||
[
|
||||
"nix",
|
||||
"--extra-experimental-features",
|
||||
"nix-command flakes",
|
||||
"eval",
|
||||
"--raw",
|
||||
'/path/to/config#nixosConfigurations."hostname".config.system.build.toplevel.drvPath',
|
||||
],
|
||||
check=True,
|
||||
stdout=PIPE,
|
||||
**DEFAULT_RUN_KWARGS,
|
||||
),
|
||||
call(
|
||||
["nix-copy-closure", "--to", "user@build-host", config_path],
|
||||
check=True,
|
||||
**DEFAULT_RUN_KWARGS,
|
||||
),
|
||||
call(
|
||||
[
|
||||
"ssh",
|
||||
*nr.process.SSH_DEFAULT_OPTS,
|
||||
"user@build-host",
|
||||
"--",
|
||||
"nix",
|
||||
"--extra-experimental-features",
|
||||
"'nix-command flakes'",
|
||||
"build",
|
||||
f"'{config_path}^*'",
|
||||
"--print-out-paths",
|
||||
"--dry-run",
|
||||
],
|
||||
check=True,
|
||||
stdout=PIPE,
|
||||
**DEFAULT_RUN_KWARGS,
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@patch("subprocess.run", autospec=True)
|
||||
def test_execute_test_flake(mock_run: Mock, tmp_path: Path) -> None:
|
||||
config_path = tmp_path / "test"
|
||||
|
||||
Reference in New Issue
Block a user