Skip to content

refactor: replace sudo_prefix with run_as_root abstraction#18

Merged
ethannortharc merged 1 commit intomainfrom
fix/lima-run-as-root
Mar 11, 2026
Merged

refactor: replace sudo_prefix with run_as_root abstraction#18
ethannortharc merged 1 commit intomainfrom
fix/lima-run-as-root

Conversation

@ethannortharc
Copy link
Copy Markdown
Owner

Summary

  • Replaces the flawed sudo_prefix() string-prepend approach with Runtime::run_as_root(name, cmd)
  • sudo_prefix() put sudo before individual commands, but sudo strips env vars — export NIX_PATH=... && sudo nixos-rebuild switch lost NIX_PATH, breaking Lima/macOS provisioning
  • run_as_root() wraps the entire command inside the sudo boundary:
    • Incus: bash -lc <cmd> (already root)
    • Lima: sudo bash -lc <cmd> (elevate entire invocation, env vars preserved)
  • Updated all callers: provision.rs, overlay.rs, nix/rebuild.rs

Test plan

  • cargo build succeeds
  • cargo test — all 67 tests pass
  • Test on macOS: devbox destroy --name test2 && devbox create --name test2 --tools rust,go
  • Test on Linux: devbox destroy --name hive-dev && devbox create --name hive-dev --tools go

🤖 Generated with Claude Code

…bstraction

The previous sudo_prefix() approach prepended "sudo" before individual
commands, but sudo strips environment variables — so commands like
"export NIX_PATH=... && sudo nixos-rebuild switch" lost NIX_PATH
across the sudo boundary, breaking Lima/macOS provisioning.

New approach: Runtime::run_as_root(name, cmd) wraps the ENTIRE command
inside the sudo boundary:
- Incus: bash -lc <cmd> (already root, login shell for PATH)
- Lima:  sudo bash -lc <cmd> (elevate entire invocation)

This keeps env vars, PATH, and privilege escalation all within one
consistent boundary. Removes sudo_prefix() entirely.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ethannortharc ethannortharc merged commit 6c6bace into main Mar 11, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant