kernel: buildLinux replaces import ./generic.nix

- defined buildLinux as generic.nix instead of manual-config.nix. This
makes kernel derivations a tad more similar to your typical derivations.
- moved $buildRoot to within the source folder, this way it doesn't have to be created before the unpackPhase
and make it easier to work on kernel source without running the unpackPhase
This commit is contained in:
Matthieu Coudron 2018-01-29 03:50:18 +09:00
parent d80057f245
commit f620b1b693
18 changed files with 76 additions and 44 deletions

View file

@ -16,7 +16,7 @@
*/ */
{ stdenv, version, kernelPlatform, extraConfig, features }: { stdenv, version, extraConfig, features }:
with stdenv.lib; with stdenv.lib;
@ -682,6 +682,5 @@ with stdenv.lib;
WW_MUTEX_SELFTEST? n WW_MUTEX_SELFTEST? n
''} ''}
${kernelPlatform.kernelExtraConfig or ""}
${extraConfig} ${extraConfig}
'' ''

View file

@ -13,18 +13,18 @@ use strict;
use IPC::Open2; use IPC::Open2;
use Cwd; use Cwd;
my $wd = getcwd; # exported via nix
my $debug = $ENV{'DEBUG'}; my $debug = $ENV{'DEBUG'};
my $autoModules = $ENV{'AUTO_MODULES'}; my $autoModules = $ENV{'AUTO_MODULES'};
my $preferBuiltin = $ENV{'PREFER_BUILTIN'}; my $preferBuiltin = $ENV{'PREFER_BUILTIN'};
my $ignoreConfigErrors = $ENV{'ignoreConfigErrors'};
my $buildRoot = $ENV{'BUILD_ROOT'};
$SIG{PIPE} = 'IGNORE'; $SIG{PIPE} = 'IGNORE';
# Read the answers. # Read the answers.
my %answers; my %answers;
my %requiredAnswers; my %requiredAnswers;
open ANSWERS, "<$ENV{KERNEL_CONFIG}" or die; open ANSWERS, "<$ENV{KERNEL_CONFIG}" or die "Could not open answer file";
while (<ANSWERS>) { while (<ANSWERS>) {
chomp; chomp;
s/#.*//; s/#.*//;
@ -40,7 +40,7 @@ close ANSWERS;
sub runConfig { sub runConfig {
# Run `make config'. # Run `make config'.
my $pid = open2(\*IN, \*OUT, "make -C $ENV{SRC} O=$wd config SHELL=bash ARCH=$ENV{ARCH}"); my $pid = open2(\*IN, \*OUT, "make -C $ENV{SRC} O=$buildRoot config SHELL=bash ARCH=$ENV{ARCH}");
# Parse the output, look for questions and then send an # Parse the output, look for questions and then send an
# appropriate answer. # appropriate answer.
@ -122,7 +122,7 @@ runConfig;
# there. `make config' often overrides answers if later questions # there. `make config' often overrides answers if later questions
# cause options to be selected. # cause options to be selected.
my %config; my %config;
open CONFIG, "<.config" or die; open CONFIG, "<$buildRoot/.config" or die "Could not read .config";
while (<CONFIG>) { while (<CONFIG>) {
chomp; chomp;
if (/^CONFIG_([A-Za-z0-9_]+)="(.*)"$/) { if (/^CONFIG_([A-Za-z0-9_]+)="(.*)"$/) {
@ -137,7 +137,7 @@ while (<CONFIG>) {
close CONFIG; close CONFIG;
foreach my $name (sort (keys %answers)) { foreach my $name (sort (keys %answers)) {
my $f = $requiredAnswers{$name} && $ENV{'ignoreConfigErrors'} ne "1" my $f = $requiredAnswers{$name} && $ignoreConfigErrors ne "1"
? sub { die "error: " . $_[0]; } : sub { warn "warning: " . $_[0]; }; ? sub { die "error: " . $_[0]; } : sub { warn "warning: " . $_[0]; };
&$f("unused option: $name\n") unless defined $config{$name}; &$f("unused option: $name\n") unless defined $config{$name};
&$f("option not set correctly: $name (wanted '$answers{$name}', got '$config{$name}')\n") &$f("option not set correctly: $name (wanted '$answers{$name}', got '$config{$name}')\n")

View file

@ -1,3 +1,11 @@
{ buildPackages, runCommand, nettools, bc, perl, gmp, libmpc, mpfr, openssl
, ncurses
, libelf
, utillinux
, writeTextFile, ubootTools
, callPackage
}:
{ stdenv, buildPackages, perl, buildLinux { stdenv, buildPackages, perl, buildLinux
, # The kernel source tarball. , # The kernel source tarball.
@ -28,7 +36,7 @@
, extraMeta ? {} , extraMeta ? {}
, hostPlatform , hostPlatform
, ... , ...
}: } @ args:
assert stdenv.isLinux; assert stdenv.isLinux;
@ -45,8 +53,10 @@ let
} // features) kernelPatches; } // features) kernelPatches;
config = import ./common-config.nix { config = import ./common-config.nix {
inherit stdenv version extraConfig; inherit stdenv version ;
kernelPlatform = hostPlatform; # append extraConfig for backwards compatibility but also means the user can't override the kernelExtraConfig part
extraConfig = extraConfig + lib.optionalString (hostPlatform ? kernelExtraConfig ) hostPlatform.kernelExtraConfig;
features = kernelFeatures; # Ensure we know of all extra patches, etc. features = kernelFeatures; # Ensure we know of all extra patches, etc.
}; };
@ -68,7 +78,9 @@ let
nativeBuildInputs = [ perl ]; nativeBuildInputs = [ perl ];
platformName = hostPlatform.platform.name; platformName = hostPlatform.platform.name;
# e.g. "defconfig"
kernelBaseConfig = hostPlatform.platform.kernelBaseConfig; kernelBaseConfig = hostPlatform.platform.kernelBaseConfig;
# e.g. "bzImage"
kernelTarget = hostPlatform.platform.kernelTarget; kernelTarget = hostPlatform.platform.kernelTarget;
autoModules = hostPlatform.platform.kernelAutoModules; autoModules = hostPlatform.platform.kernelAutoModules;
preferBuiltin = hostPlatform.platform.kernelPreferBuiltin or false; preferBuiltin = hostPlatform.platform.kernelPreferBuiltin or false;
@ -83,25 +95,25 @@ let
inherit (kernel) src patches preUnpack; inherit (kernel) src patches preUnpack;
buildPhase = '' buildPhase = ''
cd $buildRoot export buildRoot="''${buildRoot:-build}"
# Get a basic config file for later refinement with $generateConfig. # Get a basic config file for later refinement with $generateConfig.
make HOSTCC=${buildPackages.stdenv.cc.targetPrefix}gcc -C ../$sourceRoot O=$PWD $kernelBaseConfig ARCH=$arch make HOSTCC=${buildPackages.stdenv.cc.targetPrefix}gcc -C . O="$buildRoot" $kernelBaseConfig ARCH=$arch
# Create the config file. # Create the config file.
echo "generating kernel configuration..." echo "generating kernel configuration..."
echo "$kernelConfig" > kernel-config echo "$kernelConfig" > "$buildRoot/kernel-config"
DEBUG=1 ARCH=$arch KERNEL_CONFIG=kernel-config AUTO_MODULES=$autoModules \ DEBUG=1 ARCH=$arch KERNEL_CONFIG="$buildRoot/kernel-config" AUTO_MODULES=$autoModules \
PREFER_BUILTIN=$preferBuiltin SRC=../$sourceRoot perl -w $generateConfig PREFER_BUILTIN=$preferBuiltin BUILD_ROOT="$buildRoot" SRC=. perl -w $generateConfig
''; '';
installPhase = "mv .config $out"; installPhase = "mv $buildRoot/.config $out";
enableParallelBuilding = true; enableParallelBuilding = true;
}; };
kernel = buildLinux { kernel = (callPackage ./manual-config.nix {}) {
inherit version modDirVersion src kernelPatches stdenv extraMeta configfile; inherit version modDirVersion src kernelPatches stdenv extraMeta configfile hostPlatform;
config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; }; config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; };
}; };

View file

@ -1,6 +1,6 @@
{ stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args: { stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
import ./generic.nix (args // rec { buildLinux (args // rec {
version = "4.13.16"; version = "4.13.16";
extraMeta.branch = "4.13"; extraMeta.branch = "4.13";

View file

@ -2,7 +2,7 @@
with stdenv.lib; with stdenv.lib;
import ./generic.nix (args // rec { buildLinux (args // rec {
version = "4.14.17"; version = "4.14.17";
# branchVersion needs to be x.y # branchVersion needs to be x.y

View file

@ -2,7 +2,7 @@
with stdenv.lib; with stdenv.lib;
import ./generic.nix (args // rec { buildLinux (args // rec {
version = "4.15.1"; version = "4.15.1";
# modDirVersion needs to be x.y.z, will automatically add .0 if needed # modDirVersion needs to be x.y.z, will automatically add .0 if needed

View file

@ -1,6 +1,6 @@
{ stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args: { stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
import ./generic.nix (args // rec { buildLinux (args // rec {
version = "4.4.115"; version = "4.4.115";
extraMeta.branch = "4.4"; extraMeta.branch = "4.4";

View file

@ -1,6 +1,6 @@
{ stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args: { stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
import ./generic.nix (args // rec { buildLinux (args // rec {
version = "4.9.80"; version = "4.9.80";
extraMeta.branch = "4.9"; extraMeta.branch = "4.9";

View file

@ -4,7 +4,7 @@ let
modDirVersion = "4.14.12"; modDirVersion = "4.14.12";
tag = "r23"; tag = "r23";
in in
stdenv.lib.overrideDerivation (import ./generic.nix (args // rec { stdenv.lib.overrideDerivation (buildLinux (args // rec {
version = "${modDirVersion}-ti-${tag}"; version = "${modDirVersion}-ti-${tag}";
inherit modDirVersion; inherit modDirVersion;

View file

@ -15,7 +15,7 @@ let
modDirVersion = "${modVersion}-hardened"; modDirVersion = "${modVersion}-hardened";
in in
import ./generic.nix (args // { buildLinux (args // {
inherit modDirVersion; inherit modDirVersion;
version = "${version}-${revision}"; version = "${version}-${revision}";

View file

@ -1,9 +1,10 @@
{ stdenv, buildPackages, hostPlatform, fetchFromGitHub, perl, buildLinux, ... } @ args: { stdenv, buildPackages, hostPlatform, fetchFromGitHub, perl, buildLinux, ... } @ args:
import ./generic.nix (rec { buildLinux (rec {
mptcpVersion = "0.93"; mptcpVersion = "0.93";
modDirVersion = "4.9.60"; modDirVersion = "4.9.60";
version = "${modDirVersion}-mptcp_v${mptcpVersion}"; version = "${modDirVersion}-mptcp_v${mptcpVersion}";
# autoModules= true;
extraMeta = { extraMeta = {
branch = "4.4"; branch = "4.4";
@ -43,4 +44,4 @@ import ./generic.nix (rec {
TCP_CONG_BALIA m TCP_CONG_BALIA m
'' + (args.extraConfig or ""); '' + (args.extraConfig or "");
} // args // (args.argsOverride or {})) } // args)

View file

@ -4,7 +4,7 @@ let
modDirVersion = "4.9.59"; modDirVersion = "4.9.59";
tag = "1.20171029"; tag = "1.20171029";
in in
stdenv.lib.overrideDerivation (import ./generic.nix (args // rec { stdenv.lib.overrideDerivation (buildLinux (args // rec {
version = "${modDirVersion}-${tag}"; version = "${modDirVersion}-${tag}";
inherit modDirVersion; inherit modDirVersion;

View file

@ -1,6 +1,6 @@
{ stdenv, buildPackages, hostPlatform, fetchFromGitHub, perl, buildLinux, ncurses, ... } @ args: { stdenv, buildPackages, hostPlatform, fetchFromGitHub, perl, buildLinux, ncurses, ... } @ args:
import ./generic.nix (args // rec { buildLinux (args // rec {
version = "4.12.2"; version = "4.12.2";
extraMeta.branch = "4.12-2"; extraMeta.branch = "4.12-2";

View file

@ -1,6 +1,6 @@
{ stdenv, buildPackages, hostPlatform, fetchgit, perl, buildLinux, ... } @ args: { stdenv, buildPackages, hostPlatform, fetchgit, perl, buildLinux, ... } @ args:
import ./generic.nix (args // rec { buildLinux (args // rec {
version = "4.11.2017.08.23"; version = "4.11.2017.08.23";
modDirVersion = "4.11.0"; modDirVersion = "4.11.0";
extraMeta.branch = "master"; extraMeta.branch = "master";

View file

@ -1,6 +1,6 @@
{ stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, libelf, utillinux, ... } @ args: { stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, libelf, utillinux, ... } @ args:
import ./generic.nix (args // rec { buildLinux (args // rec {
version = "4.15-rc9"; version = "4.15-rc9";
modDirVersion = "4.15.0-rc9"; modDirVersion = "4.15.0-rc9";
extraMeta.branch = "4.15"; extraMeta.branch = "4.15";

View file

@ -1,8 +1,8 @@
{ buildPackages, runCommand, nettools, bc, perl, gmp, libmpc, mpfr, openssl { buildPackages, runCommand, nettools, bc, perl, gmp, libmpc, mpfr, openssl
, ncurses ? null
, libelf , libelf
, utillinux , utillinux
, writeTextFile, ubootTools , writeTextFile, ubootTools
, hostPlatform
}: }:
let let
@ -34,7 +34,9 @@ in {
# Use defaultMeta // extraMeta # Use defaultMeta // extraMeta
extraMeta ? {}, extraMeta ? {},
# Whether to utilize the controversial import-from-derivation feature to parse the config # Whether to utilize the controversial import-from-derivation feature to parse the config
allowImportFromDerivation ? false allowImportFromDerivation ? false,
hostPlatform
}: }:
let let
@ -86,8 +88,6 @@ let
inherit src; inherit src;
preUnpack = '' preUnpack = ''
mkdir build
export buildRoot="$(pwd)/build"
''; '';
patches = map (p: p.patch) kernelPatches; patches = map (p: p.patch) kernelPatches;
@ -102,7 +102,25 @@ let
configurePhase = '' configurePhase = ''
runHook preConfigure runHook preConfigure
mkdir build
export buildRoot="$(pwd)/build"
echo "manual-config configurePhase buildRoot=$buildRoot pwd=$PWD"
if [[ -z "$buildRoot" || ! -d "$buildRoot" ]]; then
echo "set $buildRoot to the build folder please"
exit 1
fi
if [ -f "$buildRoot/.config" ]; then
echo "Could not link $buildRoot/.config : file exists"
exit 1
fi
ln -sv ${configfile} $buildRoot/.config ln -sv ${configfile} $buildRoot/.config
# 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 make $makeFlags "''${makeFlagsArray[@]}" oldconfig
runHook postConfigure runHook postConfigure
@ -115,6 +133,8 @@ let
# Note: we can get rid of this once http://permalink.gmane.org/gmane.linux.kbuild.devel/13800 is merged. # Note: we can get rid of this once http://permalink.gmane.org/gmane.linux.kbuild.devel/13800 is merged.
buildFlagsArray+=("KBUILD_BUILD_TIMESTAMP=$(date -u -d @$SOURCE_DATE_EPOCH)") buildFlagsArray+=("KBUILD_BUILD_TIMESTAMP=$(date -u -d @$SOURCE_DATE_EPOCH)")
cd $buildRoot
''; '';
buildFlags = [ buildFlags = [
@ -136,7 +156,7 @@ let
postInstall = '' postInstall = ''
mkdir -p $dev mkdir -p $dev
cp $buildRoot/vmlinux $dev/ cp vmlinux $dev/
'' + (optionalString installsFirmware '' '' + (optionalString installsFirmware ''
mkdir -p $out/lib/firmware mkdir -p $out/lib/firmware
'') + (if (platform ? kernelDTB && platform.kernelDTB) then '' '') + (if (platform ? kernelDTB && platform.kernelDTB) then ''
@ -151,7 +171,7 @@ let
unlink $out/lib/modules/${modDirVersion}/source unlink $out/lib/modules/${modDirVersion}/source
mkdir -p $dev/lib/modules/${modDirVersion}/build mkdir -p $dev/lib/modules/${modDirVersion}/build
cp -dpR ../$sourceRoot $dev/lib/modules/${modDirVersion}/source cp -dpR .. $dev/lib/modules/${modDirVersion}/source
cd $dev/lib/modules/${modDirVersion}/source cd $dev/lib/modules/${modDirVersion}/source
cp $buildRoot/{.config,Module.symvers} $dev/lib/modules/${modDirVersion}/build cp $buildRoot/{.config,Module.symvers} $dev/lib/modules/${modDirVersion}/build
@ -170,7 +190,7 @@ let
# from drivers/ in the future; it adds 50M to keep all of its # from drivers/ in the future; it adds 50M to keep all of its
# headers on 3.10 though. # headers on 3.10 though.
chmod u+w -R ../source chmod u+w -R ..
arch=$(cd $dev/lib/modules/${modDirVersion}/build/arch; ls) arch=$(cd $dev/lib/modules/${modDirVersion}/build/arch; ls)
# Remove unused arches # Remove unused arches

View file

@ -50,13 +50,13 @@ ls $NIXPKGS/pkgs/os-specific/linux/kernel | while read FILE; do
# Rewrite the expression # Rewrite the expression
sed -i -e '/version = /d' -e '/modDirVersion = /d' $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE sed -i -e '/version = /d' -e '/modDirVersion = /d' $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE
if grep -q '^[0-9]\+.[0-9]\+$' <<< "$V"; then if grep -q '^[0-9]\+.[0-9]\+$' <<< "$V"; then
sed -i "\#import ./generic.nix (args // rec {#a \ modDirVersion = \"${V}.0\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE sed -i "\#buildLinux (args // rec {#a \ modDirVersion = \"${V}.0\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE
fi fi
sed -i "\#import ./generic.nix (args // rec {#a \ version = \"$V\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE sed -i "\#buildLinux (args // rec {#a \ version = \"$V\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE
# Commit the changes # Commit the changes
git add -u $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE git add -u $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE
git commit -m "kernel: $OLDVER -> $V" >/dev/null 2>&1 git commit -m "kernel: $OLDVER -> $V" >/dev/null 2>&1
echo "Updated $OLDVER -> $V" echo "Updated $OLDVER -> $V"
done done

View file

@ -13197,7 +13197,7 @@ with pkgs;
# A function to build a manually-configured kernel # A function to build a manually-configured kernel
linuxManualConfig = pkgs.buildLinux; linuxManualConfig = pkgs.buildLinux;
buildLinux = makeOverridable (callPackage ../os-specific/linux/kernel/manual-config.nix {}); buildLinux = makeOverridable (callPackage ../os-specific/linux/kernel/generic.nix {});
keyutils = callPackage ../os-specific/linux/keyutils { }; keyutils = callPackage ../os-specific/linux/keyutils { };