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.
This commit is contained in:
John Ericson 2017-07-09 15:12:32 -04:00
parent 9884a3b17a
commit 791ce593ce
2 changed files with 20 additions and 29 deletions

View File

@ -1,19 +1,16 @@
{ stdenv, fetchurl, perl, cross ? null }: { stdenvNoCC, lib, buildPackages
, buildPlatform, hostPlatform
, fetchurl, perl
}:
assert cross == null -> stdenv.isLinux; assert hostPlatform.isLinux;
let let
version = "4.4.10"; version = "4.4.10";
inherit (hostPlatform.platform) kernelHeadersBaseConfig;
kernelHeadersBaseConfig =
if cross == null
then stdenv.platform.kernelHeadersBaseConfig
else cross.platform.kernelHeadersBaseConfig;
in in
stdenv.mkDerivation { stdenvNoCC.mkDerivation {
name = "linux-headers-${version}"; name = "linux-headers-${version}";
src = fetchurl { src = fetchurl {
@ -21,23 +18,20 @@ stdenv.mkDerivation {
sha256 = "1kpjvvd9q9wwr3314q5ymvxii4dv2d27295bzly225wlc552xhja"; sha256 = "1kpjvvd9q9wwr3314q5ymvxii4dv2d27295bzly225wlc552xhja";
}; };
targetConfig = if cross != null then cross.config else null; targetConfig = if hostPlatform != buildPlatform then hostPlatform.config else null;
platform = platform = hostPlatform.platform.kernelArch or (
if cross != null then cross.platform.kernelArch else if hostPlatform.system == "i686-linux" then "i386" else
if stdenv.system == "i686-linux" then "i386" else if hostPlatform.system == "x86_64-linux" then "x86_64" else
if stdenv.system == "x86_64-linux" then "x86_64" else if hostPlatform.system == "powerpc-linux" then "powerpc" else
if stdenv.system == "powerpc-linux" then "powerpc" else if hostPlatform.isArm then "arm" else
if stdenv.isArm then "arm" else abort "don't know what the kernel include directory is called for this platform");
if stdenv.platform ? kernelArch then stdenv.platform.kernelArch else
abort "don't know what the kernel include directory is called for this platform";
buildInputs = [perl]; # 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 = extraIncludeDirs = lib.optional hostPlatform.isPowerPC ["ppc"];
if cross != null then
(if cross.arch == "powerpc" then ["ppc"] else [])
else if stdenv.system == "powerpc-linux" then ["ppc"] else [];
buildPhase = '' buildPhase = ''
if test -n "$targetConfig"; then if test -n "$targetConfig"; then
@ -63,7 +57,7 @@ stdenv.mkDerivation {
fi fi
''; '';
meta = with stdenv.lib; { meta = with lib; {
description = "Header files and scripts for Linux kernel"; description = "Header files and scripts for Linux kernel";
license = licenses.gpl2; license = licenses.gpl2;
platforms = platforms.linux; platforms = platforms.linux;

View File

@ -12021,9 +12021,7 @@ with pkgs;
lkl = callPackage ../applications/virtualization/lkl { }; lkl = callPackage ../applications/virtualization/lkl { };
linuxHeaders_4_4 = callPackage ../os-specific/linux/kernel-headers/4.4.nix { linuxHeaders_4_4 = callPackage ../os-specific/linux/kernel-headers/4.4.nix { };
cross = if targetPlatform != hostPlatform then targetPlatform else null;
};
linuxHeaders = linuxHeaders_4_4; linuxHeaders = linuxHeaders_4_4;
kernelPatches = callPackage ../os-specific/linux/kernel/patches.nix { }; kernelPatches = callPackage ../os-specific/linux/kernel/patches.nix { };
@ -12666,7 +12664,6 @@ with pkgs;
uclibc = callPackage ../os-specific/linux/uclibc { }; uclibc = callPackage ../os-specific/linux/uclibc { };
uclibcCross = lowPrio (callPackage ../os-specific/linux/uclibc { uclibcCross = lowPrio (callPackage ../os-specific/linux/uclibc {
inherit (buildPackages) linuxHeaders;
gccCross = gccCrossStageStatic; gccCross = gccCrossStageStatic;
cross = assert targetPlatform != buildPlatform; targetPlatform; cross = assert targetPlatform != buildPlatform; targetPlatform;
}); });