NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.16k stars 14.19k forks source link

Raspberry Pi 3 B+ wifi does not work until the service is restarted #82462

Open ertw opened 4 years ago

ertw commented 4 years ago

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:

  1. Install NixOs 19.09 with kernel 4.19 following the wiki guide
  2. Attempt to configure wifi using 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:
matthewbauer commented 4 years ago

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).

ertw commented 4 years ago

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.

matthewbauer commented 4 years ago

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";
ertw commented 4 years ago

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 cfg80211 ieee80211_regdom="US"
    '';
  };
  system = {
    stateVersion = "19.09";
  };
}
nixos-discourse commented 4 years ago

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

ertw commented 4 years ago

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.

https://wiki.archlinux.org/index.php/Iwd#Systemd_unit_fails_on_startup_due_to_device_not_being_available

mleonhard commented 4 years ago

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?

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

bachp commented 2 years ago

This issue seems to be still present. wlan0 doesn't even show up on the Pi 3. The only workaround is to use an older version of firmware-linux.

ratsclub commented 2 years ago

@bachp were you able to connect to do it? My wlan0 also won't show up.

bachp commented 2 years ago

I got it working by following the instructions in https://github.com/NixOS/nixpkgs/issues/115652#issue-826834436. But there doesn't seem to be a real solution yet.

nixos-discourse commented 2 years ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/raspberry-pi-3-wireless-interface/17576/1

jqqqqqqqqqq commented 2 years ago

@ertw Your typo is carried to the internet example

options cf680211 ieee80211_regdom="US"

it should be cfg80211 instead of cf680211.

Took me a tremedous long time to figure out.

Without fixing this typo, the output below is 00 and I cannot associate with any network

root@nixos ~# cat /sys/module/cfg80211/parameters/ieee80211_regdom
US