12 , # The kernel source tarball.
15 , # The kernel version.
18 , # Allows overriding the default defconfig
21 , # Legacy overrides to the intermediate kernel config, as string
24 , # kernel intermediate config overrides, as a set
25 structuredExtraConfig ? {}
27 , # The version number used for the module directory
28 modDirVersion ? version
30 , # An attribute set whose attributes express the availability of
31 # certain features in this kernel. E.g. `{iwlwifi = true;}'
32 # indicates a kernel that provides Intel wireless support. Used in
33 # NixOS to implement kernel-specific behaviour.
36 , # Custom seed used for CONFIG_GCC_PLUGIN_RANDSTRUCT if enabled. This is
37 # automatically extended with extra per-version and per-config values.
40 , # A list of patches to apply to the kernel. Each element of this list
41 # should be an attribute set {name, patch} where `name' is a
42 # symbolic name and `patch' is the actual patch. The patch may
43 # optionally be compressed with gzip or bzip2.
45 , ignoreConfigErrors ? stdenv.hostPlatform.linux-kernel.name != "pc" ||
46 stdenv.hostPlatform != stdenv.buildPlatform
53 # easy overrides to stdenv.hostPlatform.linux-kernel members
54 , autoModules ? stdenv.hostPlatform.linux-kernel.autoModules
55 , preferBuiltin ? stdenv.hostPlatform.linux-kernel.preferBuiltin or false
56 , kernelArch ? stdenv.hostPlatform.linuxArch
61 # Note: this package is used for bootstrapping fetchurl, and thus
62 # cannot use fetchpatch! All mutable patches (generated by GitHub or
63 # cgit) that are needed here should be included directly in Nixpkgs as
66 assert stdenv.isLinux;
69 # Combine the `features' attribute sets of all the kernel patches.
70 kernelFeatures = lib.fold (x: y: (x.features or {}) // y) ({
73 needsCifsUtils = true;
74 netfilterRPFilter = true;
76 } // features) kernelPatches;
78 commonStructuredConfig = import ./common-config.nix {
79 inherit lib stdenv version;
81 features = kernelFeatures; # Ensure we know of all extra patches, etc.
84 intermediateNixConfig = configfile.moduleStructuredConfig.intermediateNixConfig
85 # extra config in legacy string format
87 + stdenv.hostPlatform.linux-kernel.extraConfig or "";
89 structuredConfigFromPatches =
90 map ({extraStructuredConfig ? {}, ...}: {settings=extraStructuredConfig;}) kernelPatches;
92 # appends kernel patches extraConfig
93 kernelConfigFun = baseConfigStr:
96 map ({extraConfig ? "", ...}: extraConfig) kernelPatches;
97 in lib.concatStringsSep "\n" ([baseConfigStr] ++ configFromPatches);
99 configfile = stdenv.mkDerivation {
100 inherit ignoreConfigErrors autoModules preferBuiltin kernelArch;
101 pname = "linux-config";
104 generateConfig = ./generate-config.pl;
106 kernelConfig = kernelConfigFun intermediateNixConfig;
107 passAsFile = [ "kernelConfig" ];
109 depsBuildBuild = [ buildPackages.stdenv.cc ];
110 nativeBuildInputs = [ perl gmp libmpc mpfr ]
111 ++ lib.optionals (lib.versionAtLeast version "4.16") [ bison flex ];
113 platformName = stdenv.hostPlatform.linux-kernel.name;
115 kernelBaseConfig = if defconfig != null then defconfig else stdenv.hostPlatform.linux-kernel.baseConfig;
117 kernelTarget = stdenv.hostPlatform.linux-kernel.target;
119 prePatch = kernel.prePatch + ''
120 # Patch kconfig to print "###" after every question so that
121 # generate-config.pl from the generic builder can answer them.
122 sed -e '/fflush(stdout);/i\printf("###");' -i scripts/kconfig/conf.c
125 preUnpack = kernel.preUnpack or "";
127 inherit (kernel) src patches;
130 export buildRoot="''${buildRoot:-build}"
132 # Get a basic config file for later refinement with $generateConfig.
133 make -C . O="$buildRoot" $kernelBaseConfig \
135 HOSTCC=${buildPackages.stdenv.cc.targetPrefix}gcc \
136 HOSTCXX=${buildPackages.stdenv.cc.targetPrefix}g++
138 # Create the config file.
139 echo "generating kernel configuration..."
140 ln -s "$kernelConfigPath" "$buildRoot/kernel-config"
141 DEBUG=1 ARCH=$kernelArch KERNEL_CONFIG="$buildRoot/kernel-config" AUTO_MODULES=$autoModules \
142 PREFER_BUILTIN=$preferBuiltin BUILD_ROOT="$buildRoot" SRC=. perl -w $generateConfig
145 installPhase = "mv $buildRoot/.config $out";
147 enableParallelBuilding = true;
151 module = import ../../../../nixos/modules/system/boot/kernel_config.nix;
152 # used also in apache
153 # { modules = [ { options = res.options; config = svc.config or svc; } ];
155 # The result is a set of two attributes
156 moduleStructuredConfig = (lib.evalModules {
159 { settings = commonStructuredConfig; _file = "pkgs/os-specific/linux/kernel/common-config.nix"; }
160 { settings = structuredExtraConfig; _file = "structuredExtraConfig"; }
162 ++ structuredConfigFromPatches
166 structuredConfig = moduleStructuredConfig.settings;
168 }; # end of configfile derivation
170 kernel = (callPackage ./manual-config.nix {}) {
171 inherit version modDirVersion src kernelPatches randstructSeed lib stdenv extraMeta configfile;
173 config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; };
177 features = kernelFeatures;
178 inherit commonStructuredConfig isZen isHardened isLibre modDirVersion;
179 isXen = lib.warn "The isXen attribute is deprecated. All Nixpkgs kernels that support it now have Xen enabled." true;
180 kernelOlder = lib.versionOlder version;
181 kernelAtLeast = lib.versionAtLeast version;
182 passthru = kernel.passthru // (removeAttrs passthru [ "passthru" ]);
186 in lib.extendDerivation true passthru kernel