lol
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement generic kernel build via manual-config

This has three major benefits:

1. We no longer have two kernel build processes to maintain

2. The build process is (IMO) cleaner and cleaves more closely to
upstream. In partuclar, we use make install to install the kernel and
development source/build trees, eliminating the guesswork about which
files to copy.

3. The derivation has multiple outputs: the kernel and modules are in
the default `out' output, while the build and source trees are in a
`dev' output. This makes it possible for the full source and build tree
to be kept (which is expected by out-of-tree modules) without bloating
the closure of the system derivation.

In addition, if a solution for how to handle queries in the presence of
imports from derivations ever makes it into nix, a framework for
querying the full configuration of the kernel in nix expressions is
already in place.

Signed-off-by: Shea Levy <shea@shealevy.com>

Shea Levy f95d214c a87b1f36

+82 -253
-149
pkgs/os-specific/linux/kernel/builder.sh
··· 1 - source $stdenv/setup 2 - 3 - 4 - makeFlags="ARCH=$arch SHELL=/bin/sh KBUILD_BUILD_VERSION=1-NixOS $makeFlags" 5 - if [ -n "$crossConfig" ]; then 6 - makeFlags="$makeFlags CROSS_COMPILE=$crossConfig-" 7 - fi 8 - 9 - postPatch() { 10 - # Makefiles are full of /bin/pwd, /bin/false, /bin/bash, etc. 11 - # Patch these away, assuming the tools are in $PATH. 12 - for mf in $(find -name Makefile); do 13 - echo "stripping FHS paths in \`$mf'..." 14 - sed -i "$mf" -e 's|/usr/bin/||g ; s|/bin/||g' 15 - done 16 - } 17 - 18 - configurePhase() { 19 - if test -n "$preConfigure"; then 20 - eval "$preConfigure" 21 - fi 22 - 23 - export INSTALL_PATH=$out 24 - export INSTALL_MOD_PATH=$out 25 - 26 - # Set our own localversion, if specified. 27 - rm -f localversion* 28 - if test -n "$localVersion"; then 29 - echo "$localVersion" > localversion-nix 30 - fi 31 - 32 - # Patch kconfig to print "###" after every question so that 33 - # generate-config.pl can answer them. 34 - sed -e '/fflush(stdout);/i\printf("###");' -i scripts/kconfig/conf.c 35 - 36 - # Get a basic config file for later refinement with $generateConfig. 37 - make $kernelBaseConfig ARCH=$arch 38 - 39 - # Create the config file. 40 - echo "generating kernel configuration..." 41 - echo "$kernelConfig" > kernel-config 42 - DEBUG=1 ARCH=$arch KERNEL_CONFIG=kernel-config AUTO_MODULES=$autoModules \ 43 - perl -w $generateConfig 44 - } 45 - 46 - 47 - installPhase() { 48 - 49 - mkdir -p $out 50 - 51 - # New kernel versions have a combined tree for i386 and x86_64. 52 - archDir=$arch 53 - if test -e arch/x86 -a \( "$arch" = i386 -o "$arch" = x86_64 \); then 54 - archDir=x86 55 - fi 56 - 57 - 58 - # Copy the bzImage and System.map. 59 - cp System.map $out 60 - if test "$arch" = um; then 61 - mkdir -p $out/bin 62 - cp linux $out/bin 63 - elif test "$kernelTarget" != "vmlinux"; then 64 - # In any case we copy the 'vmlinux' ELF in the next lines 65 - cp arch/$archDir/boot/$kernelTarget $out 66 - fi 67 - 68 - cp vmlinux $out 69 - 70 - if grep -q "CONFIG_MODULES=y" .config; then 71 - # Install the modules in $out/lib/modules. 72 - make modules_install \ 73 - DEPMOD=$kmod/sbin/depmod \ 74 - $makeFlags "${makeFlagsArray[@]}" \ 75 - $installFlags "${installFlagsArray[@]}" 76 - 77 - if test -z "$dontStrip"; then 78 - # Strip the kernel modules. 79 - echo "Stripping kernel modules..." 80 - if [ -z "$crossConfig" ]; then 81 - find $out -name "*.ko" -print0 | xargs -0 strip -S 82 - else 83 - find $out -name "*.ko" -print0 | xargs -0 $crossConfig-strip -S 84 - fi 85 - fi 86 - 87 - # move this to install later on 88 - # largely copied from early FC3 kernel spec files 89 - version=$(cd $out/lib/modules && ls -d *) 90 - 91 - # remove symlinks and create directories 92 - rm -f $out/lib/modules/$version/build 93 - rm -f $out/lib/modules/$version/source 94 - mkdir $out/lib/modules/$version/build 95 - 96 - # copy config 97 - cp .config $out/lib/modules/$version/build/.config 98 - ln -s $out/lib/modules/$version/build/.config $out/config 99 - 100 - if test "$arch" != um; then 101 - # copy all Makefiles and Kconfig files 102 - ln -s $out/lib/modules/$version/build $out/lib/modules/$version/source 103 - cp --parents `find -type f -name Makefile -o -name "Kconfig*"` $out/lib/modules/$version/build 104 - cp Module.symvers $out/lib/modules/$version/build 105 - 106 - if test "$dontStrip" = "1"; then 107 - # copy any debugging info that can be found 108 - cp --parents -rv `find -name \*.debug -o -name debug.a` \ 109 - "$out/lib/modules/$version/build" 110 - fi 111 - 112 - # weed out unneeded stuff 113 - rm -rf $out/lib/modules/$version/build/Documentation 114 - rm -rf $out/lib/modules/$version/build/scripts 115 - rm -rf $out/lib/modules/$version/build/include 116 - 117 - # copy architecture dependent files 118 - cp -a arch/$archDir/scripts $out/lib/modules/$version/build/ || true 119 - cp -a arch/$archDir/*lds $out/lib/modules/$version/build/ || true 120 - cp -a arch/$archDir/Makefile*.cpu $out/lib/modules/$version/build/arch/$archDir/ || true 121 - cp -a --parents arch/$archDir/kernel/asm-offsets.s $out/lib/modules/$version/build/arch/$archDir/kernel/ || true 122 - 123 - # copy scripts 124 - rm -f scripts/*.o 125 - rm -f scripts/*/*.o 126 - cp -a scripts $out/lib/modules/$version/build 127 - 128 - # copy include files 129 - includeDir=$out/lib/modules/$version/build/include 130 - mkdir -p $includeDir 131 - (cd include && cp -a * $includeDir) 132 - (cd arch/$archDir/include && cp -a * $includeDir || true) 133 - (cd arch/$archDir/include && cp -a asm/* $includeDir/asm/ || true) 134 - (cd arch/$archDir/include && cp -a generated/asm/* $includeDir/asm/ || true) 135 - (cd arch/$archDir/include/asm/mach-generic && cp -a * $includeDir/ || true) 136 - # include files for special arm architectures 137 - if [ "$archDir" == "arm" ]; then 138 - cp -a --parents arch/arm/mach-*/include $out/lib/modules/$version/build 139 - fi 140 - fi 141 - fi 142 - 143 - if test -n "$postInstall"; then 144 - eval "$postInstall"; 145 - fi 146 - } 147 - 148 - 149 - genericBuild
+4 -1
pkgs/os-specific/linux/kernel/generate-config.pl
··· 11 11 12 12 use strict; 13 13 use IPC::Open2; 14 + use Cwd; 15 + 16 + my $wd = getcwd; 14 17 15 18 my $debug = $ENV{'DEBUG'}; 16 19 my $autoModules = $ENV{'AUTO_MODULES'}; ··· 36 39 sub runConfig { 37 40 38 41 # Run `make config'. 39 - my $pid = open2(\*IN, \*OUT, "make config SHELL=bash ARCH=$ENV{ARCH}"); 42 + my $pid = open2(\*IN, \*OUT, "make -C $ENV{SRC} O=$wd config SHELL=bash ARCH=$ENV{ARCH}"); 40 43 41 44 # Parse the output, look for questions and then send an 42 45 # appropriate answer.
+54 -84
pkgs/os-specific/linux/kernel/generic.nix
··· 1 - { stdenv, fetchurl, perl, mktemp, kmod, bc 1 + { stdenv, perl, linuxManualConfig 2 2 3 3 , # The kernel source tarball. 4 4 src ··· 23 23 # symbolic name and `patch' is the actual patch. The patch may 24 24 # optionally be compressed with gzip or bzip2. 25 25 kernelPatches ? [] 26 - 27 - , # Allows you to set your own kernel version suffix (e.g., 28 - # "-my-kernel"). 29 - localVersion ? "" 30 - 31 - , preConfigure ? "" 32 26 , extraMeta ? {} 33 - , ubootChooser ? null 34 - , postInstall ? "" 35 - 36 - , # After the builder did a 'make all' (kernel + modules) 37 - # we force building the target asked: bzImage/zImage/uImage/... 38 - postBuild ? "make $makeFlags $kernelTarget; make $makeFlags -C scripts unifdef" 39 - 40 27 , ... 41 28 }: 42 29 ··· 52 39 map ({extraConfig ? "", ...}: extraConfig) kernelPatches; 53 40 in lib.concatStringsSep "\n" ([baseConfig] ++ configFromPatches); 54 41 55 - configWithPlatform = kernelPlatform: 56 - import ./common-config.nix { inherit stdenv version kernelPlatform extraConfig; }; 42 + configfile = stdenv.mkDerivation { 43 + name = "linux-config-${version}"; 57 44 58 - config = configWithPlatform stdenv.platform; 59 - configCross = configWithPlatform stdenv.cross.platform; 45 + generateConfig = ./generate-config.pl; 60 46 61 - in 47 + kernelConfig = kernelConfigFun config; 62 48 63 - stdenv.mkDerivation { 64 - name = "linux-${version}"; 49 + ignoreConfigErrors = stdenv.platform.name != "pc"; 65 50 66 - enableParallelBuilding = true; 51 + nativeBuildInputs = [ perl ]; 67 52 68 - passthru = { 69 - inherit version modDirVersion kernelPatches; 70 - # Combine the `features' attribute sets of all the kernel patches. 71 - features = lib.fold (x: y: (x.features or {}) // y) features kernelPatches; 72 - }; 53 + platformName = stdenv.platform.name; 54 + kernelBaseConfig = stdenv.platform.kernelBaseConfig; 55 + kernelTarget = stdenv.platform.kernelTarget; 56 + autoModules = stdenv.platform.kernelAutoModules; 57 + arch = stdenv.platform.kernelArch; 73 58 74 - builder = ./builder.sh; 75 - 76 - generateConfig = ./generate-config.pl; 59 + crossAttrs = let 60 + cp = stdenv.cross.platform; 61 + in { 62 + arch = cp.kernelArch; 63 + platformName = cp.name; 64 + kernelBaseConfig = cp.kernelBaseConfig; 65 + kernelTarget = cp.kernelTarget; 66 + autoModules = cp.kernelAutoModules; 77 67 78 - inherit preConfigure src kmod localVersion postInstall postBuild; 68 + # Just ignore all options that don't apply (We are lazy). 69 + ignoreConfigErrors = true; 79 70 80 - patches = map (p: p.patch) kernelPatches; 71 + kernelConfig = kernelConfigFun configCross; 72 + }; 73 + buildCommand = '' 74 + # Get a basic config file for later refinement with $generateConfig. 75 + make -C ${kernel.sourceRoot} O=$PWD $kernelBaseConfig ARCH=$arch 81 76 82 - kernelConfig = kernelConfigFun config; 77 + # Create the config file. 78 + echo "generating kernel configuration..." 79 + echo "$kernelConfig" > kernel-config 80 + DEBUG=1 ARCH=$arch KERNEL_CONFIG=kernel-config AUTO_MODULES=$autoModules \ 81 + SRC=${kernel.sourceRoot} perl -w $generateConfig 82 + mv .config $out 83 + ''; 84 + }; 83 85 84 - # For UML and non-PC, just ignore all options that don't apply (We are lazy). 85 - ignoreConfigErrors = stdenv.platform.name != "pc"; 86 + kernel = linuxManualConfig { 87 + inherit version modDirVersion src kernelPatches; 86 88 87 - nativeBuildInputs = [ perl mktemp bc ]; 89 + configfile = configfile.nativeDrv or configfile; 88 90 89 - buildInputs = lib.optional (stdenv.platform.uboot != null) 90 - (ubootChooser stdenv.platform.uboot); 91 + crossConfigfile = configfile.crossDrv or configfile; 91 92 92 - platformName = stdenv.platform.name; 93 - kernelBaseConfig = stdenv.platform.kernelBaseConfig; 94 - kernelTarget = stdenv.platform.kernelTarget; 95 - autoModules = stdenv.platform.kernelAutoModules; 93 + config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; }; 96 94 97 - # Should we trust platform.kernelArch? We can only do 98 - # that once we differentiate i686/x86_64 in platforms. 99 - arch = 100 - if stdenv.system == "i686-linux" then "i386" else 101 - if stdenv.system == "x86_64-linux" then "x86_64" else 102 - if stdenv.isArm then "arm" else 103 - if stdenv.system == "mips64el-linux" then "mips" else 104 - abort "Platform ${stdenv.system} is not supported."; 95 + crossConfig = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; }; 96 + }; 105 97 106 - crossAttrs = let 107 - cp = stdenv.cross.platform; 108 - in 109 - assert cp.name == "sheevaplug" -> cp.uboot != null; 110 - { 111 - arch = cp.kernelArch; 112 - platformName = cp.name; 113 - kernelBaseConfig = cp.kernelBaseConfig; 114 - kernelTarget = cp.kernelTarget; 115 - autoModules = cp.kernelAutoModules; 98 + configWithPlatform = kernelPlatform: 99 + import ./common-config.nix { inherit stdenv version kernelPlatform extraConfig; }; 116 100 117 - # Just ignore all options that don't apply (We are lazy). 118 - ignoreConfigErrors = true; 101 + config = configWithPlatform stdenv.platform; 102 + configCross = configWithPlatform stdenv.cross.platform; 119 103 120 - kernelConfig = kernelConfigFun configCross; 104 + passthru = { 105 + # Combine the `features' attribute sets of all the kernel patches. 106 + features = lib.fold (x: y: (x.features or {}) // y) features kernelPatches; 121 107 122 - # The substitution of crossAttrs happens *after* the stdenv cross adapter sets 123 - # the parameters for the usual stdenv. Thus, we need to specify 124 - # the ".crossDrv" in the buildInputs here. 125 - buildInputs = lib.optional (cp.uboot != null) (ubootChooser cp.uboot).crossDrv; 126 - }; 108 + meta = kernel.meta // extraMeta; 109 + }; 127 110 128 - meta = { 129 - description = 130 - "The Linux kernel" + 131 - (if kernelPatches == [] then "" else 132 - " (with patches: " 133 - + lib.concatStrings (lib.intersperse ", " (map (x: x.name) kernelPatches)) 134 - + ")"); 135 - license = "GPLv2"; 136 - homepage = http://www.kernel.org/; 137 - maintainers = [ 138 - lib.maintainers.eelco 139 - lib.maintainers.chaoflow 140 - ]; 141 - platforms = lib.platforms.linux; 142 - } // extraMeta; 143 - } 111 + nativeDrv = lib.addPassthru kernel.nativeDrv passthru; 144 112 113 + crossDrv = lib.addPassthru kernel.crossDrv passthru; 114 + in if kernel ? crossDrv then nativeDrv // { inherit nativeDrv crossDrv; } else lib.addPassthru kernel passthru
+18 -13
pkgs/os-specific/linux/kernel/manual-config.nix
··· 48 48 ''; }; 49 49 50 50 commonMakeFlags = [ 51 - "O=$(buildRoot)" 51 + "O=$(buildRoot)" "KBUILD_BUILD_VERSION=1-NixOS" 52 52 ]; 53 53 54 54 drvAttrs = config_: platform: kernelPatches: configfile: ··· 124 124 runHook postConfigure 125 125 ''; 126 126 127 - buildFlags = [ stdenv.platform.kernelTarget ] ++ optional isModular "modules"; 127 + buildFlags = [ platform.kernelTarget ] ++ optional isModular "modules"; 128 128 129 129 installFlags = [ 130 130 "INSTALLKERNEL=${installkernel}" ··· 158 158 "s|${sourceRoot}|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-${sourceRoot.name}|g" 159 159 fi 160 160 '' else null; 161 + 162 + meta = { 163 + description = 164 + "The Linux kernel" + 165 + (if kernelPatches == [] then "" else 166 + " (with patches: " 167 + + stdenv.lib.concatStrings (stdenv.lib.intersperse ", " (map (x: x.name) kernelPatches)) 168 + + ")"); 169 + license = "GPLv2"; 170 + homepage = http://www.kernel.org/; 171 + maintainers = [ 172 + maintainers.shlevy 173 + ]; 174 + platforms = platforms.linux; 175 + }; 161 176 }; 162 177 in 163 178 ··· 173 188 "ARCH=${stdenv.platform.kernelArch}" 174 189 ]; 175 190 176 - crossAttrs = let cp = stdenv.cross.platform; in { 191 + crossAttrs = let cp = stdenv.cross.platform; in 177 192 (drvAttrs crossConfig cp (kernelPatches ++ crossKernelPatches) crossConfigfile) // { 178 193 makeFlags = commonMakeFlags ++ [ 179 194 "ARCH=${cp.kernelArch}" ··· 185 200 # can just go into buildInputs (but not nativeBuildInputs since cp.uboot 186 201 # may be different from stdenv.platform.uboot) 187 202 buildInputs = optional (cp.uboot != null) (ubootChooser cp.uboot).crossDrv; 188 - }; 189 - 190 - meta = { 191 - description = "The Linux kernel"; 192 - license = "GPLv2"; 193 - homepage = http://www.kernel.org/; 194 - maintainers = [ 195 - maintainers.shlevy 196 - ]; 197 - platforms = platforms.linux; 198 203 }; 199 204 })
+6 -6
pkgs/top-level/all-packages.nix
··· 6704 6704 kernelPatches = callPackage ../os-specific/linux/kernel/patches.nix { }; 6705 6705 6706 6706 linux_3_2 = makeOverridable (import ../os-specific/linux/kernel/linux-3.2.nix) { 6707 - inherit fetchurl stdenv perl mktemp bc kmod ubootChooser; 6707 + inherit fetchurl stdenv perl linuxManualConfig; 6708 6708 kernelPatches = 6709 6709 [ kernelPatches.sec_perm_2_6_24 6710 6710 # kernelPatches.aufs3_2 ··· 6754 6754 }); 6755 6755 6756 6756 linux_3_4 = makeOverridable (import ../os-specific/linux/kernel/linux-3.4.nix) { 6757 - inherit fetchurl stdenv perl mktemp bc kmod ubootChooser; 6757 + inherit fetchurl stdenv perl linuxManualConfig; 6758 6758 kernelPatches = 6759 6759 [ kernelPatches.sec_perm_2_6_24 6760 6760 # kernelPatches.aufs3_4 ··· 6773 6773 }); 6774 6774 6775 6775 linux_3_6_rpi = makeOverridable (import ../os-specific/linux/kernel/linux-rpi-3.6.nix) { 6776 - inherit fetchurl stdenv perl mktemp bc kmod ubootChooser; 6776 + inherit fetchurl stdenv perl linuxManualConfig; 6777 6777 }; 6778 6778 6779 6779 linux_3_10 = makeOverridable (import ../os-specific/linux/kernel/linux-3.10.nix) { 6780 - inherit fetchurl stdenv perl mktemp bc kmod ubootChooser; 6780 + inherit fetchurl stdenv perl linuxManualConfig; 6781 6781 kernelPatches = 6782 6782 [ 6783 6783 kernelPatches.sec_perm_2_6_24 ··· 6798 6798 }); 6799 6799 6800 6800 linux_3_11 = makeOverridable (import ../os-specific/linux/kernel/linux-3.11.nix) { 6801 - inherit fetchurl stdenv perl mktemp bc kmod ubootChooser; 6801 + inherit fetchurl stdenv perl linuxManualConfig; 6802 6802 kernelPatches = 6803 6803 [ 6804 6804 kernelPatches.sec_perm_2_6_24 ··· 6810 6810 }; 6811 6811 6812 6812 linux_3_12 = makeOverridable (import ../os-specific/linux/kernel/linux-3.12.nix) { 6813 - inherit fetchurl stdenv perl mktemp bc kmod ubootChooser; 6813 + inherit fetchurl stdenv perl linuxManualConfig; 6814 6814 kernelPatches = 6815 6815 [ 6816 6816 kernelPatches.sec_perm_2_6_24