Skip to content

Commit d75ba2e

Browse files
committed
nixos-rebuild-ng: run upgrade_channels with sudo
Fix #424749.
1 parent e941e71 commit d75ba2e

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def execute(argv: list[str]) -> None:
281281
copy_flags = common_flags | vars(args_groups["copy_flags"])
282282

283283
if args.upgrade or args.upgrade_all:
284-
nix.upgrade_channels(bool(args.upgrade_all))
284+
nix.upgrade_channels(args.upgrade_all, args.sudo)
285285

286286
action = Action(args.action)
287287
# Only run shell scripts from the Nixpkgs tree if the action is

pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ def switch_to_configuration(
693693
)
694694

695695

696-
def upgrade_channels(all_channels: bool = False) -> None:
696+
def upgrade_channels(all_channels: bool = False, sudo: bool = False) -> None:
697697
"""Upgrade channels for classic Nix.
698698
699699
It will either upgrade just the `nixos` channel (including any channel
@@ -705,4 +705,8 @@ def upgrade_channels(all_channels: bool = False) -> None:
705705
or channel_path.name == "nixos"
706706
or (channel_path / ".update-on-nixos-rebuild").exists()
707707
):
708-
run_wrapper(["nix-channel", "--update", channel_path.name], check=False)
708+
run_wrapper(
709+
["nix-channel", "--update", channel_path.name],
710+
check=False,
711+
sudo=sudo,
712+
)

pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -838,15 +838,19 @@ def test_switch_to_configuration_with_systemd_run(
838838
@patch("pathlib.Path.is_dir", autospec=True, return_value=True)
839839
def test_upgrade_channels(mock_is_dir: Mock, mock_glob: Mock) -> None:
840840
with patch(get_qualified_name(n.run_wrapper, n), autospec=True) as mock_run:
841-
n.upgrade_channels(False)
842-
mock_run.assert_called_once_with(["nix-channel", "--update", "nixos"], check=False)
841+
n.upgrade_channels(all_channels=False, sudo=True)
842+
mock_run.assert_called_once_with(
843+
["nix-channel", "--update", "nixos"], check=False, sudo=True
844+
)
843845

844846
with patch(get_qualified_name(n.run_wrapper, n), autospec=True) as mock_run:
845-
n.upgrade_channels(True)
847+
n.upgrade_channels(all_channels=True, sudo=False)
846848
mock_run.assert_has_calls(
847849
[
848-
call(["nix-channel", "--update", "nixos"], check=False),
849-
call(["nix-channel", "--update", "nixos-hardware"], check=False),
850-
call(["nix-channel", "--update", "home-manager"], check=False),
850+
call(["nix-channel", "--update", "nixos"], check=False, sudo=False),
851+
call(
852+
["nix-channel", "--update", "nixos-hardware"], check=False, sudo=False
853+
),
854+
call(["nix-channel", "--update", "home-manager"], check=False, sudo=False),
851855
]
852856
)

0 commit comments

Comments
 (0)