mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-14 01:33:10 +00:00
2c38df1c5b
This makes the disk usage footprint of building the kernel smaller in 3 ways: 1) There is no separate kernel source derivation 2) Rather than using the entire build tree, only the output of make modules_prepare is kept in the $dev output (plus the module symbol versioning file generated during the build) 3) Only the subset of the source tree known to be needed for external builds is kept in $dev Note that while 2) is supported by official kernel documentation, I couldn't find any source describing what we need to keep for 3). I've started with the bare minimum (the main Makefile is called by the Makefile generated by make modules_prepare) and we can/should add more as needed for kernelPackages. Signed-off-by: Shea Levy <shea@shealevy.com>
123 lines
3.6 KiB
Nix
123 lines
3.6 KiB
Nix
{ stdenv, perl, linuxManualConfig
|
|
|
|
, # 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 ? []
|
|
, extraMeta ? {}
|
|
, ...
|
|
}:
|
|
|
|
assert stdenv.platform.name == "sheevaplug" -> stdenv.platform.uboot != null;
|
|
|
|
let
|
|
|
|
lib = stdenv.lib;
|
|
|
|
kernelConfigFun = baseConfig:
|
|
let
|
|
configFromPatches =
|
|
map ({extraConfig ? "", ...}: extraConfig) kernelPatches;
|
|
in lib.concatStringsSep "\n" ([baseConfig] ++ configFromPatches);
|
|
|
|
configfile = stdenv.mkDerivation {
|
|
name = "linux-config-${version}";
|
|
|
|
generateConfig = ./generate-config.pl;
|
|
|
|
kernelConfig = kernelConfigFun config;
|
|
|
|
ignoreConfigErrors = stdenv.platform.name != "pc";
|
|
|
|
nativeBuildInputs = [ perl ];
|
|
|
|
platformName = stdenv.platform.name;
|
|
kernelBaseConfig = stdenv.platform.kernelBaseConfig;
|
|
kernelTarget = stdenv.platform.kernelTarget;
|
|
autoModules = stdenv.platform.kernelAutoModules;
|
|
arch = stdenv.platform.kernelArch;
|
|
|
|
crossAttrs = let
|
|
cp = stdenv.cross.platform;
|
|
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;
|
|
|
|
inherit (kernel.crossDrv) src patches prePatch preUnpack;
|
|
};
|
|
|
|
inherit (kernel) src patches prePatch preUnpack;
|
|
|
|
buildPhase = ''
|
|
cd $buildRoot
|
|
|
|
# Get a basic config file for later refinement with $generateConfig.
|
|
make -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 \
|
|
SRC=../$sourceRoot perl -w $generateConfig
|
|
'';
|
|
|
|
installPhase = "mv .config $out";
|
|
};
|
|
|
|
kernel = linuxManualConfig {
|
|
inherit version modDirVersion src kernelPatches;
|
|
|
|
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"; };
|
|
};
|
|
|
|
configWithPlatform = kernelPlatform:
|
|
import ./common-config.nix { inherit stdenv version kernelPlatform extraConfig; };
|
|
|
|
config = configWithPlatform stdenv.platform;
|
|
configCross = configWithPlatform stdenv.cross.platform;
|
|
|
|
passthru = {
|
|
# Combine the `features' attribute sets of all the kernel patches.
|
|
features = lib.fold (x: y: (x.features or {}) // y) features kernelPatches;
|
|
|
|
meta = kernel.meta // extraMeta;
|
|
};
|
|
|
|
nativeDrv = lib.addPassthru kernel.nativeDrv passthru;
|
|
|
|
crossDrv = lib.addPassthru kernel.crossDrv passthru;
|
|
in if kernel ? crossDrv then nativeDrv // { inherit nativeDrv crossDrv; } else lib.addPassthru kernel passthru
|