sudo dmesg

[   66.281821] nouveau 0000:04:00.0: [drm] fb0: nouveaudrmfb frame buffer device
[   66.815823] nouveau 0000:04:00.0: fb: trapped read at 00003edfd0 on channel -1 [0fedf000 unknown] engine 06 [BAR] client 08 [PFIFO_READ] subclient 00 [FB] reason 0000000b [VRAM_LIMIT]
[   73.307277] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   73.307308] Bluetooth: BNEP socket layer initialized
[   73.320653] Bluetooth: MGMT ver 1.23
[   78.933654] NET: Registered PF_PACKET protocol family
[  136.429949] rfkill: input handler disabled
[  164.725426] NET: Registered PF_QIPCRTR protocol family
[  183.334782] Bluetooth: RFCOMM TTY layer initialized
[  183.334805] Bluetooth: RFCOMM socket layer initialized
[  183.334818] Bluetooth: RFCOMM ver 1.11
[  186.825596] nouveau 0000:04:00.0: .kgx-wrapped[1855]: channel failed to initialise, -17
[  282.498459] ERROR @wl_cfg80211_scan : 
[  282.498467] WLC_SCAN error (-22)
[  283.499377] ERROR @wl_cfg80211_scan : 
[  283.499392] WLC_SCAN error (-22)
[  284.501443] ERROR @wl_cfg80211_scan : 
[  284.501460] WLC_SCAN error (-22)
[  329.145789] warning: `Socket Thread' uses wireless extensions which will stop working for Wi-Fi 7 hardware; use nl80211

AI suggestions

#1

The
ERROR @wl_cfg80211_scan message in NixOS typically indicates an issue with the proprietary Broadcom broadcom-sta (or wl) driver, which is known to be unmaintained and can conflict with newer Linux kernels. 
To resolve this, you can try one of the following methods:
Option 1: Use a Compatible (LTS) Kernel 
The broadcom-sta driver often fails to build or function correctly with the very latest kernels. By default, NixOS aims to use the latest LTS (Long Term Support) kernel, which usually has better compatibility. 
Ensure you are using the default kernel and not explicitly pulling the _latest one in your configuration. If the issue persists with the default kernel, you may need to wait for the NixOS package maintainers to patch the driver for compatibility, which they frequently do. 
Option 2: Allow the Insecure Driver (if build fails)
If your NixOS installation or build process is failing because the broadcom-sta package is marked as insecure, you need to explicitly allow it in your configuration file (/etc/nixos/configuration.nix or your flake configuration). 
Add the following to your configuration to allow the insecure package: 
nix

nixpkgs.config.allowInsecurePredicate = pkg: builtins.elem (lib.getName pkg) [
  "broadcom-sta" # aka “wl”
];

After adding this, run sudo nixos-rebuild switch to apply the changes. 
Option 3: Ensure the wl module loads correctly 
Sometimes, the driver needs to be loaded earlier in the boot process. Ensure the wl module is in your boot.initrd.kernelModules list instead of boot.kernelModules in your hardware-configuration.nix file. 
nix

boot.initrd.kernelModules = [ "wl" ];
# Remove "wl" if it is present in the line below:
# boot.kernelModules = [ ... ];

Option 4: Use the Open-Source b43 driver (if supported) 
For some Broadcom chipsets, the open-source b43 driver may work and is preferred over the proprietary STA driver. This requires enabling non-free firmware. 
Add the following to your NixOS configuration:
nix

networking.enableB43Firmware = true;
boot.kernelModules = [ "b43" ];
# Ensure "broadcom-sta" or "wl" is removed from kernel modules/packages.

After modifying your configuration, run sudo nixos-rebuild switch and reboot your system to apply the new kernel module changes. 
If these steps do not resolve the issue, connecting via a wired Ethernet connection or using a different, supported USB Wi-Fi adapter is often the most reliable solution until the driver is compatible with your kernel. 

#2

To get your Broadcom BCM4322 working on NixOS, you need to configure your system to use the proprietary
broadcom_sta driver and blacklist conflicting open-source modules in your configuration.nix file. 
Prerequisites
You will need a temporary internet connection (e.g., via an Ethernet cable or USB tethering from your smartphone) to download the necessary drivers and rebuild your system. 
Configuration Steps

    Edit your configuration.nix file: Open /etc/nixos/configuration.nix in a text editor (like nano or vim) with superuser privileges:
    bash

sudo nano /etc/nixos/configuration.nix

Add the necessary configuration: Ensure the following lines are present in your configuration.nix. This enables unfree packages (required for proprietary Broadcom drivers), loads the wl kernel module, adds the broadcom_sta package, and blacklists conflicting modules:
nixos

{ config, pkgs, ... }:

{
  # Allow unfree packages for proprietary drivers
  nixpkgs.config.allowUnfree = true;

  # Enable networking and NetworkManager (optional, but recommended for easy management)
  networking.networkmanager.enable = true;
  networking.wireless.enable = true; # Enables wireless support via wpa_supplicant if not using NetworkManager

  # Configure the Broadcom driver
  boot.kernelModules = [ "wl" ];
  boot.extraModulePackages = with config.boot.kernelPackages; [
    broadcom_sta
  ];

  # Blacklist conflicting modules
  boot.blacklistedKernelModules = [ "b43" "bcma" "ssb" "brcmfmac" "brcmsmac" ];
}

Note: The wl driver is the correct module name used by the broadcom_sta package.
Rebuild your NixOS system: After saving the changes, apply the new configuration by running:
bash

sudo nixos-rebuild switch

Reboot your system: The changes should take effect after a reboot.
bash

sudo reboot

 

After rebooting, your BCM4322 wireless card should be detected and functional. You should be able to connect to wireless networks using NetworkManager or other networking tools. 
Troubleshooting

    Driver compatibility: The b43 driver is an open-source alternative, but the proprietary broadcom_sta (using the wl module) has a higher chance of working for the BCM4322 chipset.
    Check logs: If it still doesn't work, use journalctl -b | grep -i bcm or dmesg | grep -i bcm to check for specific error messages related to the driver or firmware loading.
    Kernel version: While the configuration works on the stable 24.05 release, some users found switching to the nixos-unstable channel to be necessary for newer kernels or hardware support in general. 
