Need help installing a kernel module

I’m trying to follow this guide: https://github.com/MatthewCash/asus-wmi-screenpad-module/tree/main to install a kernel module for my laptop. As far as I can tell in the guide, the kernel version the module is built for is overridable, however, I’ve set this to match my build kernel version, but I’m still getting an ‘inconsistent kernel version’ build error.

let screenpad-driver-package = (kernelPackage: let asus-wmi-screenpad = inputs.screenpad-driver.defaultPackage.${system}.override{kernel=kernelPackage;};
  in [
    asus-wmi-screenpad
  ]
);

in {

boot.extraModulePackages = screenpad-driver-package config.boot.kernelPackages; 

boot.kernelModules = [
      "asus-wmi-screenpad"
    ];
};

What am I doing wrong?

boot.kernelPackages is a collection of packages including the kernel and out of tree modules.

boot.kernelPackages.kernel is probably what you’re looking for.

Thanks for the pointer, although I’m afraid that doesn’t seem to fix the problem, the following gives the same error:

let
screenpad-driver-package = (kernelPackage: let asus-wmi-screenpad = inputs.screenpad-driver.defaultPackage.${system}.override{kernel=kernelPackage;};
  in [
    asus-wmi-screenpad
  ]
);

in
{
boot.extraModulePackages = screenpad-driver-package config.boot.kernelPackages.kernel;
    boot.kernelModules = [
      "asus-wmi-screenpad"
    ];
}
error: builder for '/nix/store/mprm47cb235v99n8l0qq79m8jxpk5bcy-linux-6.10-modules.drv' failed with exit code 1;
       last 10 log lines:
       > sourcing setup hook '/nix/store/kd4xwxjpjxi71jkm6ka0np72if9rm3y0-move-sbin.sh'
       > sourcing setup hook '/nix/store/pag6l61paj1dc9sv15l7bm5c17xn5kyk-move-systemd-user-units.sh'
       > sourcing setup hook '/nix/store/jivxp510zxakaaic7qkrb7v1dd2rdbw9-multiple-outputs.sh'
       > sourcing setup hook '/nix/store/ilaf1w22bxi6jsi45alhmvvdgy4ly3zs-patch-shebangs.sh'
       > sourcing setup hook '/nix/store/cickvswrvann041nqxb0rxilc46svw1n-prune-libtool-files.sh'
       > sourcing setup hook '/nix/store/xyff06pkhki3qy1ls77w10s0v79c9il0-reproducible-builds.sh'
       > sourcing setup hook '/nix/store/ngg1cv31c8c7bcm2n8ww4g06nq7s4zhm-set-source-date-epoch-to-latest.sh'
       > sourcing setup hook '/nix/store/gps9qrh99j7g02840wv5x78ykmz30byp-strip.sh'
       > inconsistent kernel versions: 6.10.0
       > 6.2.9
       For full logs, run 'nix log /nix/store/mprm47cb235v99n8l0qq79m8jxpk5bcy-linux-6.10-modules.drv'.

After looking at the flake you’re using, try setting inputs.screenpad-driver.inputs.nixpkgs.follows = "nixpkgs"; in your inputs section.

The flake is coded to always use its nixpkgs’s linux_latest kernel. Replace the final nixpkgs in the line above with the attribute you use for nixpkgs.

Thanks, that’s got me a good bit further, I’ve been able to get the module to start building by doing that, however, I’m now getting a couple of make errors when trying to build the module. I’m not familiar with reading C/C++ build errors, most of the programming I’ve gone has been in Java or Python, so if you’re able to help, that’d be great. When I try nixos-rebuild, I get this error:

