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 5247a2991b1b..7cc606561404 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 @@ -471,7 +471,7 @@ def upgrade_channels(all: bool = False) -> None: that has a `.update-on-nixos-rebuild` file) or all. """ for channel_path in Path("/nix/var/nix/profiles/per-user/root/channels/").glob("*"): - if ( + if channel_path.is_dir() and ( all or channel_path.name == "nixos" or (channel_path / ".update-on-nixos-rebuild").exists() 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 317821d5fea0..093cba93ef36 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 @@ -561,7 +561,8 @@ def test_switch_to_configuration(mock_run: Any, monkeypatch: Any) -> None: Path("/nix/var/nix/profiles/per-user/root/channels/home-manager"), ], ) -def test_upgrade_channels(mock_glob: Any) -> None: +@patch(get_qualified_name(n.Path.is_dir, n), autospec=True, return_value=True) +def test_upgrade_channels(mock_is_dir: Any, mock_glob: Any) -> None: with patch(get_qualified_name(n.run_wrapper, n), autospec=True) as mock_run: n.upgrade_channels(False) mock_run.assert_called_with(["nix-channel", "--update", "nixos"], check=False)