Skip to content

Carry saved Wi-Fi networks over to iwd - #640

Closed
oliverlukschander wants to merge 1 commit into
omacom:quattro-upstreamfrom
oliverlukschander:fix/iwd-saved-networks
Closed

oliverlukschander wants to merge 1 commit into
omacom:quattro-upstreamfrom
oliverlukschander:fix/iwd-saved-networks

Conversation

@oliverlukschander

@oliverlukschander oliverlukschander commented Sep 27, 2026 •

Copy link
Copy Markdown

Summary

  • The problem: omarchy-mac switches NetworkManager to the iwd backend (20-omarchy-mac-wifi.conf). On a Mac that ran wpa_supplicant before, every saved Wi-Fi network then fails after the next boot, and the network panel shows "Wrong password" whatever is typed.
  • Cause, part 1: NetworkManager writes an iwd profile only for a connection created while it runs on iwd (connection_added in nm-iwd-manager.c). Networks saved under wpa_supplicant have none in /var/lib/iwd, so iwd asks NetworkManager's agent for the key.
  • Cause, part 2: for a WPA-PSK connection that has been used before, NetworkManager doesn't hand over the key it stores. nm_device_iwd_agent_query in nm-device-iwd.c (NM 1.58.1) sets NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW once the connection has a timestamp and asks a secret agent for a new key. Omarchy runs no agent, so the log shows need-auth (reason 'no-secrets'), then No agents were available, then net.connman.iwd.Aborted.
  • The fix: a new helper, lib/wifi-iwd-profiles, gives iwd a profile for each saved infrastructure WPA-PSK or SAE network whose key NetworkManager stores.
    • It uses the format NetworkManager writes for a new connection (nm_wifi_utils_connection_to_iwd_config in nm-wifi-utils.c): the same file name (the SSID, or = plus hex), Passphrase or PreSharedKey, and AutoConnect=false / Hidden=true where set.
    • Like NetworkManager, it leaves out agent-owned or unsaved keys and connections limited to some users. It keeps any profile iwd already has, and the most recently used connection wins when several name one network.
    • It exits unless the platform is Apple Silicon and NetworkManager's configuration selects iwd.
  • Where it runs: omarchy-mac-setup-system calls it on the live machine. Setup runs from provisioning, first run and the transition migrations while NetworkManager still runs the old backend, so the profiles are in place before the switch applies at NetworkManager's next start. Running it again later also repairs a machine that already switched.
  • Docs: the README's setup contract describes the step.

Testing

On hardware. MacBook Pro 16" M2 Pro, NetworkManager 1.58.1, iwd 3.12, moved from wpa_supplicant to quattro-upstream:

  • Before: after the switch, the saved home network failed as a wrong password, with the log lines above; the key was stored in both of its NetworkManager profiles throughout.
  • After: with the carried-over profiles, iwd autoconnected with the stored key in about 0.25 s, and NetworkManager followed ("Activation: successful") without asking for a password.

Tests.

  • test/wifi-profiles-test.sh covers:

    • no-op unless the backend is iwd;
    • the plain and hex (non-ASCII) file names;
    • Passphrase vs 64-hex PreSharedKey, and SAE;
    • agent-owned and not-saved keys, permission-limited connections, EAP, open and AP-mode connections all skipped;
    • Hidden / AutoConnect=false;
    • escaping of backslashes and a leading space;
    • an existing profile kept, and the newest connection winning;
    • setup calling the helper only in its live block.

    The nmcli stub reproduces <hidden> without --show-secrets and nmcli's :/\ escaping without --escape no, so the helper can't silently depend on either.

  • packages/omarchy-mac/test/all: 81/81 pass (76 before), and the setup-test live harness passes. Rebased onto quattro-upstream 351c9fb (2026-09-28), only the README sentence needed resolving: 98/98 pass (93 before), and the runtime suite fails exactly as on an unmodified 351c9fb. Deliberately breaking the helper or its call in setup-system (23 mutations) failed the suite every time.

  • Three small changes came after the hardware run: the platform check that test/platform-test.sh requires of every lib/* helper, grep -x … >/dev/null instead of grep -q under pipefail, and skipping permission-limited connections. None touches the tested path, and a dry run of the final helper against the same machine's real profiles wrote identical files.

A second finding, not changed here

With iwd's autoconnect (NetworkManager's default wifi.iwd.autoconnect=yes), NetworkManager follows iwd's connection by picking the first saved profile with the same SSID and security type (mirror_connection / nm_iwd_manager_get_ap_mirror_connection). It doesn't check that the profile is usable on the device.

The machine above also had an older duplicate profile for the home network, from install day, bound to interface-name=wld0; the interface is wlan0. NetworkManager picked it, and then:

device (wlan0): This is a new connection, 'assuming' it
active-connection: Failed to activate 'Magenta210398': Connection 'Magenta210398' is not available on device wlan0 because profile is not compatible with device (mismatching interface name)
iwd: src/station.c:station_dbus_disconnect()

NetworkManager then disconnects iwd, and nothing reconnects.

  • Workaround: deleting the stale profile, or setting wifi.iwd.autoconnect=no (NetworkManager then connects itself and respects profile availability, as under wpa_supplicant). Each connected within 0.5 s.
  • Where it belongs: that's NetworkManager's bug to fix. wifi.iwd.autoconnect=no in 20-omarchy-mac-wifi.conf would sidestep it for migrated machines with such leftovers, but it's a policy change, so it isn't part of this PR. I don't know where the wld0 profile came from; nothing in this repo names that interface.

Found while moving my own M2 Pro onto quattro-upstream. I'm happy to discuss here, on Discord or by mail (oliver@lukschander.com).

🤖 Generated with Claude Code

omarchy-mac runs NetworkManager on the iwd backend, and on a Mac that ran
wpa_supplicant before, every saved network then fails as a wrong password.
NetworkManager writes an iwd profile only for a connection created while it
runs on iwd. When iwd asks for the key of a WPA-PSK connection
NetworkManager has used before, it does not hand over the key it stores but
requests a new one from a secret agent (nm_device_iwd_agent_query in
nm-device-iwd.c sets REQUEST_NEW once the connection has a timestamp), and
Omarchy runs no agent.

System setup on the live machine runs before the backend applies at
NetworkManager's next start. It now gives iwd a profile for each saved
WPA-PSK or SAE network whose key NetworkManager stores, in the format
NetworkManager writes for a new connection
(nm_wifi_utils_connection_to_iwd_config in nm-wifi-utils.c): the same file
name, the passphrase or pre-shared key, and AutoConnect and Hidden. Like
NetworkManager, it leaves out connections limited to some users, and it
keeps any profile iwd already has.

Verified on an M2 Pro (MacBook Pro 16"): after the switch the saved
networks read as a wrong password, and with the carried-over profiles they
connected without asking for a password.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maralcbr

Copy link
Copy Markdown
Member

Thanks, this is still wanted. This week the Mac code moved into the omarchy-mac package (packages/omarchy-mac/) and the platform files moved to the /usr/share/omarchy-platform root (#660), so could you rebase onto quattro-upstream? packages/omarchy-mac/README.md and packages/omarchy-mac/bin/omarchy-mac-setup-system conflict.

@oliverlukschander

Copy link
Copy Markdown
Author

Thanks, happy to hear, rebase is done.

@oliverlukschander

Copy link
Copy Markdown
Author

Closing: this was ported to the packages repo as omacom/omarchy-mac-pkgs#1 and merged there on 4 October (thanks @maralcbr). quattro-upstream is frozen, so nothing more to do here.

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