diff options
Diffstat (limited to 'pkgs/os-specific/linux/kernel/generic.nix')
-rw-r--r-- | pkgs/os-specific/linux/kernel/generic.nix | 93 |
1 files changed, 39 insertions, 54 deletions
diff --git a/pkgs/os-specific/linux/kernel/generic.nix b/pkgs/os-specific/linux/kernel/generic.nix index 0d2b7655edb..1b8c3f76155 100644 --- a/pkgs/os-specific/linux/kernel/generic.nix +++ b/pkgs/os-specific/linux/kernel/generic.nix @@ -1,4 +1,10 @@ -{ stdenv, perl, buildLinux +{ buildPackages +, ncurses +, callPackage +, perl +, bison ? null +, flex ? null +, stdenv , # The kernel source tarball. src @@ -23,11 +29,18 @@ # symbolic name and `patch' is the actual patch. The patch may # optionally be compressed with gzip or bzip2. kernelPatches ? [] -, ignoreConfigErrors ? stdenv.platform.name != "pc" +, ignoreConfigErrors ? hostPlatform.platform.name != "pc" || + hostPlatform != stdenv.buildPlatform , extraMeta ? {} , hostPlatform + +# easy overrides to hostPlatform.platform members +, autoModules ? hostPlatform.platform.kernelAutoModules +, preferBuiltin ? hostPlatform.platform.kernelPreferBuiltin or false +, kernelArch ? hostPlatform.platform.kernelArch + , ... -}: +} @ args: assert stdenv.isLinux; @@ -43,14 +56,14 @@ let netfilterRPFilter = true; } // features) kernelPatches; - configWithPlatform = kernelPlatform: import ./common-config.nix { - inherit stdenv version kernelPlatform extraConfig; + config = import ./common-config.nix { + inherit stdenv version ; + # append extraConfig for backwards compatibility but also means the user can't override the kernelExtraConfig part + extraConfig = extraConfig + lib.optionalString (hostPlatform.platform ? kernelExtraConfig) hostPlatform.platform.kernelExtraConfig; + features = kernelFeatures; # Ensure we know of all extra patches, etc. }; - config = configWithPlatform stdenv.platform; - configCross = configWithPlatform hostPlatform.platform; - kernelConfigFun = baseConfig: let configFromPatches = @@ -58,38 +71,22 @@ let in lib.concatStringsSep "\n" ([baseConfig] ++ configFromPatches); configfile = stdenv.mkDerivation { - inherit ignoreConfigErrors; + inherit ignoreConfigErrors autoModules preferBuiltin kernelArch; name = "linux-config-${version}"; generateConfig = ./generate-config.pl; kernelConfig = kernelConfigFun config; - nativeBuildInputs = [ perl ]; - - platformName = stdenv.platform.name; - kernelBaseConfig = stdenv.platform.kernelBaseConfig; - kernelTarget = stdenv.platform.kernelTarget; - autoModules = stdenv.platform.kernelAutoModules; - preferBuiltin = stdenv.platform.kernelPreferBuiltin or false; - arch = stdenv.platform.kernelArch; - - crossAttrs = let - cp = hostPlatform.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; + depsBuildBuild = [ buildPackages.stdenv.cc ]; + nativeBuildInputs = [ perl ] + ++ lib.optionals (stdenv.lib.versionAtLeast version "4.16") [ bison flex ]; - kernelConfig = kernelConfigFun configCross; - - inherit (kernel.crossDrv) src patches preUnpack; - }; + platformName = hostPlatform.platform.name; + # e.g. "defconfig" + kernelBaseConfig = hostPlatform.platform.kernelBaseConfig; + # e.g. "bzImage" + kernelTarget = hostPlatform.platform.kernelTarget; prePatch = kernel.prePatch + '' # Patch kconfig to print "###" after every question so that @@ -100,33 +97,27 @@ let inherit (kernel) src patches preUnpack; buildPhase = '' - cd $buildRoot + export buildRoot="''${buildRoot:-build}" # Get a basic config file for later refinement with $generateConfig. - make -C ../$sourceRoot O=$PWD $kernelBaseConfig ARCH=$arch + make HOSTCC=${buildPackages.stdenv.cc.targetPrefix}gcc -C . O="$buildRoot" $kernelBaseConfig ARCH=$kernelArch # 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 + echo "$kernelConfig" > "$buildRoot/kernel-config" + DEBUG=1 ARCH=$kernelArch KERNEL_CONFIG="$buildRoot/kernel-config" AUTO_MODULES=$autoModules \ + PREFER_BUILTIN=$preferBuiltin BUILD_ROOT="$buildRoot" SRC=. perl -w $generateConfig ''; - installPhase = "mv .config $out"; + installPhase = "mv $buildRoot/.config $out"; enableParallelBuilding = true; }; - kernel = buildLinux { - inherit version modDirVersion src kernelPatches stdenv extraMeta; - - configfile = configfile.nativeDrv or configfile; - - crossConfigfile = configfile.crossDrv or configfile; + kernel = (callPackage ./manual-config.nix {}) { + inherit version modDirVersion src kernelPatches stdenv extraMeta configfile hostPlatform; config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; }; - - crossConfig = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; }; }; passthru = { @@ -134,10 +125,4 @@ let passthru = kernel.passthru // (removeAttrs passthru [ "passthru" ]); }; - 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 +in lib.extendDerivation true passthru kernel |