You can override the Linux kernel and associated packages using the option <option>boot.kernelPackages</option>. For instance, this selects the Linux 3.10 kernel:
Note that this not only replaces the kernel, but also packages that are specific to the kernel version, such as the NVIDIA video drivers. This ensures that driver packages are consistent with the kernel.
<varname>extraConfig</varname> takes a list of Linux kernel configuration options, one per line. The name of the option should not include the prefix <literal>CONFIG_</literal>. The option value is typically <literal>y</literal>, <literal>n</literal> or <literal>m</literal> (to build something as a kernel module).
Kernel modules for hardware devices are generally loaded automatically by <command>udev</command>. You can force a module to be loaded via <xreflinkend="opt-boot.kernelModules"/>, e.g.
The first step before compiling the kernel is to generate an appropriate <literal>.config</literal> configuration. Either you pass your own config via the <literal>configfile</literal> setting of <literal>linuxManualConfig</literal>:
or you can let nixpkgs generate the configuration. Nixpkgs generates it via answering the interactive kernel utility <command>make config</command>. The answers depend on parameters passed to <filename>pkgs/os-specific/linux/kernel/generic.nix</filename> (which you can influence by overriding <literal>extraConfig, autoModules, modDirVersion, preferBuiltin, extraConfig</literal>).
When developing kernel modules it's often convenient to run edit-compile-run loop as quickly as possible. See below snippet as an example of developing <literal>mellanox</literal> drivers.