Error compiling linux when rebuilding system

I am getting error when I try to rebuild my system using sudo nixos-rebuild switch

/build/source/os_dep/linux/wifi_regd.c: In function 'rtw_regd_init':
/build/source/os_dep/linux/wifi_regd.c:409:36: error: 'REGULATORY_IGNORE_STALE_KICKOFF' undeclared (first use in this function)
  409 |         wiphy->regulatory_flags |= REGULATORY_IGNORE_STALE_KICKOFF;
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/build/source/os_dep/linux/wifi_regd.c:409:36: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [/nix/store/qv47mlwd7bmgjcp56hlvr7bscin8zif8-linux-6.1.41-dev/lib/modules/6.1.41/source/scripts/ /build/source/os_dep/linux/wifi_regd.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/nix/store/qv47mlwd7bmgjcp56hlvr7bscin8zif8-linux-6.1.41-dev/lib/modules/6.1.41/source/Makefile:2012: /build/source] Error 2
make: *** [Makefile:2504: modules] Error 2
error: builder for '/nix/store/2rij9bvx0fqsnipqzbgh0xs1v8284b1k-rtl8812au-6.1.41-unstable-2023-07-20.drv' failed with exit code 2
error: 1 dependencies of derivation '/nix/store/dvh52l5g2vnaipk0l7ssywih9vblk148-kernel-modules.drv' failed to build
error (ignored): error: cannot unlink '/tmp/nix-build-zerotierone-1.10.6.drv-0/cargo-vendor-dir': Directory not empty
error: 1 dependencies of derivation '/nix/store/yczv5zmjajb9i401ma932cgs06nyfsfs-linux-6.1.41-modules.drv' failed to build
error: 1 dependencies of derivation '/nix/store/8bpzn8lqbp3dh6nvn3rhp87cbhci32j9-nixos-system-toaster-23.05.2385.48e82fe1b1c.drv' failed to build

From my observation it has something to do with linux kernel but I don’t understand how should I go about fixing it, as I am very much new to nixos :sweat_smile:

Extra info maybe necessary:-
I did not have enough space when I tried to rebuild my system earlier so, I cleaned up previous generations (~132 generations) using this trim generations script. Then I ran sudo nix-collect-garbage, after which I again tried to rebuild my system and met with this error.

There’s an open issue for that: linuxPackages.rtl88x2bu: does not build: REGULATORY_IGNORE_STALE_KICKOFF undeclared · Issue #246182 · NixOS/nixpkgs · GitHub

Edit: the fix for rtl88x2bu and your rtl8812au is trivial, I opened a PR for that: linuxPackages.{rtl8812au,rtl88x2bu}: update to latest by ius · Pull Request #246260 · NixOS/nixpkgs · GitHub

(will take some time to get merged & trickle down to nixos-23.05)