Running phase: buildPhase
build flags: SHELL=/nix/store/m101dg80ngyjdb02g6jwy80sr7kzj26g-bash-5.2p26/bin/bash KERNEL_MODULES=/nix/store/hlhp0pprnyq96npl2k1b5z9iy2xc4c9q-linux-6.10-dev/lib/modules/6.10.0
ln -sf /build/ighz2w017r614b62p6dhiiz1h5lz06ba-source/Makefile /build/ighz2w017r614b62p6dhiiz1h5lz06ba-source/src/
make -C /nix/store/hlhp0pprnyq96npl2k1b5z9iy2xc4c9q-linux-6.10-dev/lib/modules/6.10.0/build M=/build/ighz2w017r614b62p6dhiiz1h5lz06ba-source/obj/ src=/build/ighz2w017r614b62p6dhiiz1h5lz06ba-source/>
make[1]: Entering directory '/nix/store/hlhp0pprnyq96npl2k1b5z9iy2xc4c9q-linux-6.10-dev/lib/modules/6.10.0/build'
make[3]: *** No rule to make target '/build/ighz2w017r614b62p6dhiiz1h5lz06ba-source/obj/asus_wmi_screenpad.o', needed by '/build/ighz2w017r614b62p6dhiiz1h5lz06ba-source/obj/'.  Stop.
make[2]: *** [/nix/store/hlhp0pprnyq96npl2k1b5z9iy2xc4c9q-linux-6.10-dev/lib/modules/6.10.0/source/Makefile:1934: /build/ighz2w017r614b62p6dhiiz1h5lz06ba-source/obj] Error 2
make[1]: *** [/nix/store/hlhp0pprnyq96npl2k1b5z9iy2xc4c9q-linux-6.10-dev/lib/modules/6.10.0/source/Makefile:240: __sub-make] Error 2
make[1]: Leaving directory '/nix/store/hlhp0pprnyq96npl2k1b5z9iy2xc4c9q-linux-6.10-dev/lib/modules/6.10.0/build'
make: *** [Makefile:12: all] Error 2

I tried again earlier today to build the module by cloning the repo and running the suggested nix run command in the readme. This built fine (I believe this was against kernel 6.9.8). However, I ran a nixos-rebuild with the above section commented out, to update the rest of my system before starting to try to debug this again, and now attempting the same nix run command gives this error:

building
build flags: SHELL=/nix/store/0hx32wk55ml88jrb1qxwg5c5yazfm6gf-bash-5.2-p15/bin/bash KERNEL_MODULES=/nix/store/hlhp0pprnyq96npl2k1b5z9iy2xc4c9q-linux-6.10-dev/lib/modules/6.10.0
ln -sf /build/yqbc1sl5vllprykl9fmm872br9fp88s5-source/Makefile /build/yqbc1sl5vllprykl9fmm872br9fp88s5-source/src/
make -C /nix/store/hlhp0pprnyq96npl2k1b5z9iy2xc4c9q-linux-6.10-dev/lib/modules/6.10.0/build M=/build/yqbc1sl5vllprykl9fmm872br9fp88s5-source/obj/ src=/build/yqbc1sl5vllprykl9fmm872br9fp88s5-source/src/ modules
make[1]: Entering directory '/nix/store/hlhp0pprnyq96npl2k1b5z9iy2xc4c9q-linux-6.10-dev/lib/modules/6.10.0/build'
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: gcc (GCC) 13.3.0
  You are using:           gcc (GCC) 12.2.0
make[3]: *** No rule to make target '/build/yqbc1sl5vllprykl9fmm872br9fp88s5-source/obj/asus_wmi_screenpad.o', needed by '/build/yqbc1sl5vllprykl9fmm872br9fp88s5-source/obj/'.  Stop.
make[2]: *** [/nix/store/hlhp0pprnyq96npl2k1b5z9iy2xc4c9q-linux-6.10-dev/lib/modules/6.10.0/source/Makefile:1934: /build/yqbc1sl5vllprykl9fmm872br9fp88s5-source/obj] Error 2
make[1]: *** [/nix/store/hlhp0pprnyq96npl2k1b5z9iy2xc4c9q-linux-6.10-dev/lib/modules/6.10.0/source/Makefile:240: __sub-make] Error 2
make[1]: Leaving directory '/nix/store/hlhp0pprnyq96npl2k1b5z9iy2xc4c9q-linux-6.10-dev/lib/modules/6.10.0/build'
make: *** [Makefile:12: all] Error 2

If I’m reading this correctly, I’m using the wrong version of gcc to build the package? Does this mean I need to override gcc in the build? If so, how would I go about doing this?