2018-03-08 04:45:39 +01:00
|
|
|
{ buildPackages
|
2018-01-28 19:50:18 +01:00
|
|
|
, callPackage
|
2018-03-08 04:45:39 +01:00
|
|
|
, perl
|
|
|
|
, bison ? null
|
|
|
|
, flex ? null
|
2019-01-04 02:07:17 +01:00
|
|
|
, gmp ? null
|
|
|
|
, libmpc ? null
|
|
|
|
, mpfr ? null
|
2021-01-15 15:45:37 +01:00
|
|
|
, lib
|
2018-03-08 04:45:39 +01:00
|
|
|
, stdenv
|
2008-03-24 20:39:42 +01:00
|
|
|
|
2009-01-15 16:40:23 +01:00
|
|
|
, # The kernel source tarball.
|
|
|
|
src
|
2008-03-24 20:39:42 +01:00
|
|
|
|
2009-01-15 16:40:23 +01:00
|
|
|
, # The kernel version.
|
|
|
|
version
|
|
|
|
|
2017-11-03 14:49:51 +01:00
|
|
|
, # Allows overriding the default defconfig
|
|
|
|
defconfig ? null
|
|
|
|
|
2016-01-05 15:22:43 +01:00
|
|
|
, # Legacy overrides to the intermediate kernel config, as string
|
2013-07-31 23:56:48 +02:00
|
|
|
extraConfig ? ""
|
|
|
|
|
2021-07-12 06:58:16 +02:00
|
|
|
# Additional make flags passed to kbuild
|
|
|
|
, extraMakeFlags ? []
|
|
|
|
|
2016-01-05 15:22:43 +01:00
|
|
|
, # kernel intermediate config overrides, as a set
|
|
|
|
structuredExtraConfig ? {}
|
|
|
|
|
2011-08-08 22:49:49 +02:00
|
|
|
, # The version number used for the module directory
|
|
|
|
modDirVersion ? version
|
|
|
|
|
2009-01-15 16:40:23 +01: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 ? {}
|
|
|
|
|
2019-01-12 01:34:33 +01:00
|
|
|
, # Custom seed used for CONFIG_GCC_PLUGIN_RANDSTRUCT if enabled. This is
|
|
|
|
# automatically extended with extra per-version and per-config values.
|
|
|
|
randstructSeed ? ""
|
|
|
|
|
2009-01-15 16:40:23 +01:00
|
|
|
, # A list of patches to apply to the kernel. Each element of this list
|
2008-03-24 20:39:42 +01: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 16:40:23 +01:00
|
|
|
kernelPatches ? []
|
2021-01-23 02:33:55 +01:00
|
|
|
, ignoreConfigErrors ? stdenv.hostPlatform.linux-kernel.name != "pc" ||
|
2018-08-20 20:43:41 +02:00
|
|
|
stdenv.hostPlatform != stdenv.buildPlatform
|
2009-09-11 15:16:18 +02:00
|
|
|
, extraMeta ? {}
|
2018-03-08 04:47:06 +01:00
|
|
|
|
2020-10-29 09:15:05 +01:00
|
|
|
, isZen ? false
|
|
|
|
, isLibre ? false
|
|
|
|
, isHardened ? false
|
|
|
|
|
2021-01-23 02:33:55 +01:00
|
|
|
# easy overrides to stdenv.hostPlatform.linux-kernel members
|
|
|
|
, autoModules ? stdenv.hostPlatform.linux-kernel.autoModules
|
|
|
|
, preferBuiltin ? stdenv.hostPlatform.linux-kernel.preferBuiltin or false
|
|
|
|
, kernelArch ? stdenv.hostPlatform.linuxArch
|
2021-04-07 17:57:58 +02:00
|
|
|
, kernelTests ? []
|
2009-07-15 23:09:17 +02:00
|
|
|
, ...
|
2018-07-20 21:54:05 +02:00
|
|
|
}:
|
2008-03-24 20:39:42 +01:00
|
|
|
|
2020-06-26 22:44:45 +02:00
|
|
|
# Note: this package is used for bootstrapping fetchurl, and thus
|
|
|
|
# cannot use fetchpatch! All mutable patches (generated by GitHub or
|
|
|
|
# cgit) that are needed here should be included directly in Nixpkgs as
|
|
|
|
# files.
|
|
|
|
|
2014-08-22 11:57:40 +02:00
|
|
|
assert stdenv.isLinux;
|
2009-11-08 18:19:46 +01:00
|
|
|
|
2008-03-24 20:39:42 +01:00
|
|
|
let
|
2017-09-15 23:07:14 +02:00
|
|
|
# Combine the `features' attribute sets of all the kernel patches.
|
2021-01-25 07:57:48 +01:00
|
|
|
kernelFeatures = lib.foldr (x: y: (x.features or {}) // y) ({
|
2017-09-15 23:07:14 +02:00
|
|
|
iwlwifi = true;
|
|
|
|
efiBootStub = true;
|
|
|
|
needsCifsUtils = true;
|
|
|
|
netfilterRPFilter = true;
|
2019-01-06 19:26:08 +01:00
|
|
|
ia32Emulation = true;
|
2017-09-15 23:07:14 +02:00
|
|
|
} // features) kernelPatches;
|
|
|
|
|
2018-10-03 11:49:50 +02:00
|
|
|
commonStructuredConfig = import ./common-config.nix {
|
2021-01-15 15:45:37 +01:00
|
|
|
inherit lib stdenv version;
|
2018-01-28 19:50:18 +01:00
|
|
|
|
2017-09-15 23:07:14 +02:00
|
|
|
features = kernelFeatures; # Ensure we know of all extra patches, etc.
|
|
|
|
};
|
|
|
|
|
2019-01-31 05:34:42 +01:00
|
|
|
intermediateNixConfig = configfile.moduleStructuredConfig.intermediateNixConfig
|
|
|
|
# extra config in legacy string format
|
|
|
|
+ extraConfig
|
2021-01-23 02:33:55 +01:00
|
|
|
+ stdenv.hostPlatform.linux-kernel.extraConfig or "";
|
2018-10-03 11:49:50 +02:00
|
|
|
|
|
|
|
structuredConfigFromPatches =
|
|
|
|
map ({extraStructuredConfig ? {}, ...}: {settings=extraStructuredConfig;}) kernelPatches;
|
|
|
|
|
|
|
|
# appends kernel patches extraConfig
|
|
|
|
kernelConfigFun = baseConfigStr:
|
2010-02-27 22:48:48 +01:00
|
|
|
let
|
|
|
|
configFromPatches =
|
|
|
|
map ({extraConfig ? "", ...}: extraConfig) kernelPatches;
|
2018-10-03 11:49:50 +02:00
|
|
|
in lib.concatStringsSep "\n" ([baseConfigStr] ++ configFromPatches);
|
2010-02-27 22:48:48 +01:00
|
|
|
|
2014-01-01 15:21:25 +01:00
|
|
|
configfile = stdenv.mkDerivation {
|
2021-07-12 06:58:16 +02:00
|
|
|
inherit ignoreConfigErrors autoModules preferBuiltin kernelArch extraMakeFlags;
|
2019-08-13 23:52:01 +02:00
|
|
|
pname = "linux-config";
|
|
|
|
inherit version;
|
2014-01-01 15:21:25 +01:00
|
|
|
|
|
|
|
generateConfig = ./generate-config.pl;
|
|
|
|
|
2016-01-05 15:22:43 +01:00
|
|
|
kernelConfig = kernelConfigFun intermediateNixConfig;
|
2018-04-09 01:38:08 +02:00
|
|
|
passAsFile = [ "kernelConfig" ];
|
2014-01-01 15:21:25 +01:00
|
|
|
|
2018-01-16 04:28:45 +01:00
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
2019-01-04 02:07:17 +01:00
|
|
|
nativeBuildInputs = [ perl gmp libmpc mpfr ]
|
2021-01-15 15:45:37 +01:00
|
|
|
++ lib.optionals (lib.versionAtLeast version "4.16") [ bison flex ];
|
2014-01-01 15:21:25 +01:00
|
|
|
|
2021-01-23 02:33:55 +01:00
|
|
|
platformName = stdenv.hostPlatform.linux-kernel.name;
|
2018-01-28 19:50:18 +01:00
|
|
|
# e.g. "defconfig"
|
2021-01-23 02:33:55 +01:00
|
|
|
kernelBaseConfig = if defconfig != null then defconfig else stdenv.hostPlatform.linux-kernel.baseConfig;
|
2018-01-28 19:50:18 +01:00
|
|
|
# e.g. "bzImage"
|
2021-01-23 02:33:55 +01:00
|
|
|
kernelTarget = stdenv.hostPlatform.linux-kernel.target;
|
2017-10-28 21:09:54 +02:00
|
|
|
|
2021-07-12 06:58:16 +02:00
|
|
|
makeFlags = lib.optionals (stdenv.hostPlatform.linux-kernel ? makeFlags) stdenv.hostPlatform.linux-kernel.makeFlags
|
|
|
|
++ extraMakeFlags;
|
2021-07-12 06:55:40 +02: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 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
|
|
|
|
'';
|
|
|
|
|
2018-07-24 21:37:22 +02:00
|
|
|
preUnpack = kernel.preUnpack or "";
|
|
|
|
|
|
|
|
inherit (kernel) src patches;
|
2014-01-02 05:56:24 +01:00
|
|
|
|
|
|
|
buildPhase = ''
|
2018-01-28 19:50:18 +01:00
|
|
|
export buildRoot="''${buildRoot:-build}"
|
2021-02-15 20:15:48 +01:00
|
|
|
export HOSTCC=$CC_FOR_BUILD
|
|
|
|
export HOSTCXX=$CXX_FOR_BUILD
|
|
|
|
export HOSTAR=$AR_FOR_BUILD
|
|
|
|
export HOSTLD=$LD_FOR_BUILD
|
2014-01-02 05:56:24 +01:00
|
|
|
|
2014-01-01 15:21:25 +01:00
|
|
|
# Get a basic config file for later refinement with $generateConfig.
|
2021-07-12 06:58:16 +02:00
|
|
|
make $makeFlags \
|
|
|
|
-C . O="$buildRoot" $kernelBaseConfig \
|
2019-01-04 02:07:17 +01:00
|
|
|
ARCH=$kernelArch \
|
2021-02-15 20:15:48 +01:00
|
|
|
HOSTCC=$HOSTCC HOSTCXX=$HOSTCXX HOSTAR=$HOSTAR HOSTLD=$HOSTLD \
|
2021-07-12 06:55:40 +02:00
|
|
|
CC=$CC OBJCOPY=$OBJCOPY OBJDUMP=$OBJDUMP READELF=$READELF \
|
|
|
|
$makeFlags
|
2014-01-01 15:21:25 +01:00
|
|
|
|
|
|
|
# Create the config file.
|
|
|
|
echo "generating kernel configuration..."
|
2018-04-09 01:38:08 +02:00
|
|
|
ln -s "$kernelConfigPath" "$buildRoot/kernel-config"
|
2018-03-08 04:47:06 +01:00
|
|
|
DEBUG=1 ARCH=$kernelArch KERNEL_CONFIG="$buildRoot/kernel-config" AUTO_MODULES=$autoModules \
|
2021-07-12 06:55:40 +02:00
|
|
|
PREFER_BUILTIN=$preferBuiltin BUILD_ROOT="$buildRoot" SRC=. MAKE_FLAGS="$makeFlags" \
|
|
|
|
perl -w $generateConfig
|
2014-01-01 15:21:25 +01:00
|
|
|
'';
|
2014-01-02 05:56:24 +01:00
|
|
|
|
2018-01-28 19:50:18 +01:00
|
|
|
installPhase = "mv $buildRoot/.config $out";
|
2014-06-30 08:52:33 +02:00
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
2018-10-03 11:49:50 +02:00
|
|
|
|
|
|
|
passthru = rec {
|
|
|
|
module = import ../../../../nixos/modules/system/boot/kernel_config.nix;
|
|
|
|
# used also in apache
|
|
|
|
# { modules = [ { options = res.options; config = svc.config or svc; } ];
|
|
|
|
# check = false;
|
|
|
|
# The result is a set of two attributes
|
|
|
|
moduleStructuredConfig = (lib.evalModules {
|
|
|
|
modules = [
|
|
|
|
module
|
2019-08-21 15:14:31 +02:00
|
|
|
{ settings = commonStructuredConfig; _file = "pkgs/os-specific/linux/kernel/common-config.nix"; }
|
|
|
|
{ settings = structuredExtraConfig; _file = "structuredExtraConfig"; }
|
2018-10-03 11:49:50 +02:00
|
|
|
]
|
|
|
|
++ structuredConfigFromPatches
|
|
|
|
;
|
|
|
|
}).config;
|
|
|
|
|
|
|
|
structuredConfig = moduleStructuredConfig.settings;
|
|
|
|
};
|
|
|
|
}; # end of configfile derivation
|
2014-01-01 15:21:25 +01:00
|
|
|
|
2021-07-18 03:57:35 +02:00
|
|
|
kernel = (callPackage ./manual-config.nix { inherit buildPackages; }) {
|
2021-07-12 06:58:16 +02:00
|
|
|
inherit version modDirVersion src kernelPatches randstructSeed lib stdenv extraMakeFlags extraMeta configfile;
|
2014-01-01 15:21:25 +01:00
|
|
|
|
|
|
|
config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; };
|
|
|
|
};
|
|
|
|
|
2008-05-22 21:29:23 +02:00
|
|
|
passthru = {
|
2017-09-15 23:07:14 +02:00
|
|
|
features = kernelFeatures;
|
2021-07-13 11:18:32 +02:00
|
|
|
inherit commonStructuredConfig structuredExtraConfig extraMakeFlags isZen isHardened isLibre modDirVersion;
|
2021-04-04 16:55:56 +02:00
|
|
|
isXen = lib.warn "The isXen attribute is deprecated. All Nixpkgs kernels that support it now have Xen enabled." true;
|
2020-10-29 09:15:05 +01:00
|
|
|
kernelOlder = lib.versionOlder version;
|
|
|
|
kernelAtLeast = lib.versionAtLeast version;
|
2017-12-04 09:33:39 +01:00
|
|
|
passthru = kernel.passthru // (removeAttrs passthru [ "passthru" ]);
|
2021-04-07 17:57:58 +02:00
|
|
|
tests = kernelTests;
|
2008-05-22 21:29:23 +02:00
|
|
|
};
|
2011-07-11 16:07:21 +02:00
|
|
|
|
2017-10-28 21:09:54 +02:00
|
|
|
in lib.extendDerivation true passthru kernel
|