about summary refs log tree commit diff
path: root/nixpkgs/pkgs/os-specific/linux/kernel-headers
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/os-specific/linux/kernel-headers')
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel-headers/default.nix85
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel-headers/no-dynamic-cc-version-check.patch32
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel-headers/no-relocs.patch13
3 files changed, 130 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel-headers/default.nix b/nixpkgs/pkgs/os-specific/linux/kernel-headers/default.nix
new file mode 100644
index 000000000000..eb0059f55c35
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel-headers/default.nix
@@ -0,0 +1,85 @@
+{ stdenvNoCC, lib, buildPackages
+, fetchurl, fetchpatch, perl
+, elf-header
+}:
+
+let
+  common = { version, sha256, patches ? [] }: stdenvNoCC.mkDerivation {
+    name = "linux-headers-${version}";
+
+    src = fetchurl {
+      url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
+      inherit sha256;
+    };
+
+    ARCH = stdenvNoCC.hostPlatform.platform.kernelArch or (throw "missing kernelArch");
+
+    # 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 ];
+    # `elf-header` is null when libc provides `elf.h`.
+    nativeBuildInputs = [ perl elf-header ];
+
+    extraIncludeDirs = lib.optional stdenvNoCC.hostPlatform.isPowerPC ["ppc"];
+
+    inherit patches;
+
+    hardeningDisable = lib.optional stdenvNoCC.buildPlatform.isDarwin "format";
+
+    makeFlags = [
+      "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)"
+    ];
+
+    # Skip clean on darwin, case-sensitivity issues.
+    buildPhase = 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
+    '';
+
+    checkPhase = ''
+      make headers_check $makeFlags
+    '';
+
+    installPhase = ''
+      make headers_install INSTALL_HDR_PATH=$out $makeFlags
+    ''
+    # Some builds (e.g. KVM) want a kernel.release.
+    + '' mkdir -p $out/include/config
+      echo "${version}-default" > $out/include/config/kernel.release
+    ''
+    # These oddly named file records teh `SHELL` passed, which causes bootstrap
+    # tools run-time dependency.
+    + ''
+      find "$out" -name '..install.cmd' -print0 | xargs -0 rm
+    '';
+
+    meta = with lib; {
+      description = "Header files and scripts for Linux kernel";
+      license = licenses.gpl2;
+      platforms = platforms.linux;
+    };
+  };
+in {
+
+  linuxHeaders = common {
+    version = "4.18.3";
+    sha256 = "1m23hjd02bg8mqnd8dc4z4m3kxds1cyrc6j5saiwnhzbz373rvc1";
+    patches = [
+       ./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
+    ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel-headers/no-dynamic-cc-version-check.patch b/nixpkgs/pkgs/os-specific/linux/kernel-headers/no-dynamic-cc-version-check.patch
new file mode 100644
index 000000000000..9b582cac7153
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel-headers/no-dynamic-cc-version-check.patch
@@ -0,0 +1,32 @@
+diff --git a/Makefile b/Makefile
+index 863f58503bee..b778d5023208 100644
+--- a/Makefile
++++ b/Makefile
+@@ -501,11 +501,9 @@ KBUILD_CFLAGS      += $(call cc-option,-fno-PIE)
+ KBUILD_AFLAGS  += $(call cc-option,-fno-PIE)
+ 
+ # check for 'asm goto'
+-ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
+   CC_HAVE_ASM_GOTO := 1
+   KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
+   KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
+-endif
+ 
+ # The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
+ # Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
+diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
+index 065324a8046f..d09c67194549 100644
+--- a/scripts/Kbuild.include
++++ b/scripts/Kbuild.include
+@@ -216,11 +216,8 @@ cc-disable-warning = $(call try-run-cached,\
+ cc-name = $(call shell-cached,$(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)
+ 
+ # cc-version
+-cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
+ 
+ # cc-fullversion
+-cc-fullversion = $(shell $(CONFIG_SHELL) \
+-	$(srctree)/scripts/gcc-version.sh -p $(CC))
+ 
+ # cc-ifversion
+ # Usage:  EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel-headers/no-relocs.patch b/nixpkgs/pkgs/os-specific/linux/kernel-headers/no-relocs.patch
new file mode 100644
index 000000000000..67e8b19e23bd
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel-headers/no-relocs.patch
@@ -0,0 +1,13 @@
+diff --git a/arch/x86/Makefile b/arch/x86/Makefile
+index fad55160dcb9..a48c8331cbb2 100644
+--- a/arch/x86/Makefile
++++ b/arch/x86/Makefile
+@@ -239,7 +239,7 @@ ifdef CONFIG_RETPOLINE
+ endif
+ 
+ archscripts: scripts_basic
+-	$(Q)$(MAKE) $(build)=arch/x86/tools relocs
++	$(Q)$(MAKE) $(build)=arch/x86/tools
+ 
+ ###
+ # Syscall table generation