How to override packages from another PR, instead of importing them under another namespace?

Trying to get serious with nixpkgs PRs, I decided to dogfood my own PRs, since that would remove the sync step where I copy the modified files between my nixpkgs fork and my nixos-config repo to use it on my machines.

To achieve that, I converted my existing configs to flake so I can define my PRs as input, and added some shim files so I can reference the modules and packages almost like they are merged. This is working for 2 of my PRs.

I also have a PR of a simple kernel module. I can use the nixpkgs.overlays method in the above linked shim file and set boot.kernelPackages = pkgs.pr-ch9344.linuxPackages;. This would allow me to enable the kernel module per usual with boot.extraModulePackages. However, I’m also stuck with whatever kernel was defined in my PR, so I’d rather only override the kernel module definition.

I tried the following shim file:

{ config, lib, pkgs, inputs, ... }:

{
  disabledModules = [
    "pkgs/os-specific/linux/ch9344/default.nix"
  ];
  imports = [
    "${inputs.pr-ch9344}/pkgs/os-specific/linux/ch9344/default.nix"
  ];
}

… and got the following error:

error:
       … while calling the 'seq' builtin

         at /nix/store/mykqzd5whqs367ahav828iqjcrr15ycg-source/lib/modules.nix:320:18:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          321|         _module = checked (config._module);

       … while evaluating a branch condition

         at /nix/store/mykqzd5whqs367ahav828iqjcrr15ycg-source/lib/modules.nix:261:9:

          260|       checkUnmatched =
          261|         if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [] then
             |         ^
          262|           let

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: function 'anonymous lambda' called with unexpected argument 'inputs'

       at /nix/store/vvh8nqgfpgpgvbv8f6zv7vzjlzpm6i0d-source/pkgs/os-specific/linux/ch9344/default.nix:1:1:

            1| { stdenv, lib, fetchzip, kernel }:
             | ^
            2|

I don’t understand how imports determine the argument it would pass to the nix file. But I guess it might be enabled here. In any case I tried to manually specify the argument:

{ config, lib, pkgs, inputs,
stdenv, fetchzip, kernel,
... }:

{
  disabledModules = [
    "pkgs/os-specific/linux/ch9344/default.nix"
  ];
  imports = [
    (import "${inputs.pr-ch9344}/pkgs/os-specific/linux/ch9344/default.nix" {
      stdenv = stdenv;
      lib = lib;
      fetchzip = fetchzip;
      kernel = kernel;
    })
  ];
}

… and I’m getting a different error now:

       … while calling the 'seq' builtin

         at /nix/store/mykqzd5whqs367ahav828iqjcrr15ycg-source/lib/modules.nix:320:18:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          321|         _module = checked (config._module);

       … while evaluating a branch condition

         at /nix/store/mykqzd5whqs367ahav828iqjcrr15ycg-source/lib/modules.nix:261:9:

          260|       checkUnmatched =
          261|         if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [] then
             |         ^
          262|           let

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: infinite recursion encountered

       at /nix/store/mykqzd5whqs367ahav828iqjcrr15ycg-source/lib/modules.nix:506:28:

          505|         builtins.addErrorContext (context name)
          506|           (args.${name} or config._module.args.${name})
             |                            ^
          507|       ) (lib.functionArgs f);

I’m currently out of idea how to proceed now.