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