Prefer extra kernel module over integrated one

Hi guys,

there is a dddvb kernel module with drivers for Digital Devices DVB cards. There is version 0.9.33 already integrated in the stock kernel but I have Max M4 card which is not supported by this version yet. So I added boot.extraModulePackages = with config.boot.kernelPackages; [ dddvb ]; to the configuration to include latest version of the module provided by nixpkgs (0.9.38-pre.6).

Now I have two versions of the same module included in kernel files tree - the integrated one in /run/booted-system/kernel-modules/lib/modules/6.0.19/kernel subtree and the latest version in /run/booted-system/kernel-modules/lib/modules/6.0.19/extra subtree. But no matter what method I use to load the module I always get the old integrated version.

What is the proper way to solve this in NixOS? Or in more words what should I add to configuration.nix to make sure module from nixpkgs gets loaded instead of the integrated one?

Thank you,

Just a follow up for those who also encountered this problem.

On normal Linux system this would be easily solvable by adding a config file to /etc/depmod.d. On NixOS depmod runs only during build and there are no configuration options nor documentation explaining how to configure it. I guess there is probably a way but I do not understand Nix language enough (yet) to be able to find it myself. If anybody knows how to set depmod configuration so that it gets picked up when NixOS runs depmod, please, share it with us in this thread.

As a workaround I solved this by using boot.kernelPatches to build custom kernel with old drivers excluded. It took a bit of experimenting until It turned out that to get rid of default ddbridge driver, ngene driver has to be excluded as well and also that the dddvb package has to be upgraded to version 0.9.38 and modified to build the driver with KERNEL_DVB_CORE=y.

Here is relevant part of the config:

  boot.kernelPackages = pkgs.linuxPackages_6_1;
  boot.kernelPatches = [ { name = "exclude-ddbridge"; patch = null; extraConfig =
  ''; } ];
  boot.extraModulePackages = [ dddvb ];

And modified default.nix of dddvb package:

{ lib
, stdenv
, fetchFromGitHub
, fetchpatch
, kernel

stdenv.mkDerivation rec {
  pname = "dddvb";
  version = "0.9.38";

  hardeningDisable = [ "all" ];

  src = fetchFromGitHub {
    owner = "DigitalDevices";
    repo = "dddvb";
    rev = "refs/tags/${version}";
    hash = "sha256-s3rEndzE50LoPBVwtp3+BHI3xTStlNqoCP38GHpCves=";

  postPatch = ''
    sed -i '/depmod/d' Makefile

  nativeBuildInputs = kernel.moduleBuildDependencies;

  makeFlags = [

  MDIR = placeholder "out";

  enableParallelBuilding = true;

  meta = with lib; {
    homepage = "";
    description = "ddbridge linux driver";
    license = licenses.gpl2Only;
    maintainers = with maintainers; [ hexa ];
    platforms = platforms.linux;