nixos-rebuild-ng: add env var to allow use without systemd-run (#527342)
This commit is contained in:
@@ -379,6 +379,10 @@ NIX_SSHOPTS
|
||||
NIX_SUDOOPTS
|
||||
Additional options to be passed to sudo on the command line.
|
||||
|
||||
NIXOS_REBUILD_NO_SYSTEMD_RUN
|
||||
If set, then *nixos-rebuild* will run without the
|
||||
_systemd-run_ wrapper.
|
||||
|
||||
# FILES
|
||||
|
||||
/etc/nixos/system.nix
|
||||
|
||||
@@ -708,6 +708,8 @@ def switch_to_configuration(
|
||||
"not working in target host"
|
||||
)
|
||||
cmd = []
|
||||
elif os.environ.get("NIXOS_REBUILD_NO_SYSTEMD_RUN"):
|
||||
cmd = []
|
||||
|
||||
run_wrapper(
|
||||
[*cmd, path_to_config / "bin/switch-to-configuration", str(action)],
|
||||
|
||||
@@ -819,6 +819,38 @@ def test_switch_to_configuration_without_systemd_run(
|
||||
)
|
||||
|
||||
|
||||
@patch(get_qualified_name(n.run_wrapper, n), autospec=True)
|
||||
def test_switch_to_configuration_without_systemd_run_env_var(
|
||||
mock_run: Any, monkeypatch: MonkeyPatch
|
||||
) -> None:
|
||||
profile_path = Path("/path/to/profile")
|
||||
mock_run.return_value = CompletedProcess([], 0)
|
||||
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setenv("LOCALE_ARCHIVE", "")
|
||||
mp.setenv("NIXOS_REBUILD_NO_SYSTEMD_RUN", "1")
|
||||
|
||||
n.switch_to_configuration(
|
||||
profile_path,
|
||||
m.Action.SWITCH,
|
||||
elevate=e.NO_ELEVATOR,
|
||||
target_host=None,
|
||||
specialisation=None,
|
||||
install_bootloader=False,
|
||||
)
|
||||
mock_run.assert_called_with(
|
||||
[profile_path / "bin/switch-to-configuration", "switch"],
|
||||
env={
|
||||
"LOCALE_ARCHIVE": e.PRESERVE_ENV,
|
||||
"NIXOS_NO_CHECK": e.PRESERVE_ENV,
|
||||
"NIXOS_INSTALL_BOOTLOADER": "0",
|
||||
},
|
||||
elevate=e.NO_ELEVATOR,
|
||||
remote=None,
|
||||
stdout=sys.stderr,
|
||||
)
|
||||
|
||||
|
||||
@patch(get_qualified_name(n.run_wrapper, n), autospec=True)
|
||||
def test_switch_to_configuration_with_systemd_run(
|
||||
mock_run: Mock, monkeypatch: MonkeyPatch
|
||||
|
||||
Reference in New Issue
Block a user