Skip to content

fix(kyber): resolve sudo not found in enableIpForwarding activation - #1440

Merged
shunkakinoki merged 1 commit into
mainfrom
quizzical-stargazing-bear
Apr 12, 2026
Merged

fix(kyber): resolve sudo not found in enableIpForwarding activation#1440
shunkakinoki merged 1 commit into
mainfrom
quizzical-stargazing-bear

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Apr 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • The enableIpForwarding home-manager activation hook used bare sudo which is not on PATH during activation, causing command not found on make nix-switch
  • Replaced with the same sudo discovery pattern used by the tailscale module (checks command -v sudo, /run/wrappers/bin/sudo, /usr/bin/sudo, doas)
  • Includes DRY_RUN_CMD support consistent with other activation hooks

Test plan

  • Run make nix-switch on kyber - should no longer fail with sudo: command not found
  • Verify IP forwarding is enabled after activation (cat /proc/sys/net/ipv4/ip_forward)

Summary by cubic

Fixes the kyber Home Manager activation error where enableIpForwarding used sudo that wasn’t on PATH, breaking make nix-switch. Adds a robust root command helper and DRY_RUN_CMD support so IP forwarding is applied reliably.

  • Bug Fixes
    • Replace bare sudo with discovery of sudo (PATH, /run/wrappers/bin/sudo, /usr/bin/sudo) or doas; fail if neither is available and not root, matching the tailscale module pattern.
    • Add run_root_cmd wrapper that honors DRY_RUN_CMD and use it for sysctl and tee.

Written for commit 327d5fd. Summary will update on new commits.

Use sudo discovery pattern (checking PATH, /run/wrappers/bin/sudo,
/usr/bin/sudo, doas) consistent with the tailscale module, instead of
bare `sudo` which is not on PATH during home-manager activation.

Closes the `command not found: sudo` error on `make nix-switch`.
@mesa-dot-dev

mesa-dot-dev Bot commented Apr 12, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

Copilot AI review requested due to automatic review settings April 12, 2026 08:06
@coderabbitai

coderabbitai Bot commented Apr 12, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Summary by CodeRabbit

  • Improvements
    • Enhanced system configuration script flexibility by supporting multiple privilege escalation methods.
    • Improved error handling with clearer messaging when required tools are unavailable.
    • Added dry-run mode support for automated configuration testing.

Walkthrough

The home.activation.enableIpForwarding activation script in named-hosts/kyber/default.nix is modified to replace direct sudo usage with a flexible privilege-escalation helper that detects and uses available tools (sudo, doas, or root status). A new run_root_cmd() wrapper applies $DRY_RUN_CMD consistently and handles missing escalation methods gracefully.

Changes

Cohort / File(s) Summary
Privilege Escalation Helper
named-hosts/kyber/default.nix
Replaced direct sudo invocations with a helper function that selects available privilege-escalation command (sudo, doas, or root check); introduced run_root_cmd() wrapper respecting $DRY_RUN_CMD environment variable; added graceful error handling when no escalation method is available.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

bug

Poem

A rabbit hops through privilege trees,
Checking for sudo, doas with ease,
When escalation tools align,
DRY_RUN hops and things run fine,
Root or helper—the choice is free! 🐰

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: replacing bare sudo with a discovery pattern to resolve sudo not found errors in the enableIpForwarding activation hook.
Description check ✅ Passed The description clearly explains the bug (bare sudo not on PATH during activation), the solution (sudo discovery pattern matching tailscale module), and includes a concrete test plan.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch quizzical-stargazing-bear

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mesa-dot-dev

mesa-dot-dev Bot commented Apr 12, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Fixes sudo: command not found error in enableIpForwarding home-manager activation on make nix-switch.

What changed?

  • The enableIpForwarding home-manager activation hook now uses a robust sudo discovery pattern (checks command -v sudo, /run/wrappers/bin/sudo, /usr/bin/sudo, doas)
  • Includes DRY_RUN_CMD support consistent with other activation hooks

Description generated by Mesa. Update settings

@shunkakinoki
shunkakinoki merged commit cd49a38 into main Apr 12, 2026
29 of 30 checks passed
@shunkakinoki
shunkakinoki deleted the quizzical-stargazing-bear branch April 12, 2026 08:07

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a more robust mechanism for handling elevated commands within the Home Manager activation script for Tailscale IP forwarding. It adds detection logic for sudo or doas and a run_root_cmd helper function to manage privilege escalation and dry runs. The review feedback suggests simplifying the command discovery logic using a loop for better maintainability and recommends using absolute Nix store paths for utilities like sysctl and tee to ensure reliability across different environments.

Comment on lines +152 to +166
SUDO_CMD=""
if command -v sudo >/dev/null 2>&1; then
SUDO_CMD="sudo"
elif [ -x /run/wrappers/bin/sudo ]; then
SUDO_CMD="/run/wrappers/bin/sudo"
elif [ -x /usr/bin/sudo ]; then
SUDO_CMD="/usr/bin/sudo"
elif command -v doas >/dev/null 2>&1; then
SUDO_CMD="doas"
elif [ -x /usr/bin/doas ]; then
SUDO_CMD="/usr/bin/doas"
elif [ "$(id -u)" -ne 0 ]; then
echo "IP forwarding requires root privileges, but sudo/doas is not available." >&2
exit 1
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for discovering an elevated command helper (sudo/doas) is quite verbose and duplicated from the tailscale module. Using a loop improves maintainability and readability. Additionally, to further resolve the PATH issues that prompted this PR, consider using absolute Nix store paths for other utilities like sysctl (e.g., ${pkgs.procps}/bin/sysctl) and tee (e.g., ${pkgs.coreutils}/bin/tee), as is done with rage and gnupg elsewhere in this file.

          SUDO_CMD=""
          for cmd in "sudo" "/run/wrappers/bin/sudo" "/usr/bin/sudo" "doas" "/usr/bin/doas"; do
            if command -v "$cmd" >/dev/null 2>&1 || [ -x "$cmd" ]; then
              SUDO_CMD="$cmd"
              break
            fi
          done

          if [ -z "$SUDO_CMD" ] && [ "$(id -u)" -ne 0 ]; then
            echo "IP forwarding requires root privileges, but sudo/doas is not available." >&2
            exit 1
          fi

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes the enableIpForwarding home-manager activation hook on kyber so it can reliably run privileged commands during activation (when sudo isn’t on PATH).

Changes:

  • Add discovery logic for an elevated command helper (sudo via command -v, wrapper paths, or doas)
  • Route privileged operations through a run_root_cmd helper with DRY_RUN_CMD support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +163 to +172
elif [ "$(id -u)" -ne 0 ]; then
echo "IP forwarding requires root privileges, but sudo/doas is not available." >&2
exit 1
fi

run_root_cmd() {
if [ -n "$SUDO_CMD" ]; then
''${DRY_RUN_CMD:-} "$SUDO_CMD" "$@"
else
''${DRY_RUN_CMD:-} "$@"
Comment on lines 176 to 180
if [ "$(cat /proc/sys/net/ipv4/ip_forward)" != "1" ]; then
echo "Enabling IP forwarding for Tailscale exit node..."
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv6.conf.all.forwarding=1
run_root_cmd sysctl -w net.ipv4.ip_forward=1
run_root_cmd sysctl -w net.ipv6.conf.all.forwarding=1
fi
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.

2 participants