Automatically selecting appropriate version of a kernel module package

I’m setting up a drawing tablet following Drawing Tablet - NixOS Wiki, and in the instructions it specifies this configuration:

{
  services.xserver.digimend.enable = true;
  environment.systemPackages = [
    pkgs.linuxKernel.packages.linux_6_9.digimend
  ];
}

Where the Digimend package is selected from https://search.nixos.org/packages?channel=24.05&query=digimend.
In order to get the kernel module I have to manually specify the kernel version, it seems. Is there a way to make it automatically select the appropriate package for the installed kernel? It’s not a big deal on a stable channel where the kernel isn’t updated, but I’m considering switching to unstable for other driver patches, and I want to avoid having to manually update my configuration when a new kernel gets pushed to the unstable channel. Maybe I am also misunderstanding how the kernel and kernel packages get packaged under NixOS. I am a little confused since selecting a packages for a kernel version appears to be done through pkgs.linuxPackages_<kernel>, while selecting this kernel module is done through pkgs.linuxKernel.<kernel>.

1 Like

Your currently selected kernelPackages are available under config.boot.kernelPackages.

{ config, ... }:

{
  services.xserver.digimend.enable = true;
  environment.systemPackages = [
    config.boot.kernelPackages.digimend
  ];
}
1 Like

Btw, this is a good time to learn that any config option’s value (set by any module) can be accessed by any other NixOS module.

If you ever need to use e.g. psql, you should also always take it from config.services.postgresql.package.

I make use of this quite frequently in order to follow the DRY principle when dealing with domain names. I have a module where I can declare a virtual host using a high-level interface. It automatically sets an option’s value to contain the fully-qualified domain name (FQDN) for that virtual host. When configuring the respective service’s module, I then simply reference this value.

1 Like

Oh I did not know that. Updated the wikipage Drawing Tablet Revision History - NixOS Wiki