Skip to content

About

WireGuard tunnels from NetworkManager in the Omarchy bar: tunnel switching, a live traffic graph and exit IP check.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Omarchy WireGuard

WireGuard tunnels for the Omarchy bar: a status icon with a panel that lists every WireGuard profile NetworkManager knows, switches between them with one click, graphs live traffic and verifies the exit IP.

Profiles are found automatically. To add one:

nmcli connection import type wireguard file my-gateway.conf

Preview

WireGuard panel: live traffic graph and exit IP above the tunnel list

Features

  • Every NetworkManager WireGuard profile, discovered automatically.
  • One tunnel at a time by default: bringing one up takes the others down first, because two full-tunnel gateways break each other's routing.
  • A default tunnel for the power switch, the icon's right-click and the IPC on call. Star any row to choose it.
  • A graph of the last minute of download and upload for the active tunnel, with the current rates and totals.
  • Exit-IP check against the profile's peer endpoint: "verified" when the public address is the gateway, "unexpected" when it is not, "not checked" when the endpoint is a host name.
  • A notification after every connect, switch, disconnect or failure. Connect and switch report the exit IP and flag a mismatch. Can be turned off.
  • Panel keys and IPC calls for every action.

Installation

omarchy plugin add https://github.com/selfcrypto/omarchy-wireguard.git --enable

Verify:

omarchy plugin list
omarchy plugin validate ~/.config/omarchy/plugins/io.github.selfcrypto.wireguard

Update:

omarchy plugin update io.github.selfcrypto.wireguard

Remove:

omarchy plugin remove io.github.selfcrypto.wireguard

Usage

  • Left click on the bar icon opens the panel.
  • Right click connects the default tunnel, or disconnects.
  • Middle click refreshes.
  • In the panel: click a row to switch to it (or disconnect it), click the star to make it the default. Keys: t toggle, 1–9 pick a tunnel (the default is always 1), d make the connected tunnel the default, r refresh and re-check the exit IP.

Configuration

Settings live on the widget's entry in ~/.config/omarchy/shell.json and are set with omarchy bar set:

omarchy bar set io.github.selfcrypto.wireguard defaultTunnel my-gateway   # or its UUID
omarchy bar set io.github.selfcrypto.wireguard exclusive false --json
omarchy bar set io.github.selfcrypto.wireguard notifications false --json
omarchy bar set io.github.selfcrypto.wireguard refreshIntervalSec 5
Key Meaning Default
defaultTunnel NetworkManager connection UUID or name the switch / right-click / on bring up (the star stores the UUID; a shared name picks the first profile with it) first profile
exclusive bring every other tunnel down before bringing one up true
notifications notification after every connect, switch, disconnect or failure true
refreshIntervalSec status poll interval, 2–60 s 3

IPC

omarchy-shell io.github.selfcrypto.wireguard status          # "gateway", "disconnected" or "unavailable"
omarchy-shell io.github.selfcrypto.wireguard list            # JSON: tunnels with UUIDs, active, default, stale, truncated
omarchy-shell io.github.selfcrypto.wireguard on | off        # default tunnel up / everything down
omarchy-shell io.github.selfcrypto.wireguard up <name|uuid>
omarchy-shell io.github.selfcrypto.wireguard down <name|uuid>
omarchy-shell io.github.selfcrypto.wireguard setDefault <name|uuid>
omarchy-shell io.github.selfcrypto.wireguard toggle          # the panel

up, down and setDefault take a name or a UUID from list. A name two profiles share is refused (ambiguous name: ...); pass the UUID instead. on, off, up and down answer ok when the change started, otherwise the reason nothing started (busy, already active, already connected, not active, no tunnel). How the change ended comes as a toast.

When NetworkManager does not answer, the panel keeps the last tunnels it saw and shows "Status unavailable". Then status answers unavailable, list carries "stale": true, and off answers unavailable unless the last snapshot has a tunnel up.

Requirements and dependencies

  • NetworkManager with WireGuard profiles (nmcli); curl for the exit-IP check; sh (bash or dash, not BusyBox ash), timeout (coreutils) and flock (util-linux). All ship with Omarchy.
  • Runs entirely as the user: NetworkManager's default policy lets the active local session bring its connections up and down, so no polkit prompt.
  • One external request: the exit IP comes from https://1.1.1.1/cdn-cgi/trace (Cloudflare), only while the panel is open or a tunnel changes.
  • The exit-IP verdict is only given when the profile's endpoint is an IP literal; a hostname endpoint shows the address tagged "not checked".

How it runs things

Every external command goes through wg-helper.sh, one process per operation, as timeout -k 3 <deadline> sh wg-helper.sh <command> args...:

  • Deadlines: each operation has a wall-clock limit that covers its whole process group (timeout runs the helper as a group leader and signals the group, then kills it). Discovery 10 s, byte counters 5 s, exit IP 10 s, a switch 95 s plus 40 s per other WireGuard profile the panel knows (at least one), a disconnect 20 s plus 15 s per tunnel, toasts 15 s. Inside the helper every nmcli call has its own timeout, so a switch ends by itself before its deadline.
  • The tunnels a switch takes down are read from NetworkManager by the helper itself, under its lock: every active WireGuard connection but the new one, whatever the panel last saw. When that query fails, or finds more tunnels than the panel's deadline was computed for, nothing changes and the toast says the switch was not attempted.
  • A switch brings the new tunnel up only once NetworkManager reports every previous tunnel down, and reports success only when the new one is active and the previous ones are not.
  • A failed switch takes the new tunnel down and brings back the tunnels that were active before it, read from NetworkManager's active connections, and checks the result. If the new tunnel stays active, the previous ones stay down and the toast says so. The helper prints one line with the previous tunnels and whether NetworkManager showed each active at the end; the toast names tunnels from that line only. If the switch is interrupted (deadline, TERM, INT or HUP), the helper kills the step in flight with its whole process group and runs the same restore in a process group of its own, so the final KILL does not stop it.
  • One lock (flock, in $XDG_RUNTIME_DIR) for every command that brings a tunnel up or down. The restore after an interruption keeps it until it ends. A switch or disconnect that finds it taken changes nothing and its toast says another tunnel change is still running. Only the helper and that restore hold it: every nmcli call runs without the lock's file descriptor, and whatever a call leaves running in its process group is killed when it ends.
  • Fixed argv: profiles travel as UUIDs in arguments, never inside a script, and only UUIDs returned by the last discovery are passed on. Names are only shown, because NetworkManager lets two profiles share one.
  • Bounded, validated output: discovery lists at most 32 profiles, clips names to 256 bytes and endpoints to 253, accepts interface names only when they satisfy the kernel's own rules (1–15 bytes, no /, : or whitespace) and hold no control character before touching /sys/class/net, and emits JSON with every string escaped or validated. The widget re-validates every field it parses.
  • Exit IP: HTTPS only, no redirects, 3 s connect and 6 s total deadline, 4 KiB response cap in curl and again in the reader; the value is used only when the trace carries exactly one ip= line holding a canonical IPv4 address.
  • Text from outside (names, endpoints, the exit IP) is shown as plain text, capped and elided. IPC replies have the same limits. list is always whole JSON: its ceiling (128 KiB) is above the worst case of these limits, and past it tunnels would be dropped from the end with "truncated": true.

Working on the code

Start with CLAUDE.md: the map of the code, the current state and the release steps.

License

MIT. See LICENSE.

About

WireGuard tunnels from NetworkManager in the Omarchy bar: tunnel switching, a live traffic graph and exit IP check.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages