1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-17 13:10:29 +03:00

kernel-builder: Implement kernel normalization as a nix build

This uses the actual output expected by the build, rather than hoping
menuconfig gives the same result.

For kernels prior to 5.8 it wasn't an issue.

Starting with 5.8 the build environment will influence the actual
configuration used.

We're stripping some information when comparing.

The exact TEXT_VERSION string will change according to whether it's a
native or cross compilation.

Finally, minor version bumps are not relevant here.
This commit is contained in:
Samuel Dionne-Riel 2020-09-29 22:12:50 -04:00
parent c708340e8e
commit 4060dd5af5

View File

@ -105,6 +105,10 @@ let kernel = stdenv.mkDerivation {
pname = "linux";
inherit src version file;
# Allows disabling the kernel config normalization.
# Set to false when normalizing the kernel config.
forceNormalizedConfig = true;
depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ perl bc nettools openssl rsync gmp libmpc mpfr ]
++ optional (stdenv.hostPlatform.platform.kernelTarget == "uImage") buildPackages.ubootTools
@ -182,15 +186,37 @@ let kernel = stdenv.mkDerivation {
# reads the existing .config file and prompts the user for options in
# the current kernel source that are not found in the file.
make $makeFlags "''${makeFlagsArray[@]}" oldconfig
if ! diff -q $buildRoot/.config{.old,}; then
printf "\n\n--------------------------------\n"
diff -u $buildRoot/.config{.old,} || :
printf "\n--------------------------------\n\n"
echo 'error: Your configuration does not match once passed through `make oldconfig`.'
echo ' Use the `bin/kernel-normalize-config` tool to refresh the configuration.'
echo " Don't forget to make sure the changed configuration options are good!"
printf "\n"
exit 1
if [ -n "$forceNormalizedConfig" ]; then
if [ -e $buildRoot/.config.old ]; then
# First we strip options that save the exact compiler version.
# This is first because it will break with cross-compilation.
# It also will break on minor version bumps.
# We do not strip options related to compiler features, since
# compiler features changing is something we want to track, I think.
(
cd $buildRoot
for f in .config{,.old}; do
sed \
-e 's;CONFIG_CC_VERSION_TEXT=.*;CONFIG_CC_VERSION_TEXT=;' \
-e 's;CONFIG_GCC_VERSION=.*;CONFIG_GCC_VERSION=;' \
-e 's;CONFIG_LD_VERSION=.*;CONFIG_LD_VERSION=;' \
-e 's;CONFIG_CLANG_VERSION=.*;CONFIG_CLANG_VERSION=;' \
$f > .tmp$f
done
)
if ! diff -q $buildRoot/.tmp.config{.old,}; then
printf "\n\n--------------------------------\n"
diff -u $buildRoot/.tmp.config{.old,} || :
printf "\n--------------------------------\n\n"
echo 'error: Your configuration does not match once passed through `make oldconfig`.'
echo ' Use the `bin/kernel-normalize-config` tool to refresh the configuration.'
echo " Don't forget to make sure the changed configuration options are good!"
printf "\n"
exit 1
fi
rm -v $buildRoot/.tmp.config{.old,}
fi
fi
runHook postConfigure
@ -248,6 +274,13 @@ let kernel = stdenv.mkDerivation {
dontStrip = true;
passthru = {
normalizedConfig = kernel.overrideAttrs({ ... }: {
forceNormalizedConfig = false;
buildPhase = "echo Skipping build phase...";
installPhase = ''
cp .config $out
'';
});
# Patching over this configuration to expose menuconfig.
menuconfig = kernel.overrideAttrs({nativeBuildInputs ? [] , ...}: {
nativeBuildInputs = nativeBuildInputs ++ [