Install kernel package from unstable when using a custom kernel


I am running nixos on a Microsoft surface 7 pro. I use the nix module from nixos-hardware here:

I want to use a new module named ithc for the device I added recently and which is not in stable yet:

In my flake I added the following inputs and overlay to enable having access to a pkgs.unstable when I need it :

  inputs = {
    nixpkgs.url = "nixpkgs/nixos-22.05";
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
    nixos-hardware.url = github:NixOS/nixos-hardware/master;
  outputs = { nixpkgs, nixos-hardware, nixpkgs-unstable, ... }:
      system = "x86_64-linux";
      overlay-unstable = final: prev: {
        unstable = import nixpkgs-unstable {
          inherit system;
          config.allowUnfree = true;
    surface = nixpkgs.lib.nixosSystem {
          inherit system;
          modules = [
            ({ config, pkgs, ... }: { nixpkgs.overlays = [ overlay-unstable ]; })

My problem is that when I add the ithc module to extraModulePackages: It is unable to find it (error: undefined variable 'ithc')
extraModulePackages = with config.boot.kernelPackages; [ xpadneo ithc ];

I think I need to tell it to find the ithc module in pkgs.unstable instead of the kernelPackages coming from surface specific module but I don’t know how to do that.

I doubt this is trivial, unfortunately. The modules are strictly coupled to their packages, mixing multiple kernel/packages is probably a bad idea. Consider using unstable entirely until your changes stabilize.

The variable you’re grabbing those modules from is boot.kernelPackages, by the way, which in your case will probably be the default kernel.

Perhaps just setting that to a kernel from unstable will fix the problem, but note you’ll be running a kernel nobody else is testing your software with, so I’m not sure this gives you any stability whatsoever.

Looks like the surface config they’re importing builds a custom kernel.

I don’t think it should be as hard as you’re saying. Their problem is simply that adding a pkgs.unstable variable doesn’t magically add new kernel module packages to main nixos kernel module packages.

They should just be able to use config.boot.kernelPackages.callPackage to call the Nix expression out of the unstable repo and add that to extraModulePackages. Maybe something like this would work?

  boot.extraModulePackages = [
      "${pkgs.unstable.path}/pkgs/os-specific/linux/ithc/default.nix" {})

EDIT: Alternatively they could re-import the kernel packages expression from the surface stuff in nixos-hardware using the unstable pkgs and set kernelPackages to that. Though they’ll have to mkForce it since the surface code sets it.

  boot.kernelPackages = lib.mkForce (pkgs.unstable.callPackage
    "${nixos-hardware}/nixos-hardware/microsoft/surface/kernel/linux-5.16.11.nix" {});

I’m less sure this would work. But if it does, it would recreate kernelPackages using nixos unstable sources and that surface kernel expression, meaning it would include all the kernel packages in unstable.

1 Like

Thanks for the answers !
I put as @ElvishJerricco said and it worked.

 boot.extraModulePackages = [
      "${pkgs.unstable.path}/pkgs/os-specific/linux/ithc/default.nix" {})

Shall I ask to the author of the custom kernel derivation to integrate it in the nixpkgs repo ? There are already other custom kernels such as zen and It would avoid the lengthy kernel compilation when I upgrade or garbage collect my store.

Custom kernels in nixpkgs are something we’re moving away from. nixos-hardware is where we’d prefer for them to be nowadays.

Hosted by Flying Circus.