2014-01-22 01:05:55 +00:00
|
|
|
{ stdenv, perl, buildLinux
|
2008-03-24 19:39:42 +00:00
|
|
|
|
2009-01-15 15:40:23 +00:00
|
|
|
, # The kernel source tarball.
|
|
|
|
src
|
2008-03-24 19:39:42 +00:00
|
|
|
|
2009-01-15 15:40:23 +00:00
|
|
|
, # The kernel version.
|
|
|
|
version
|
|
|
|
|
2013-07-31 22:56:48 +01:00
|
|
|
, # Overrides to the kernel config.
|
|
|
|
extraConfig ? ""
|
|
|
|
|
2011-08-08 21:49:49 +01:00
|
|
|
, # The version number used for the module directory
|
|
|
|
modDirVersion ? version
|
|
|
|
|
2009-01-15 15:40:23 +00:00
|
|
|
, # An attribute set whose attributes express the availability of
|
|
|
|
# certain features in this kernel. E.g. `{iwlwifi = true;}'
|
|
|
|
# indicates a kernel that provides Intel wireless support. Used in
|
|
|
|
# NixOS to implement kernel-specific behaviour.
|
|
|
|
features ? {}
|
|
|
|
|
|
|
|
, # A list of patches to apply to the kernel. Each element of this list
|
2008-03-24 19:39:42 +00:00
|
|
|
# should be an attribute set {name, patch} where `name' is a
|
|
|
|
# symbolic name and `patch' is the actual patch. The patch may
|
|
|
|
# optionally be compressed with gzip or bzip2.
|
2009-01-15 15:40:23 +00:00
|
|
|
kernelPatches ? []
|
2016-01-23 16:58:35 +00:00
|
|
|
, ignoreConfigErrors ? stdenv.platform.name != "pc"
|
2009-09-11 14:16:18 +01:00
|
|
|
, extraMeta ? {}
|
2017-06-28 21:32:25 +01:00
|
|
|
, hostPlatform
|
2009-07-15 22:09:17 +01:00
|
|
|
, ...
|
2008-03-24 19:39:42 +00:00
|
|
|
}:
|
|
|
|
|
2014-08-22 10:57:40 +01:00
|
|
|
assert stdenv.isLinux;
|
2009-11-08 17:19:46 +00:00
|
|
|
|
2008-03-24 19:39:42 +00:00
|
|
|
let
|
|
|
|
|
2009-01-15 15:40:23 +00:00
|
|
|
lib = stdenv.lib;
|
2008-03-24 19:39:42 +00:00
|
|
|
|
2017-09-15 22:07:14 +01:00
|
|
|
# Combine the `features' attribute sets of all the kernel patches.
|
|
|
|
kernelFeatures = lib.fold (x: y: (x.features or {}) // y) ({
|
|
|
|
iwlwifi = true;
|
|
|
|
efiBootStub = true;
|
|
|
|
needsCifsUtils = true;
|
|
|
|
netfilterRPFilter = true;
|
|
|
|
} // features) kernelPatches;
|
|
|
|
|
|
|
|
configWithPlatform = kernelPlatform: import ./common-config.nix {
|
|
|
|
inherit stdenv version kernelPlatform extraConfig;
|
|
|
|
features = kernelFeatures; # Ensure we know of all extra patches, etc.
|
|
|
|
};
|
|
|
|
|
|
|
|
config = configWithPlatform stdenv.platform;
|
|
|
|
configCross = configWithPlatform hostPlatform.platform;
|
|
|
|
|
2010-02-27 21:48:48 +00:00
|
|
|
kernelConfigFun = baseConfig:
|
|
|
|
let
|
|
|
|
configFromPatches =
|
|
|
|
map ({extraConfig ? "", ...}: extraConfig) kernelPatches;
|
|
|
|
in lib.concatStringsSep "\n" ([baseConfig] ++ configFromPatches);
|
|
|
|
|
2014-01-01 14:21:25 +00:00
|
|
|
configfile = stdenv.mkDerivation {
|
2016-01-23 16:58:35 +00:00
|
|
|
inherit ignoreConfigErrors;
|
2014-01-01 14:21:25 +00:00
|
|
|
name = "linux-config-${version}";
|
|
|
|
|
|
|
|
generateConfig = ./generate-config.pl;
|
|
|
|
|
|
|
|
kernelConfig = kernelConfigFun config;
|
|
|
|
|
|
|
|
nativeBuildInputs = [ perl ];
|
|
|
|
|
|
|
|
platformName = stdenv.platform.name;
|
|
|
|
kernelBaseConfig = stdenv.platform.kernelBaseConfig;
|
|
|
|
kernelTarget = stdenv.platform.kernelTarget;
|
|
|
|
autoModules = stdenv.platform.kernelAutoModules;
|
2017-03-23 00:03:37 +00:00
|
|
|
preferBuiltin = stdenv.platform.kernelPreferBuiltin or false;
|
2014-01-01 14:21:25 +00:00
|
|
|
arch = stdenv.platform.kernelArch;
|
|
|
|
|
|
|
|
crossAttrs = let
|
2017-06-28 21:32:25 +01:00
|
|
|
cp = hostPlatform.platform;
|
2014-01-01 14:21:25 +00:00
|
|
|
in {
|
|
|
|
arch = cp.kernelArch;
|
|
|
|
platformName = cp.name;
|
|
|
|
kernelBaseConfig = cp.kernelBaseConfig;
|
|
|
|
kernelTarget = cp.kernelTarget;
|
|
|
|
autoModules = cp.kernelAutoModules;
|
|
|
|
|
|
|
|
# Just ignore all options that don't apply (We are lazy).
|
|
|
|
ignoreConfigErrors = true;
|
|
|
|
|
|
|
|
kernelConfig = kernelConfigFun configCross;
|
2014-01-02 04:56:24 +00:00
|
|
|
|
Greatly reduce kernel closure size
Based on access analysis with strace, I determined an essentially
minimal required set of files from the kernel source that was needed to
build all current kernel packages on 3.10, which ultimately resulted in
keeping 30M of source. Generalizing from that minimal set, which
required ad-hoc specifications of which headers outside of include/ and
arch/*/include and which files in the scripts/ directory should be kept,
to a policy of keeping all non-arch-specific headers that aren't part of
the drivers/ directory and the entire scripts/ directory added an
additional 17M, but there was nothing in the analysis that indicated
that that ad-hoc specification was at all complete so I think the extra
hit is worth the likely greater compatibility.
For reference, we now keep:
* All headers that are NOT in arch/${notTargetArch}/include or drivers/
* The scripts/ directory
* Makefile
* arch/${targetArch}/Makefile
IMO the most likely cause of future problems are the headers in
drivers/, but hopefully they won't actually be needed as they add 50M
Ideally kernel packages would only use include and
arch/${targetArch}/include, but alas this is observably not the case.
master:
* $out
* size: 234M
* references-closure: linux-headers, glibc, attr, acl, zlib, gcc,
coreutils, perl, bash
merge-kernel-builds:
* $out
* size: 152M
* references-closure: none
* $dev
* size: 57M
* references-closure: linux-headers, glibc, zlib, gcc
So even with the non-minimal set we still beat out master. Keeping the
drivers headers would make us only slightly bigger.
Signed-off-by: Shea Levy <shea@shealevy.com>
2014-01-05 11:55:47 +00:00
|
|
|
inherit (kernel.crossDrv) src patches preUnpack;
|
2014-01-01 14:21:25 +00:00
|
|
|
};
|
2014-01-02 04:56:24 +00:00
|
|
|
|
Greatly reduce kernel closure size
Based on access analysis with strace, I determined an essentially
minimal required set of files from the kernel source that was needed to
build all current kernel packages on 3.10, which ultimately resulted in
keeping 30M of source. Generalizing from that minimal set, which
required ad-hoc specifications of which headers outside of include/ and
arch/*/include and which files in the scripts/ directory should be kept,
to a policy of keeping all non-arch-specific headers that aren't part of
the drivers/ directory and the entire scripts/ directory added an
additional 17M, but there was nothing in the analysis that indicated
that that ad-hoc specification was at all complete so I think the extra
hit is worth the likely greater compatibility.
For reference, we now keep:
* All headers that are NOT in arch/${notTargetArch}/include or drivers/
* The scripts/ directory
* Makefile
* arch/${targetArch}/Makefile
IMO the most likely cause of future problems are the headers in
drivers/, but hopefully they won't actually be needed as they add 50M
Ideally kernel packages would only use include and
arch/${targetArch}/include, but alas this is observably not the case.
master:
* $out
* size: 234M
* references-closure: linux-headers, glibc, attr, acl, zlib, gcc,
coreutils, perl, bash
merge-kernel-builds:
* $out
* size: 152M
* references-closure: none
* $dev
* size: 57M
* references-closure: linux-headers, glibc, zlib, gcc
So even with the non-minimal set we still beat out master. Keeping the
drivers headers would make us only slightly bigger.
Signed-off-by: Shea Levy <shea@shealevy.com>
2014-01-05 11:55:47 +00:00
|
|
|
prePatch = kernel.prePatch + ''
|
|
|
|
# Patch kconfig to print "###" after every question so that
|
|
|
|
# generate-config.pl from the generic builder can answer them.
|
|
|
|
sed -e '/fflush(stdout);/i\printf("###");' -i scripts/kconfig/conf.c
|
|
|
|
'';
|
|
|
|
|
|
|
|
inherit (kernel) src patches preUnpack;
|
2014-01-02 04:56:24 +00:00
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
cd $buildRoot
|
|
|
|
|
2014-01-01 14:21:25 +00:00
|
|
|
# Get a basic config file for later refinement with $generateConfig.
|
2014-01-02 04:56:24 +00:00
|
|
|
make -C ../$sourceRoot O=$PWD $kernelBaseConfig ARCH=$arch
|
2014-01-01 14:21:25 +00:00
|
|
|
|
|
|
|
# Create the config file.
|
|
|
|
echo "generating kernel configuration..."
|
|
|
|
echo "$kernelConfig" > kernel-config
|
|
|
|
DEBUG=1 ARCH=$arch KERNEL_CONFIG=kernel-config AUTO_MODULES=$autoModules \
|
2017-03-23 00:03:37 +00:00
|
|
|
PREFER_BUILTIN=$preferBuiltin SRC=../$sourceRoot perl -w $generateConfig
|
2014-01-01 14:21:25 +00:00
|
|
|
'';
|
2014-01-02 04:56:24 +00:00
|
|
|
|
|
|
|
installPhase = "mv .config $out";
|
2014-06-30 07:52:33 +01:00
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
2014-01-01 14:21:25 +00:00
|
|
|
};
|
|
|
|
|
2014-01-22 01:05:55 +00:00
|
|
|
kernel = buildLinux {
|
2017-12-04 08:33:39 +00:00
|
|
|
inherit version modDirVersion src kernelPatches stdenv extraMeta;
|
2014-01-01 14:21:25 +00:00
|
|
|
|
|
|
|
configfile = configfile.nativeDrv or configfile;
|
|
|
|
|
|
|
|
crossConfigfile = configfile.crossDrv or configfile;
|
|
|
|
|
|
|
|
config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; };
|
|
|
|
|
|
|
|
crossConfig = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; };
|
|
|
|
};
|
|
|
|
|
2008-05-22 20:29:23 +01:00
|
|
|
passthru = {
|
2017-09-15 22:07:14 +01:00
|
|
|
features = kernelFeatures;
|
2017-12-04 08:33:39 +00:00
|
|
|
passthru = kernel.passthru // (removeAttrs passthru [ "passthru" ]);
|
2008-05-22 20:29:23 +01:00
|
|
|
};
|
2011-07-11 15:07:21 +01:00
|
|
|
|
2014-01-01 14:21:25 +00:00
|
|
|
nativeDrv = lib.addPassthru kernel.nativeDrv passthru;
|
2011-07-24 21:24:12 +01:00
|
|
|
|
2014-01-01 14:21:25 +00:00
|
|
|
crossDrv = lib.addPassthru kernel.crossDrv passthru;
|
2017-09-15 22:07:14 +01:00
|
|
|
|
|
|
|
in if kernel ? crossDrv
|
|
|
|
then nativeDrv // { inherit nativeDrv crossDrv; }
|
|
|
|
else lib.addPassthru kernel passthru
|