Best way to handle boot.extraModulePackages Kernel module conflict

Hey, I am having issues with Kernel module name conflicts and I am looking for advice on the best way to resolve it.

I’m trying to use boot.extraModulePackages to load the it87 module https://github.com/NixOS/nixpkgs/blob/ffaadc7b70686e25af496c5ec2c4491ad3656b94/pkgs/os-specific/linux/it87/default.nix . Below is what I have:

boot.extraModulePackages = with config.boot.kernelPackages; [
   it87
];

When I use this snippet it adds the the file it87.ko to /run/current-system/kernel-modules/lib/modules/6.1.35/kernel/drivers/hwmon/

The issue I have is the file /run/current-system/kernel-modules/lib/modules/6.1.35/kernel/drivers/hwmon/it87.ko.xz already exists and when I do a modprobe the it87.ko.xz seems to get used over the it87.ko which fails for me as the mainline version doesn’t support my hardware.

As a workaround I’ve added the below to my configuration.nix, disabling the mainline it87 module being built. This solves the problem but requires a long kernel compilation.

 boot.kernelPatches = lib.singleton {
    name = "disable-it87";
    patch = null;
    extraStructuredConfig = with lib.kernel; {
      SENSORS_IT87 = no;
    };
  };

Does anyone have a better solution? If https://github.com/NixOS/nixpkgs/blob/ffaadc7b70686e25af496c5ec2c4491ad3656b94/pkgs/os-specific/linux/it87/default.nix built a ko.xz extension I’m guessing it would overwrite the default and this would be a non issue?

1 Like

Hello!

Did you find any solution to this?

I have the following configuration but I am not able to load the it87 kernel module

  boot.kernelModules = [ "kvm-amd" "it87" ];
  boot.extraModulePackages = with config.boot.kernelPackages; [
    it87
  ];

And lsmod does not show it87 in any way

Thanks

I was not able to make it87 work
At this point I gave up on using it87 with fancontrol for my Gigabyte MB and set up the fans in the BIOS.

fancontrol is still used for the AMDGPU

It may be a little bit too late, but I have achieved using the it87 module to get/set the fans speed on my Gigabyte Z690M mb. I have used this section from the arch wiki as reference.

Here is my working config:

  # Detect fans on Gigabyte Z690 motherboard
  boot.kernelParams = [ "acpi_enforce_resources=lax" ];
  boot.kernelModules = [ "coretemp" "it87" ];
  boot.extraModprobeConfig = ''
    options it87 force_id=0x8628
  '';

You should probably need to change the options to match your chipset (check the arch wiki section mentioned before)

Can confirm, I got it working on my gigabyte aorus b650i with what brusapa AND skip did.

boot.extraModulePackages = with config.boot.kernelPackages; [
    it87
  ];
boot.kernelParams = [ "acpi_enforce_resources=lax" ];
  boot.kernelModules = [ "coretemp" "it87" ];
  boot.extraModprobeConfig = ''
    options it87 force_id=0x8628
  '';

the original issue – that it87.ko.xz gets loaded instead of it87.ko – can be addressed a couple ways.

A. build all your in-tree kernel modules without compression:

  boot.kernelPatches = lib.singleton {
    name = "disable-compression";
    patch = null;
    extraStructuredConfig = with lib.kernel; {
      MODULE_COMPRESS_ALL = lib.mkForce no;
    };
  };

B. use the default nixos kernel and compress the out-of-tree it87 (i recommend this method since it’s quicker to iterate on):

boot.extraModulePackages = with config.boot.kernelPackages; [
   (it87.overrideAttrs (super: {
      postInstall = (super.postInstall or "") + ''
        find $out -name '*.ko' -exec xz {} \;
      '';
   }))
];

note that in either of these cases, you should expect a build failure when building the aggregated /kernel derivation, because you’ve got two conflicting modules and nixpkgs has no way to know which instance if it87 you prefer. that can be patched like so:

    # default nixos behavior is to error if a kernel module is provided by more than one package.
    # but we're doing that intentionally, so inline the `pkgs.aggregateModules` call from 
    # <nixos/modules/system/boot/kernel.nix> but configured for out-of-tree modules to override in-tree ones
    system.modulesTree = lib.mkForce [(
      (pkgs.aggregateModules
        ( config.boot.extraModulePackages ++ [ config.boot.kernelPackages.kernel ])
      ).overrideAttrs {
        # earlier items in the list above override the contents of later items
        ignoreCollisions = true;
      })
    )];

lastly, it looks like you’ve already got this part right, but to generalize the solution: make sure you’re building the in-tree kernel component you wish to override as a module (or as = no, as your earlier workaround does, though you may need to add the module to boot.kernelModules with that approach. it just can’t be = yes otherwise there’s no way to override it with an out-of-tree version).

I’m having a similar problem. The ena driver present in the linux tree is quite old & that’s why most people compile & use the ena drivers from the amazon tree.
I’ve been doing that automatically, since I include the amazon-image.nix in my configuration. It seems to be correctly including the ena driver & I can see the ena driver at /run/booted-system/kernel-modules/lib/modules/6.15.0/misc/ena.ko.xz. But it still seem to be loading the in-tree linux version at /run/booted-system/kernel-modules/lib/modules/6.15.0/kernel/drivers/net/ethernet/amazon/ena/ena.ko.xz. I’m not sure what I’m doing wrong. I have an identical ec2 instance in another region with the 100% same nix config & flake.lock files & that instance seem to be using the newer ena.ko.xz. I’ve tried various changes to modprobe configs, but I’m not able to get it to load the correct version at boot. The only way to load the correct driver is to run sudo rmmod ena && sudo insmod /run/booted-system/kernel-modules/lib/modules/6.15.0/misc/ena.ko.xz.