Setting some kernel modules to be load before all others

I’m writing a nixos module (which will be imported in imports
in configuration.nix) which needs to set some kernel modules to be loaded via boot.initrd.kernelModules option. But I want my modules to be loaded before the user’s modules which are specified in his configuration.nix. I know modules specified in this option load in the order they are specified, like in a configuration like this:

boot.initrd.kernelModules = [
  "vfio_pci"  # first to be loaded
  "vfio"
  "vfio_iommu_type1"
  "nvidia"  # last
];

But I don’t know how will setting this option in my module and in configuration.nix will interact with each other. Will they merge? If in which order?

I experimented a bit with nixos-option command and apparently everything is processed şn the order they appear. Imports come before and are prepended to configuration.nix options.

If you don’t want to rely on the import order, look into the mkOrder family of functions, especially mkBefore is what you want.

There is an example in the NixOS manual which shows its use in the context of boot.kernelModules.

Thanks. Exactly what I was looking for. If you don’t mind, how can I close this topic as solved? Or is there not such a thing?

I think you might be able to mark my reply as a solution or an answer, but I’m also not very familiar with it