Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ stdenvNoCC, lib, buildPackages, fetchurl, perl, elf-header }:
2
3let
4 makeLinuxHeaders = { src, version, patches ? [] }: stdenvNoCC.mkDerivation {
5 inherit src;
6
7 pname = "linux-headers";
8 inherit version;
9
10 ARCH = stdenvNoCC.hostPlatform.platform.kernelArch or stdenvNoCC.hostPlatform.kernelArch;
11
12 # It may look odd that we use `stdenvNoCC`, and yet explicit depend on a cc.
13 # We do this so we have a build->build, not build->host, C compiler.
14 depsBuildBuild = [ buildPackages.stdenv.cc ];
15 # `elf-header` is null when libc provides `elf.h`.
16 nativeBuildInputs = [ perl elf-header ];
17
18 extraIncludeDirs = lib.optional stdenvNoCC.hostPlatform.isPowerPC ["ppc"];
19
20 inherit patches;
21
22 hardeningDisable = lib.optional stdenvNoCC.buildPlatform.isDarwin "format";
23
24 makeFlags = [
25 "SHELL=bash"
26 # Avoid use of runtime build->host compilers for checks. These
27 # checks only cared to work around bugs in very old compilers, so
28 # these changes should be safe.
29 "cc-version:=9999"
30 "cc-fullversion:=999999"
31 # `$(..)` expanded by make alone
32 "HOSTCC:=$(CC_FOR_BUILD)"
33 "HOSTCXX:=$(CXX_FOR_BUILD)"
34 ];
35
36 # Skip clean on darwin, case-sensitivity issues.
37 buildPhase = lib.optionalString (!stdenvNoCC.buildPlatform.isDarwin) ''
38 make mrproper $makeFlags
39 '' + ''
40 make headers $makeFlags
41 '';
42
43 checkPhase = ''
44 make headers_check $makeFlags
45 '';
46
47 # The following command requires rsync:
48 # make headers_install INSTALL_HDR_PATH=$out $makeFlags
49 # but rsync depends on popt which does not compile on aarch64 without
50 # updateAutotoolsGnuConfigScriptsHook which is not enabled in stage2,
51 # so we replicate it with cp. This also reduces bootstrap closure size.
52 installPhase = ''
53 mkdir -p $out
54 cp -r usr/include $out
55 find $out -type f ! -name '*.h' -delete
56 ''
57 # Some builds (e.g. KVM) want a kernel.release.
58 + ''
59 mkdir -p $out/include/config
60 echo "${version}-default" > $out/include/config/kernel.release
61 '';
62
63 meta = with lib; {
64 description = "Header files and scripts for Linux kernel";
65 license = licenses.gpl2;
66 platforms = platforms.linux;
67 };
68 };
69in {
70 inherit makeLinuxHeaders;
71
72 linuxHeaders = let version = "5.5"; in
73 makeLinuxHeaders {
74 inherit version;
75 src = fetchurl {
76 url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz";
77 sha256 = "0c131fi6s7vgvka1c0597vnvcmwn1pp968rci5kq64iwj3pd9yx6";
78 };
79 patches = [
80 ./no-relocs.patch # for building x86 kernel headers on non-ELF platforms
81 ];
82 };
83}