nixpkgs/pkgs/os-specific/linux/kernel/generic.nix

114 lines
3.4 KiB
Nix
Raw Normal View History

2017-10-28 21:09:54 +02:00
{ stdenv, buildPackages, perl, buildLinux
, # The kernel source tarball.
src
, # The kernel version.
version
, # Overrides to the kernel config.
extraConfig ? ""
, # The version number used for the module directory
modDirVersion ? version
, # 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
# 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.
kernelPatches ? []
, ignoreConfigErrors ? hostPlatform.platform.name != "pc" ||
hostPlatform != stdenv.buildPlatform
, extraMeta ? {}
2017-06-28 22:32:25 +02:00
, hostPlatform
, ...
}:
assert stdenv.isLinux;
let
lib = stdenv.lib;
# 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;
config = import ./common-config.nix {
inherit stdenv version extraConfig;
kernelPlatform = hostPlatform;
features = kernelFeatures; # Ensure we know of all extra patches, etc.
};
kernelConfigFun = baseConfig:
let
configFromPatches =
map ({extraConfig ? "", ...}: extraConfig) kernelPatches;
in lib.concatStringsSep "\n" ([baseConfig] ++ configFromPatches);
configfile = stdenv.mkDerivation {
inherit ignoreConfigErrors;
name = "linux-config-${version}";
generateConfig = ./generate-config.pl;
kernelConfig = kernelConfigFun config;
2017-10-28 21:09:54 +02:00
nativeBuildInputs = [ buildPackages.stdenv.cc perl ];
2017-10-28 21:09:54 +02:00
platformName = hostPlatform.platform.name;
kernelBaseConfig = hostPlatform.platform.kernelBaseConfig;
kernelTarget = hostPlatform.platform.kernelTarget;
autoModules = hostPlatform.platform.kernelAutoModules;
preferBuiltin = hostPlatform.platform.kernelPreferBuiltin or false;
arch = hostPlatform.platform.kernelArch;
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 12:55:47 +01: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;
buildPhase = ''
cd $buildRoot
# Get a basic config file for later refinement with $generateConfig.
2017-10-28 21:09:54 +02:00
make HOSTCC=${buildPackages.stdenv.cc.targetPrefix}gcc -C ../$sourceRoot O=$PWD $kernelBaseConfig ARCH=$arch
# Create the config file.
echo "generating kernel configuration..."
echo "$kernelConfig" > kernel-config
DEBUG=1 ARCH=$arch KERNEL_CONFIG=kernel-config AUTO_MODULES=$autoModules \
PREFER_BUILTIN=$preferBuiltin SRC=../$sourceRoot perl -w $generateConfig
'';
installPhase = "mv .config $out";
enableParallelBuilding = true;
};
kernel = buildLinux {
inherit version modDirVersion src kernelPatches stdenv extraMeta configfile;
config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; };
};
passthru = {
features = kernelFeatures;
passthru = kernel.passthru // (removeAttrs passthru [ "passthru" ]);
};
2017-10-28 21:09:54 +02:00
in lib.extendDerivation true passthru kernel