A definition for option `boot.extraModulePackages."[definition 2-entry 1]"' is not of type `package'

Hello guys! I added this line to my nix config:

    boot.extraModulePackages = [ config.boot.kernelPackages.wireguard ];

but I’m getting the following error message:

error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'nixos-system-pc-23.11.20230927.8a86b98'
         whose name attribute is located at /nix/store/8lg5579v1k5mc63ypzfagrcl8l32x3bh-source/pkgs/stdenv/generic/make-derivation.nix:300:7

       … while evaluating attribute 'buildCommand' of derivation 'nixos-system-pc-23.11.20230927.8a86b98'

         at /nix/store/8lg5579v1k5mc63ypzfagrcl8l32x3bh-source/nixos/modules/system/activation/top-level.nix:53:5:

           52|     passAsFile = [ "extraDependencies" ];
           53|     buildCommand = systemBuilder;
             |     ^
           54|

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: A definition for option `boot.extraModulePackages."[definition 2-entry 1]"' is not of type `package'. Definition values:

may I ask what I’m doing wrong?

HI, I stumbled upon the same error and then I found this that states: “Note that wireguard has been merged into the mainline kernel, so on newer (21.05+) versions of NixOS with the default kernel wireguard is no longer an option available.” so if you are using a recent version of Nix there there should be no reason to add that package.
You should be able to check if the module is loaded by running lsmod | grep wireguard
Hope this helps.