Recompile kernel with disabled options / modules in NixOS

Hello,

I’m trying to change my kernel config using NixOS options. In particular, I want to disable the WIRELESS module ( CONFIG_WIRELESS ). I found the wiki stating you can use boot.kernelPackages to customize your kernel, which I tried with the following configuration :

  boot.kernelPackages = pkgs.linuxPackages_5_14.extend (lib.const (ksuper: {
    kernel = ksuper.kernel.override {
      structuredExtraConfig = with lib.kernel; { MAC80211_DEBUGFS = yes; };
    };
  }));

Looking at the resulting conf using zgrep MAC80211_DEBUGFS /proc/config.gz, I can see that my change has been taken into account :

[root@nixos:~]# zgrep MAC80211_DEBUGFS /proc/config.gz
CONFIG_MAC80211_DEBUGFS=y

Now, what I’m really trying to achieve is disabling the WIRELESS completely, so I modified the code to get this:

  boot.kernelPackages = pkgs.linuxPackages_5_14.extend (lib.const (ksuper: {
    kernel = ksuper.kernel.override {
      structuredExtraConfig = with lib.kernel; { WIRELESS = no; };
    };
  }));

This results in some errors, e.g.

unpacking sources
unpacking source archive /nix/store/f67si2mxyqwswqh3n9qrpqlcncavsgi6-linux-5.14.20.tar.xz
source root is linux-5.14.20
setting SOURCE_DATE_EPOCH to timestamp 1637240494 of file linux-5.14.20/virt/lib/irqbypass.c

[…]

QUESTION:   KCM sockets, NAME: AF_KCM, ALTS: N/m/y/?, ANSWER: m
GOT: m
GOT:   *
GOT:   * Wireless
GOT:   *
GOT:   Wireless (WIRELESS) [Y/?] y
QUESTION:     cfg80211 - wireless configuration API, NAME: CFG80211, ALTS: Y/n/m/?, ANSWER: m
GOT: m
QUESTION:       nl80211 testmode command, NAME: NL80211_TESTMODE, ALTS: N/y/?, ANSWER:

[…]

GOT: #
GOT: # configuration written to .config
GOT: #
GOT: make[1]: Leaving directory '/build/linux-5.14.20/build'
GOT: make: Leaving directory '/build/linux-5.14.20'
warning: unused option: DEBUG_STACKOVERFLOW
warning: unused option: EXT4_ENCRYPTION
warning: unused option: F2FS_FS_ENCRYPTION
warning: unused option: RCU_PERF_TEST
error: option not set correctly: WIRELESS (wanted 'n', got 'y')
warning: unused option: XEN_SCRUB_PAGES
warning: unused option: XEN_SELFBALLOONING
warning: unused option: XEN_STUB
warning: unused option: XEN_TMEM
builder for '/nix/store/l5ay2nh62nanz48ny0w1f1c36f1x420i-linux-config-5.14.20.drv' failed with exit code 255

So, how can I set CONFIG_WIRELESS to no in my kernel using nixos options, if possible not handling the .config by hand ? Is that possible ?

Thanks

I have found sth similar. Maybe it will help hacknix/500-linux-ath10k.nix at 479e37c977a16c8991cdaa060aa90e77d732b6a8 · hackworthltd/hacknix · GitHub

Hosted by Flying Circus.