Kernel Headers Missing

I’m trying to compile the kernel module but I can’t find the location of the kernel headers. I found and installed the linuxHeaders package via Nix search but I couldn’t solve the problem.

Makefile:

MODULE      := hotfix-kvadra-touchpad

obj-m       := $(MODULE).o
$(MODULE)-objs  := module.o

PWD := $(shell pwd)

all:
    echo $(PWD)
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

install: install_module
    install -Dm644 hotfix-kvadra-touchpad.conf /usr/lib/modules-load.d/hotfix-kvadra-touchpad.conf

install_module:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules_install

the command I’have run:

sudo make all

Output:

echo /home/faruk/Projects/hotfix-kvadra-touchpad
/home/faruk/Projects/hotfix-kvadra-touchpad
make -C /lib/modules/6.15.6/build M=/home/faruk/Projects/hotfix-kvadra-touchpad modules
make[1]: Entering directory '/home/faruk/Projects/hotfix-kvadra-touchpad'
make[1]: *** /lib/modules/6.15.6/build: No such file or directory.  Stop.
make[1]: Leaving directory '/home/faruk/Projects/hotfix-kvadra-touchpad'
make: *** [Makefile:10: all] Error 2

The module I’m trying to compile: GitHub - alexpevzner/hotfix-kvadra-touchpad: Kernel module that provides hotfix for touchpad issues for KVADRA NAU LE14U and similar

Have you tried making a nix shell, with the kernel headers?

hotfix-kvadra-touchpad on  master [?] via  v14.2.1-gcc took 37s 
❯ uname -r
6.15.6
hotfix-kvadra-touchpad on  master [?] via  v14.2.1-gcc 
❯ nix-shell
hotfix-kvadra-touchpad on  master [?] via  v14.2.1-gcc via  impure (shell) 
❯ uname -r
6.15.6
hotfix-kvadra-touchpad on  master [?] via  v14.2.1-gcc via  impure (shell) 
❯ nix eval --raw nixpkgs#linuxHeaders
/nix/store/ml8m9via9a0d4ixk9zz1s477lyjvvrk8-linux-headers-6.14.7

the shell.nix I’ve used:

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  name = "shell";

  buildInputs = [
    pkgs.gcc
    pkgs.gnumake
    pkgs.linuxHeaders
  ];
}
ls -lah /nix/store/ml8m9via9a0d4ixk9zz1s477lyjvvrk8-linux-headers-6.14.7
"/nix/store/ml8m9via9a0d4ixk9zz1s477lyjvvrk8-linux-headers-6.14.7": No such file or directory (os error 2)

I don’t think mixing and matching how you are pulling in nixpkgs is going to yield much insight. If you want to find the path your shell is using

❯ nix repl --file '<nixpkgs>'
Nix 2.28.4
Type :? for help.
Loading installable ''...
Added 24773 variables.
nix-repl> :b pkgs.linuxHeaders

This derivation produced the following outputs:
  out -> /nix/store/1vrsi68s2y6xjk3pcfim09ary675lmc3-linux-headers-6.12.7



~                                                                                  5s 14:18:38
❯ lt -D /nix/store/1vrsi68s2y6xjk3pcfim09ary675lmc3-linux-headers-6.12.7
/nix/store/1vrsi68s2y6xjk3pcfim09ary675lmc3-linux-headers-6.12.7
└── include
    ├── asm
    ├── asm-generic
    ├── config
    ├── drm
    ├── linux
    │   ├── android
    │   ├── byteorder
    │   ├── caif
    │   ├── can
    │   ├── cifs
    │   ├── dvb
    │   ├── genwqe
    │   ├── hdlc
    │   ├── hsi
nix repl --file '<nixpkgs>'
Nix 2.28.4
Type :? for help.
Loading installable ''...
Added 24774 variables.
nix-repl> :b pkgs.linuxHeaders

This derivation produced the following outputs:
  out -> /nix/store/1vrsi68s2y6xjk3pcfim09ary675lmc3-linux-headers-6.12.7

nix-repl> 
ll /nix/store/1vrsi68s2y6xjk3pcfim09ary675lmc3-linux-headers-6.12.7/
Permissions Size User Date Modified Name
dr-xr-xr-x     - root  1 Oca  1970   include

Still need help, I can’t solve the problem

I’ve solved the problem.

The ‘shell.nix’ file that I’ve created:

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  buildInputs = [
    pkgs.linuxPackages_latest.kernel.dev
    pkgs.gcc
    pkgs.gnumake
  ];

  shellHook = ''
    export KERNEL_DIR=${pkgs.linuxPackages_latest.kernel.dev}/lib/modules/${pkgs.linuxPackages_latest.kernel.modDirVersion}/build
    echo "KERNEL_DIR set to $KERNEL_DIR"
  '';
}

then entered using nix-shell command and compiled kernel module.

1 Like