cli: only use sudo when deploying locally
This commit is contained in:
@@ -156,21 +156,24 @@ def deploy_machines(machines: list[Machine]) -> None:
|
|||||||
switch_cmd = ["nixos-rebuild", "switch", *nix_options]
|
switch_cmd = ["nixos-rebuild", "switch", *nix_options]
|
||||||
test_cmd = ["nixos-rebuild", "test", *nix_options]
|
test_cmd = ["nixos-rebuild", "test", *nix_options]
|
||||||
|
|
||||||
|
become_root = True
|
||||||
|
|
||||||
target_host: Host | None = host.meta.get("target_host")
|
target_host: Host | None = host.meta.get("target_host")
|
||||||
if target_host:
|
if target_host:
|
||||||
|
become_root = False
|
||||||
switch_cmd.extend(["--target-host", target_host.target])
|
switch_cmd.extend(["--target-host", target_host.target])
|
||||||
test_cmd.extend(["--target-host", target_host.target])
|
test_cmd.extend(["--target-host", target_host.target])
|
||||||
|
|
||||||
if (target_host and target_host.user != "root") or host.user != "root":
|
if target_host.user != "root":
|
||||||
switch_cmd.extend(["--use-remote-sudo"])
|
switch_cmd.extend(["--use-remote-sudo"])
|
||||||
test_cmd.extend(["--use-remote-sudo"])
|
test_cmd.extend(["--use-remote-sudo"])
|
||||||
|
|
||||||
env = host.nix_ssh_env(None)
|
env = host.nix_ssh_env(None)
|
||||||
ret = host.run(
|
ret = host.run(
|
||||||
switch_cmd,
|
switch_cmd,
|
||||||
RunOpts(check=False, msg_color=MsgColor(stderr=AnsiColor.DEFAULT)),
|
RunOpts(check=False, msg_color=MsgColor(stderr=AnsiColor.DEFAULT)),
|
||||||
extra_env=env,
|
extra_env=env,
|
||||||
become_root=True,
|
become_root=become_root,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Last output line (config store path) is printed to stdout instead of stderr
|
# Last output line (config store path) is printed to stdout instead of stderr
|
||||||
@@ -193,7 +196,7 @@ def deploy_machines(machines: list[Machine]) -> None:
|
|||||||
test_cmd if is_mobile else switch_cmd,
|
test_cmd if is_mobile else switch_cmd,
|
||||||
RunOpts(msg_color=MsgColor(stderr=AnsiColor.DEFAULT)),
|
RunOpts(msg_color=MsgColor(stderr=AnsiColor.DEFAULT)),
|
||||||
extra_env=env,
|
extra_env=env,
|
||||||
become_root=True,
|
become_root=become_root,
|
||||||
)
|
)
|
||||||
|
|
||||||
with AsyncRuntime() as runtime:
|
with AsyncRuntime() as runtime:
|
||||||
|
|||||||
Reference in New Issue
Block a user