2018-01-14 00:28:11 +03:00
|
|
|
{ stdenvNoCC, lib, buildPackages
|
2018-01-27 01:40:40 +03:00
|
|
|
, fetchurl, fetchpatch, perl
|
|
|
|
, elf-header
|
2018-01-14 00:28:11 +03:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2018-01-27 01:40:40 +03:00
|
|
|
common = { version, sha256, patches ? [] }: stdenvNoCC.mkDerivation ({
|
2018-01-14 00:28:11 +03:00
|
|
|
name = "linux-headers-${version}";
|
|
|
|
|
|
|
|
src = fetchurl {
|
|
|
|
url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
|
|
|
|
inherit sha256;
|
|
|
|
};
|
|
|
|
|
2018-09-11 20:27:13 +03:00
|
|
|
ARCH = stdenvNoCC.hostPlatform.platform.kernelArch or (throw "missing kernelArch");
|
2018-01-14 00:28:11 +03:00
|
|
|
|
|
|
|
# It may look odd that we use `stdenvNoCC`, and yet explicit depend on a cc.
|
|
|
|
# We do this so we have a build->build, not build->host, C compiler.
|
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
2018-01-27 01:40:40 +03:00
|
|
|
# TODO make unconditional next mass rebuild
|
|
|
|
nativeBuildInputs = [ perl ] ++ lib.optional
|
|
|
|
(stdenvNoCC.hostPlatform != stdenvNoCC.buildPlatform)
|
|
|
|
elf-header;
|
2018-01-14 00:28:11 +03:00
|
|
|
|
2018-08-20 21:43:41 +03:00
|
|
|
extraIncludeDirs = lib.optional stdenvNoCC.hostPlatform.isPowerPC ["ppc"];
|
2018-01-14 00:28:11 +03:00
|
|
|
|
|
|
|
# "patches" array defaults to 'null' to avoid changing hash
|
|
|
|
# and causing mass rebuild
|
|
|
|
inherit patches;
|
|
|
|
|
2018-01-27 01:40:40 +03:00
|
|
|
# TODO avoid native hack next rebuild
|
|
|
|
makeFlags = if stdenvNoCC.hostPlatform == stdenvNoCC.buildPlatform then null else [
|
|
|
|
"SHELL=bash"
|
|
|
|
# Avoid use of runtime build->host compilers for checks. These
|
|
|
|
# checks only cared to work around bugs in very old compilers, so
|
|
|
|
# these changes should be safe.
|
|
|
|
"cc-version:=9999"
|
|
|
|
"cc-fullversion:=999999"
|
|
|
|
# `$(..)` expanded by make alone
|
|
|
|
"HOSTCC:=$(BUILD_CC)"
|
|
|
|
"HOSTCXX:=$(BUILD_CXX)"
|
|
|
|
];
|
|
|
|
|
|
|
|
# TODO avoid native hack next rebuild
|
|
|
|
# Skip clean on darwin, case-sensitivity issues.
|
|
|
|
buildPhase = if stdenvNoCC.hostPlatform == stdenvNoCC.buildPlatform then ''
|
2018-01-14 00:28:11 +03:00
|
|
|
make mrproper headers_check SHELL=bash
|
2018-01-27 01:40:40 +03:00
|
|
|
'' else lib.optionalString (!stdenvNoCC.buildPlatform.isDarwin) ''
|
|
|
|
make mrproper $makeFlags
|
|
|
|
''
|
|
|
|
# For some reason, doing `make install_headers` twice, first without
|
|
|
|
# INSTALL_HDR_PATH=$out then with, is neccessary to get this to work
|
|
|
|
# for darwin cross. @Ericson2314 has no idea why.
|
|
|
|
+ ''
|
|
|
|
make headers_install $makeFlags
|
|
|
|
'';
|
|
|
|
|
|
|
|
# TODO avoid native hack next rebuild
|
|
|
|
checkPhase = if stdenvNoCC.hostPlatform == stdenvNoCC.buildPlatform then null else ''
|
|
|
|
make headers_check $makeFlags
|
2018-01-14 00:28:11 +03:00
|
|
|
'';
|
|
|
|
|
2018-01-27 01:40:40 +03:00
|
|
|
# TODO avoid native hack next rebuild
|
|
|
|
installPhase = (if stdenvNoCC.hostPlatform == stdenvNoCC.buildPlatform then ''
|
2018-01-14 00:28:11 +03:00
|
|
|
make INSTALL_HDR_PATH=$out headers_install
|
2018-01-27 01:40:40 +03:00
|
|
|
'' else ''
|
|
|
|
make headers_install INSTALL_HDR_PATH=$out $makeFlags
|
|
|
|
'') + ''
|
2018-01-14 00:28:11 +03:00
|
|
|
|
|
|
|
# Some builds (e.g. KVM) want a kernel.release.
|
|
|
|
mkdir -p $out/include/config
|
|
|
|
echo "${version}-default" > $out/include/config/kernel.release
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "Header files and scripts for Linux kernel";
|
|
|
|
license = licenses.gpl2;
|
|
|
|
platforms = platforms.linux;
|
|
|
|
};
|
2018-01-27 01:40:40 +03:00
|
|
|
} // lib.optionalAttrs (stdenvNoCC.hostPlatform != stdenvNoCC.buildPlatform) {
|
|
|
|
# TODO Make unconditional next mass rebuild
|
|
|
|
hardeningDisable = lib.optional stdenvNoCC.buildPlatform.isDarwin "format";
|
|
|
|
});
|
2018-01-14 00:28:11 +03:00
|
|
|
in {
|
|
|
|
|
2018-02-19 00:59:29 +03:00
|
|
|
linuxHeaders = common {
|
2018-01-31 02:17:45 +03:00
|
|
|
version = "4.15";
|
|
|
|
sha256 = "0sd7l9n9h7vf9c6gd6ciji28hawda60yj0llh17my06m0s4lf9js";
|
2018-01-27 01:40:40 +03:00
|
|
|
# TODO make unconditional next mass rebuild
|
|
|
|
patches = lib.optionals (stdenvNoCC.hostPlatform != stdenvNoCC.buildPlatform) [
|
|
|
|
./no-relocs.patch # for building x86 kernel headers on non-ELF platforms
|
|
|
|
./no-dynamic-cc-version-check.patch # so we can use `stdenvNoCC`, see `makeFlags` above
|
|
|
|
];
|
2018-01-14 00:28:11 +03:00
|
|
|
};
|
|
|
|
}
|