Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux kernel cannot be built in NixOS #5162

Open
Freed-Wu opened this issue May 28, 2024 · 1 comment
Open

Linux kernel cannot be built in NixOS #5162

Freed-Wu opened this issue May 28, 2024 · 1 comment
Labels

Comments

@Freed-Wu
Copy link
Contributor

Freed-Wu commented May 28, 2024

Xmake Version

v2.9.1+20240422

Operating System Version and Architecture

6.9.1

Describe Bug

$ git clone --depth=1 --recursive https://github.com/xmake-io/xmake
$ cd xmake/tests/projects/linux/driver/hello_custom
$ nix-env -iA nixos.linuxPackages_latest.kernel.dev
$ nix eval --impure --expr '"${(import <nixpkgs> {}).linuxPackages_latest.kernel.dev}"'
"/nix/store/cajf6mwyfm0r8dpa12chcj2hpla1yzk0-linux-6.9.1-dev"
$ xmake -f --linux-headers=/nix/store/cajf6mwyfm0r8dpa12chcj2hpla1yzk0-linux-6.9.1-dev/lib/modules/6.9.1/source
$ xmake -rv
[ 40%]: cache compiling.release src/add.c
/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/gcc -c -m64 -DKBUILD_MODNAME=\"hello\" -DKBUILD_BASENAME=\"add\" -o build/.objs/hello/linux/x86_64/release/src/add.c.o src/add.c
[ 60%]: cache compiling.release src/hello.c
/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/gcc -c -m64 -DKBUILD_MODNAME=\"hello\" -DKBUILD_BASENAME=\"hello\" -o build/.objs/hello/linux/x86_64/release/src/hello.c.o src/hello.c
error: src/hello.c:1:10: fatal error: linux/init.h: No such file or directory
    1 | #include <linux/init.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.

I think that is because NixOS's linux headers is a little different:

That is ArchLinux:

$ ls /usr/src/linux -dl
Permissions Size User Date Modified Name
lrwxrwxrwx     - root 18 May 00:56   /usr/src/linux -> ../lib/modules/6.9.1-arch1-1/build
$ ls /usr/src/linux -l
 arch    crypto    include   kernel                   localversion.20-pkgname   Module.symvers   scripts    System.map   version   vmlinux.h
 block   drivers   init      lib                      Makefile                  net              security   tools        virt
 certs   fs        Kconfig   localversion.10-pkgrel   mm                        samples          sound      usr          vmlinux

This is NixOS:

$ nix eval --impure --expr '"${(import <nixpkgs> {}).linuxPackages_latest.kernel.dev}"'
"/nix/store/cajf6mwyfm0r8dpa12chcj2hpla1yzk0-linux-6.9.1-dev"
$ ls /nix/store/cajf6mwyfm0r8dpa12chcj2hpla1yzk0-linux-6.9.1-dev/lib/modules/6.9.1
 build   source
$ ls /nix/store/cajf6mwyfm0r8dpa12chcj2hpla1yzk0-linux-6.9.1-dev/lib/modules/6.9.1/build
 arch   include   kernel   Makefile   Module.symvers   scripts   source   tools
$ ls /nix/store/cajf6mwyfm0r8dpa12chcj2hpla1yzk0-linux-6.9.1-dev/lib/modules/6.9.1/source
 arch    certs    Documentation   include   io_uring   kernel   Makefile   net    samples   security   tools   virt
 block   crypto   fs              init      ipc        lib      mm         rust   scripts   sound      usr
$ ls /nix/store/cajf6mwyfm0r8dpa12chcj2hpla1yzk0-linux-6.9.1-dev/lib/modules/6.9.1/build/source -dl
Permissions Size User Date Modified Name
lrwxrwxrwx     - root  1 Jan  1970   /nix/store/cajf6mwyfm0r8dpa12chcj2hpla1yzk0-linux-6.9.1-dev/lib/modules/6.9.1/build/source -> ../source

Expected Behavior

Can work.

Project Configuration

xmake test example.

Additional Information and Error Logs

If we cannot find some files in /nix/store/XXX/lib/modules/6.9.1/build, we should search /nix/store/XXX/lib/modules/6.9.1/build/source as a fallback for NixOS.

@Freed-Wu Freed-Wu added the bug label May 28, 2024
@waruqi
Copy link
Member

waruqi commented May 29, 2024

you can try use linux-header from xmake-repo.

add_requires("linux-headers", {configs = {driver_modules = true}})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants