From c20ef42f01aeb6a40e111cb810a031e5c7cd9ccf Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Sat, 21 Jun 2025 01:01:32 +0200 Subject: [PATCH] nixos-rebuild-ng: skip broken test for Nix < 2.18 The mock test for building with remote, but distinct target and build host checks a bunch of internals (how many shell commands are executed, which ones exactly) that are special cased on WITH_NIX_2_18, so the test breaks when that is false. I've opted to simply skip the test for now since the expected call list is very annoying to keep maintained and updated for multiple versions. This should fix NixOS configurations with config nix.package.version < 2.18. To keep it that way, I've added nixos-rebuild-ng with some nixVersions to passthru.tests that aren't likely to be removed in the short term. --- pkgs/by-name/ni/nixos-rebuild-ng/package.nix | 16 +++++++++++++++- .../ni/nixos-rebuild-ng/src/tests/test_main.py | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/package.nix b/pkgs/by-name/ni/nixos-rebuild-ng/package.nix index 8590cc90549a..f02be7888d09 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/package.nix +++ b/pkgs/by-name/ni/nixos-rebuild-ng/package.nix @@ -5,7 +5,6 @@ installShellFiles, mkShell, nix, - nixosTests, python3, python3Packages, runCommand, @@ -16,6 +15,10 @@ # Very long tmp dirs lead to "too long for Unix domain socket" # SSH ControlPath errors. Especially macOS sets long TMPDIR paths. withTmpdir ? if stdenv.hostPlatform.isDarwin then "/tmp" else null, + # passthru.tests + nixosTests, + nixVersions, + nixos-rebuild-ng, }: let executable = if withNgSuffix then "nixos-rebuild-ng" else "nixos-rebuild"; @@ -105,6 +108,17 @@ python3Packages.buildPythonApplication rec { }; tests = { + with_nix_latest = nixos-rebuild-ng.override { + nix = nixVersions.latest; + }; + with_nix_stable = nixos-rebuild-ng.override { + nix = nixVersions.stable; + }; + with_nix_2_3 = nixos-rebuild-ng.override { + # oldest / minimum supported version in nixpkgs + nix = nixVersions.nix_2_3; + }; + inherit (nixosTests) nixos-rebuild-install-bootloader-ng nixos-rebuild-specialisations-ng diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py b/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py index 22b7054000a8..f65975b3e22c 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py +++ b/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py @@ -11,6 +11,7 @@ import pytest from pytest import MonkeyPatch import nixos_rebuild as nr +from nixos_rebuild.constants import WITH_NIX_2_18 from .helpers import get_qualified_name @@ -514,6 +515,10 @@ def test_execute_nix_switch_flake(mock_run: Mock, tmp_path: Path) -> None: @patch("subprocess.run", autospec=True) @patch("uuid.uuid4", autospec=True) @patch(get_qualified_name(nr.cleanup_ssh), autospec=True) +@pytest.mark.skipif( + not WITH_NIX_2_18, + reason="Tests internal logic based on the assumption that Nix >= 2.18", +) def test_execute_nix_switch_build_target_host( mock_cleanup_ssh: Mock, mock_uuid4: Mock,