Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 20.09 182 lines 6.1 kB view raw
1{ buildPackages 2, callPackage 3, perl 4, bison ? null 5, flex ? null 6, gmp ? null 7, libmpc ? null 8, mpfr ? null 9, stdenv 10 11, # The kernel source tarball. 12 src 13 14, # The kernel version. 15 version 16 17, # Allows overriding the default defconfig 18 defconfig ? null 19 20, # Legacy overrides to the intermediate kernel config, as string 21 extraConfig ? "" 22 23, # kernel intermediate config overrides, as a set 24 structuredExtraConfig ? {} 25 26, # The version number used for the module directory 27 modDirVersion ? version 28 29, # An attribute set whose attributes express the availability of 30 # certain features in this kernel. E.g. `{iwlwifi = true;}' 31 # indicates a kernel that provides Intel wireless support. Used in 32 # NixOS to implement kernel-specific behaviour. 33 features ? {} 34 35, # Custom seed used for CONFIG_GCC_PLUGIN_RANDSTRUCT if enabled. This is 36 # automatically extended with extra per-version and per-config values. 37 randstructSeed ? "" 38 39, # A list of patches to apply to the kernel. Each element of this list 40 # should be an attribute set {name, patch} where `name' is a 41 # symbolic name and `patch' is the actual patch. The patch may 42 # optionally be compressed with gzip or bzip2. 43 kernelPatches ? [] 44, ignoreConfigErrors ? stdenv.hostPlatform.platform.name != "pc" || 45 stdenv.hostPlatform != stdenv.buildPlatform 46, extraMeta ? {} 47 48# easy overrides to stdenv.hostPlatform.platform members 49, autoModules ? stdenv.hostPlatform.platform.kernelAutoModules 50, preferBuiltin ? stdenv.hostPlatform.platform.kernelPreferBuiltin or false 51, kernelArch ? stdenv.hostPlatform.platform.kernelArch 52 53, ... 54}: 55 56# Note: this package is used for bootstrapping fetchurl, and thus 57# cannot use fetchpatch! All mutable patches (generated by GitHub or 58# cgit) that are needed here should be included directly in Nixpkgs as 59# files. 60 61assert stdenv.isLinux; 62 63let 64 65 lib = stdenv.lib; 66 67 # Combine the `features' attribute sets of all the kernel patches. 68 kernelFeatures = lib.fold (x: y: (x.features or {}) // y) ({ 69 iwlwifi = true; 70 efiBootStub = true; 71 needsCifsUtils = true; 72 netfilterRPFilter = true; 73 grsecurity = false; 74 xen_dom0 = false; 75 ia32Emulation = true; 76 } // features) kernelPatches; 77 78 commonStructuredConfig = import ./common-config.nix { 79 inherit stdenv version ; 80 81 features = kernelFeatures; # Ensure we know of all extra patches, etc. 82 }; 83 84 intermediateNixConfig = configfile.moduleStructuredConfig.intermediateNixConfig 85 # extra config in legacy string format 86 + extraConfig 87 + lib.optionalString (stdenv.hostPlatform.platform ? kernelExtraConfig) stdenv.hostPlatform.platform.kernelExtraConfig; 88 89 structuredConfigFromPatches = 90 map ({extraStructuredConfig ? {}, ...}: {settings=extraStructuredConfig;}) kernelPatches; 91 92 # appends kernel patches extraConfig 93 kernelConfigFun = baseConfigStr: 94 let 95 configFromPatches = 96 map ({extraConfig ? "", ...}: extraConfig) kernelPatches; 97 in lib.concatStringsSep "\n" ([baseConfigStr] ++ configFromPatches); 98 99 configfile = stdenv.mkDerivation { 100 inherit ignoreConfigErrors autoModules preferBuiltin kernelArch; 101 pname = "linux-config"; 102 inherit version; 103 104 generateConfig = ./generate-config.pl; 105 106 kernelConfig = kernelConfigFun intermediateNixConfig; 107 passAsFile = [ "kernelConfig" ]; 108 109 depsBuildBuild = [ buildPackages.stdenv.cc ]; 110 nativeBuildInputs = [ perl gmp libmpc mpfr ] 111 ++ lib.optionals (stdenv.lib.versionAtLeast version "4.16") [ bison flex ]; 112 113 platformName = stdenv.hostPlatform.platform.name; 114 # e.g. "defconfig" 115 kernelBaseConfig = if defconfig != null then defconfig else stdenv.hostPlatform.platform.kernelBaseConfig; 116 # e.g. "bzImage" 117 kernelTarget = stdenv.hostPlatform.platform.kernelTarget; 118 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 123 ''; 124 125 preUnpack = kernel.preUnpack or ""; 126 127 inherit (kernel) src patches; 128 129 buildPhase = '' 130 export buildRoot="''${buildRoot:-build}" 131 132 # Get a basic config file for later refinement with $generateConfig. 133 make -C . O="$buildRoot" $kernelBaseConfig \ 134 ARCH=$kernelArch \ 135 HOSTCC=${buildPackages.stdenv.cc.targetPrefix}gcc \ 136 HOSTCXX=${buildPackages.stdenv.cc.targetPrefix}g++ 137 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 143 ''; 144 145 installPhase = "mv $buildRoot/.config $out"; 146 147 enableParallelBuilding = true; 148 149 passthru = rec { 150 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; } ]; 154 # check = false; 155 # The result is a set of two attributes 156 moduleStructuredConfig = (lib.evalModules { 157 modules = [ 158 module 159 { settings = commonStructuredConfig; _file = "pkgs/os-specific/linux/kernel/common-config.nix"; } 160 { settings = structuredExtraConfig; _file = "structuredExtraConfig"; } 161 ] 162 ++ structuredConfigFromPatches 163 ; 164 }).config; 165 166 structuredConfig = moduleStructuredConfig.settings; 167 }; 168 }; # end of configfile derivation 169 170 kernel = (callPackage ./manual-config.nix {}) { 171 inherit version modDirVersion src kernelPatches randstructSeed stdenv extraMeta configfile; 172 173 config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; }; 174 }; 175 176 passthru = { 177 features = kernelFeatures; 178 inherit commonStructuredConfig; 179 passthru = kernel.passthru // (removeAttrs passthru [ "passthru" ]); 180 }; 181 182in lib.extendDerivation true passthru kernel