Help loading kernel module from store

Greetings,
I’m trying to install the lenovo-legion package and associated kernel module, but can’t seem to get them to work. From my investigation, it would appear that the kernel module isn’t loading. The method I’m using is through the configuration.nix file in which I’d included:

  environment.systemPackages = with pkgs; [
    pkgs.linuxKernel.packages.linux_6_8.lenovo-legion-module
    pkgs.lenovo-legion
  ];

  boot.kernelPackages = pkgs.linuxPackages_latest;

it would appear to me that I’m missing a step or two to actually enable the kernel package from the lenovo-legion-module, but I can’t seem to figure out what to do. I’d attempted to go through the documentation at https://nixos.wiki/wiki/Linux_kernel

The custom module section suggested including

  boot.extraModulePackages = with config.boot.kernelPackages; [ lenovo-legion-module ];

but that caused an error during

sudo nixos-rebuild switch && reboot

Thank you in advance for any help or insight

Managed to solve it myself, indluding my solution for posterity:

  boot.kernelPackages = pkgs.linuxPackages_latest;
  
  environment.systemPackages = with pkgs; [
    pkgs.lenovo-legion
    pkgs.linuxKernel.packages.linux_latest_libre.lenovo-legion-module
  ];

  boot.extraModulePackages = with config.boot.kernelPackages;
    [ lenovo-legion-module ];
  
  boot.kernelModules = [ 
    "lenovo-legion-module" 
  ];

Although valid your config is a bit redundant. Since this is the only thing that led me to finding out this package needs a module here’s a more concise configuration with why it is needed:

  boot = {
    # Kernel
    # absolutely don't need this, but use if you want to switch to a different kernel
    kernelPackages = pkgs.linuxPackages_latest; 
    # Kernel modules
    extraModulePackages = with config.boot.kernelPackages; [ lenovo-legion-module ];
    # config.boot.kernelPackages already grabs your current kernel version for safety
    kernelModules = [ "lenovo-legion-module" ];
  };