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;
};
};
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.
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.