nixos-rebuild-ng: ignore non-directories in upgrade_channels

This commit is contained in:
Thiago Kenji Okada
2024-11-30 17:54:32 +00:00
parent cfe42fba1c
commit f72572c147
2 changed files with 3 additions and 2 deletions
@@ -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()
@@ -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)