Skip to content

Add omarchy-toggle-ip-mode (DHCP/static IPv4 switcher)#4905

Closed
ElvarThorS wants to merge 1 commit intobasecamp:devfrom
ElvarThorS:toggle-ip-mode
Closed

Add omarchy-toggle-ip-mode (DHCP/static IPv4 switcher)#4905
ElvarThorS wants to merge 1 commit intobasecamp:devfrom
ElvarThorS:toggle-ip-mode

Conversation

@ElvarThorS
Copy link
Copy Markdown

Summary

  • Add bin/omarchy-toggle-ip-mode.
  • It switches a selected systemd-networkd interface between DHCP and static IPv4.
  • It works both interactively and with flags.

What it does

  • Lists managed interfaces and shows each with subnet + usable IP range.
  • Preselects the default-route interface for quick use.
  • Default toggle behavior:
    • if static override exists -> remove it and return to DHCP
    • otherwise -> ask for a static IP and create the override
  • Supports non-interactive usage:
    • --iface <iface>
    • --dhcp
    • --static <ip>
  • Remembers the last static IP per interface.

Design choices

  • Writes only a drop-in override at /etc/systemd/network/<profile>.network.d/90-omarchy-ip-mode.conf.
  • Does not edit base .network files.
  • Resolves the profile in this order:
    1. networkctl reported file
    2. common Omarchy profile names
    3. scan of standard networkd profile paths
  • Uses gum when available, with shell prompt fallback.
  • Restarts systemd-networkd and systemd-resolved after changes.

Safety checks and failure handling

  • Refuses to write if no valid .network profile is found.
  • Validates IPv4 format, subnet match, usable host range, and rejects gateway IP as static.
  • Handles systems with no default route by choosing a fallback managed interface.
  • --dhcp is idempotent (prints a no-op message if already DHCP).
  • Validates CLI flags and prints clear errors for invalid combinations/values.

Scope

  • Adds one tracked file: bin/omarchy-toggle-ip-mode.
  • No migrations.
  • No edits to existing scripts or base network profile files.

Runtime artifacts (created on user systems)

  • State file: ~/.local/state/omarchy/ip-mode/last-static-<iface>
  • Networkd override: /etc/systemd/network/<profile>.network.d/90-omarchy-ip-mode.conf (created/updated in static mode, removed in DHCP mode)

Copilot AI review requested due to automatic review settings March 5, 2026 08:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.


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

You can also share your feedback on Copilot code review. Take the survey.

@dhh
Copy link
Copy Markdown
Member

dhh commented Mar 7, 2026

Interesting idea, but not something that's common enough to warrant over 500 lines of code to the project. Thanks for the suggestion, though!

@dhh dhh closed this Mar 7, 2026
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.

3 participants