How to provide missing headers to a kernel build?

I’m trying to fix an issue with my NVMe drive not showing up on my NanoPC-T4 which was recently made functional by @tmountain(Thanks!). I checked that FriendlyARM has their own distro called FriendlyCore which does detect it and found their fork of kernel:

I’m trying to build that kernel like this:

  boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.linux_4_4.override {
    argsOverride = rec {
      src = pkgs.fetchzip {
            url = "https://github.com/friendlyarm/kernel-rockchip/archive/3dd9af3221d2a4ea4caf2865bac5fe9aaf2e2643.zip";
            sha256 = "0x4bfw90bc3diz8763frjscs5sq7lmc4ij03c0vgxr6ahr9axm5c";
      };
      version = "4.4.179";
      modDirVersion = "4.4.179";
      };
  });
  # Fix for Error: selected processor does not support `crc32x w0,w0,x1'
  # See: https://github.com/NixOS/nixpkgs/issues/64916
  boot.kernelPatches = [{
    name = "aarch64-march-fix.patch";
    patch = ./aarch64-march-fix.patch;
  }];

But it’s failing with the following errors:

../include/drm/drm_edid.h:27:10: fatal error: linux/hdmi.h: No such file or directory
../include/drm/drm_crtc.h:33:10: fatal error: linux/hdmi.h: No such file or directory

And I’m not sure how I’m supposed to provide the missing header.

I was looking at pkgs/os-specific/linux/kernel/generic.nix but I can’t seem to find anything that matches what I need.

I’m aware the simplest way to fix my issue would be to apply the specific patch to normal NixOS kernel instead of building a custom one, but I actually have no clue which patch in friendlyarm/kernel-rockchip fixes my issue. I just know that Friendly Core image with 4.19.111 kernel makes the NVMe drive work.

I have abandoned my attempt to build a custom kernel, and instead tried to use a similar kernel config to the one used by Armbian, and by comparing I found a few settings that were baked in instead of included as modules. By using this config and recompiling the kernel I managed to fix the NVMe detection problem:

{
  boot.kernelPackages = pkgs.linuxPackages_5_10;
  boot.kernelPatches = [{
    name = "pcie-rockchip-config.patch";
    patch = null;
    extraConfig = ''
      LOCALVERSION_AUTO n
      COMPILE_TEST y
      NVME_CORE y
      BLK_DEV_NVME y
      NVME_MULTIPATH y
      PCIE_ROCKCHIP y
      PCIE_ROCKCHIP_HOST y
      PCIE_ROCKCHIP_EP y
      ROCKCHIP_THERMAL y
      ROCKCHIP_LVDS y
      ROCKCHIP_MBOX y
      DEVFREQ_EVENT_ROCKCHIP_DFI y
      ROCKCHIP_SARADC y
      PHY_ROCKCHIP_DP y
      PHY_ROCKCHIP_INNO_HDMI y
      PHY_ROCKCHIP_INNO_USB3 y
      PHY_ROCKCHIP_PCIE y
      PHY_ROCKCHIP_USB y
    '';
  }];
}

I’m trying to do a similar thing to get my GPD Pocket to work with a newer kernel on NixOS. Did you basically diff the .config from somewhere in the nix store with the known-good .config?

Yes, exactly. You can easily find the current kernel config by doing:

zcat /proc/config.gz > ~/kernel_config

I essentially booted a working Armbian image on my NanoPC-T4 from an SD card and copied the kernel config from /proc/config.gz, and then compared it against the on on NixOS(with vimdiff in my case), and found the set of settings that were enabled with y(baked in) rather than m(modules) and tried a few until it worked.

2 Likes