Describe the bug
I would like to have my Rasberry Pi connect to wifi without requiring user interaction. I have attempted to configure it using both wpa_supplicant and iwd, and both services are in a failed state on initial login. I have tried wpa_supplicant both with & without connman, and with & without declaratively specifying the connection details of the SSID.
Restarting the service (systemctl restart wpa_supplicant.service or systemctl restart iwd.service) causes the wireless to immediately connect, and systemctl status shows the service in a healthy state.
When I run journalctl -u iwd, I see the following error listed:
NEW_INTERFACE failed: Device or resource busy
To Reproduce
Steps to reproduce the behavior:
network.wireless.enable = true; or network.wireless.iwd.enable = true;Expected behavior
The pi should connect to wifi, and the wireless service (iwd or wpa_supplicant) should not crash.
Metadata
Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.
- system: `"aarch64-linux"`
- host os: `Linux 4.19.107, NixOS, 19.09.2201.7d31bbceaa1 (Loris)`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.3.3`
- channels(root): `"nixos-unstable-20.09pre215947.82b54d49066, nixos-19.09.2201.7d31bbceaa1"`
- channels(ertw): `"nixpkgs-unstable-20.09pre215991.93ba4ecd586"`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
Maintainer information:
# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
I had to add this to my config for wifi to work:
boot.extraModprobeConfig = ''
options cfg80211 ieee80211_regdom="${regDom}"
'';
hardware.firmware = [ pkgs.wireless-regdb ];
where regDom is your 2 letter country code (US for the United States).
Update: I did try @matthewbauer's suggestion, and I'm not sure whether it helped or not. Now I am sometimes getting connected to wifi, and sometimes not. In the case where it fails to connect to wifi, I see the same NEW_INTERFACE failed: Device or resource busy in systemctl status.
I am also still unable to boot into the latest 5.4 kernel (I reported a separate bug for this), so maybe this is an issue that is been fixed, and is only affecting 4.19?
Is there some way I can configure the systemd unit to always restart? Something like, attempt to start every 5 seconds forever seems like what I'd want regardless in an embedded device where connectivity is critical.
I think you can do:
systemd.services.iwd.serviceConfig.Restart = "always";
I also have this in my settings, but can't remember if it made a difference:
networking.dhcpcd.extraConfig = "timeout 0";
Okay, systemd.services.iwd.serviceConfig.Restart = "always"; does seem to solve my problem- the device is now connecting reliably to wifi and I can SSH into it without needing a display.
I'd like to leave this issue open for now though, as there is something causing both iwd and wpa_supplicant to crash on initial startup. Ideally we could discover what this is, and correctly solve for it rather than just restarting the service.
Here is what I believe to be the minimal config for working WLAN on the Raspberry Pi 3 B+:
{ config, pkgs, lib, ... }:
{
systemd.services.iwd.serviceConfig.Restart = "always";
hardware = {
enableRedistributableFirmware = true;
firmware = [ pkgs.wireless-regdb ];
};
networking = {
useDHCP = false;
interfaces.wlan0.useDHCP = true;
networkmanager.wifi.backend = "iwd";
wireless.iwd.enable = true;
};
boot = {
extraModprobeConfig = ''
options cf680211 ieee80211_regdom="US"
'';
};
system = {
stateVersion = "19.09";
};
}
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/raspberry-pi-aarch64-connect-to-wifi-automatically/6162/2
To add to this, the Arch Linux iwd entry specifically calls out issues with the systemd unit failing on startup, which sounds like what I've been running into.
My Raspberry Pi 4B was failing to load the wlan0 device. The fix is to add hardware.enableRedistributableFirmware = true;. The full working config is in https://github.com/Robertof/nixos-docker-sd-image-builder/issues/10#issuecomment-646901392
Shall we close this issue?
Most helpful comment
Okay,
systemd.services.iwd.serviceConfig.Restart = "always";does seem to solve my problem- the device is now connecting reliably to wifi and I can SSH into it without needing a display.I'd like to leave this issue open for now though, as there is something causing both
iwdandwpa_supplicantto crash on initial startup. Ideally we could discover what this is, and correctly solve for it rather than just restarting the service.Here is what I believe to be the minimal config for working WLAN on the Raspberry Pi 3 B+: