nixpkgs/pkgs/os-specific/linux/kernel-headers/4.4.nix
John Ericson 791ce593ce linux-headers: Improve derivation, removing cross arg
- Perl is used at build time, so must be in `nativeBuildInputs`. It's
   not used at run time so it should not be in `buildInputs`, too.

 - Don't treat headers like a compiler---use the build and host
   platforms not host and target. Perhaps that would make sense if every
   library's headers could be a separate derivation, but since that is
   not feasible, best to keep the implementation and interface in the
   same stage.

   To do this, we used `stdenvNoCC` to get rid of the normal toolchain,
   and added a dependency for the toolchain targeting the build platform
   --- `buildPackages.stdenv.cc` --- thus everything is effectively slid
   a stage black.
2017-08-24 11:31:56 -04:00

65 lines
1.9 KiB
Nix

{ stdenvNoCC, lib, buildPackages
, buildPlatform, hostPlatform
, fetchurl, perl
}:
assert hostPlatform.isLinux;
let
version = "4.4.10";
inherit (hostPlatform.platform) kernelHeadersBaseConfig;
in
stdenvNoCC.mkDerivation {
name = "linux-headers-${version}";
src = fetchurl {
url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
sha256 = "1kpjvvd9q9wwr3314q5ymvxii4dv2d27295bzly225wlc552xhja";
};
targetConfig = if hostPlatform != buildPlatform then hostPlatform.config else null;
platform = hostPlatform.platform.kernelArch or (
if hostPlatform.system == "i686-linux" then "i386" else
if hostPlatform.system == "x86_64-linux" then "x86_64" else
if hostPlatform.system == "powerpc-linux" then "powerpc" else
if hostPlatform.isArm then "arm" else
abort "don't know what the kernel include directory is called for this platform");
# 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.
nativeBuildInputs = [ buildPackages.stdenv.cc perl ];
extraIncludeDirs = lib.optional hostPlatform.isPowerPC ["ppc"];
buildPhase = ''
if test -n "$targetConfig"; then
export ARCH=$platform
fi
make ${kernelHeadersBaseConfig} SHELL=bash
make mrproper headers_check SHELL=bash
'';
installPhase = ''
make INSTALL_HDR_PATH=$out headers_install
# Some builds (e.g. KVM) want a kernel.release.
mkdir -p $out/include/config
echo "${version}-default" > $out/include/config/kernel.release
'';
# !!! hacky
fixupPhase = ''
ln -s asm $out/include/asm-$platform
if test "$platform" = "i386" -o "$platform" = "x86_64"; then
ln -s asm $out/include/asm-x86
fi
'';
meta = with lib; {
description = "Header files and scripts for Linux kernel";
license = licenses.gpl2;
platforms = platforms.linux;
};
}