1{ stdenvNoCC, lib, buildPackages
2, buildPlatform, hostPlatform
3, fetchurl, perl
4}:
5
6assert hostPlatform.isLinux;
7
8let
9 version = "4.4.10";
10 inherit (hostPlatform.platform) kernelHeadersBaseConfig;
11in
12
13stdenvNoCC.mkDerivation {
14 name = "linux-headers-${version}";
15
16 src = fetchurl {
17 url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
18 sha256 = "1kpjvvd9q9wwr3314q5ymvxii4dv2d27295bzly225wlc552xhja";
19 };
20
21 targetConfig = if hostPlatform != buildPlatform then hostPlatform.config else null;
22
23 platform = hostPlatform.platform.kernelArch or (
24 if hostPlatform.system == "i686-linux" then "i386" else
25 if hostPlatform.system == "x86_64-linux" then "x86_64" else
26 if hostPlatform.system == "powerpc-linux" then "powerpc" else
27 if hostPlatform.isArm then "arm" else
28 abort "don't know what the kernel include directory is called for this platform");
29
30 # It may look odd that we use `stdenvNoCC`, and yet explicit depend on a cc.
31 # We do this so we have a build->build, not build->host, C compiler.
32 nativeBuildInputs = [ buildPackages.stdenv.cc perl ];
33
34 extraIncludeDirs = lib.optional hostPlatform.isPowerPC ["ppc"];
35
36 buildPhase = ''
37 if test -n "$targetConfig"; then
38 export ARCH=$platform
39 fi
40 make ${kernelHeadersBaseConfig} SHELL=bash
41 make mrproper headers_check SHELL=bash
42 '';
43
44 installPhase = ''
45 make INSTALL_HDR_PATH=$out headers_install
46
47 # Some builds (e.g. KVM) want a kernel.release.
48 mkdir -p $out/include/config
49 echo "${version}-default" > $out/include/config/kernel.release
50 '';
51
52 # !!! hacky
53 fixupPhase = ''
54 ln -s asm $out/include/asm-$platform
55 if test "$platform" = "i386" -o "$platform" = "x86_64"; then
56 ln -s asm $out/include/asm-x86
57 fi
58 '';
59
60 meta = with lib; {
61 description = "Header files and scripts for Linux kernel";
62 license = licenses.gpl2;
63 platforms = platforms.linux;
64 };
65}