lol

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

+76 -44
+1 -2
pkgs/os-specific/linux/kernel/common-config.nix
··· 16 16 17 17 */ 18 18 19 - { stdenv, version, kernelPlatform, extraConfig, features }: 19 + { stdenv, version, extraConfig, features }: 20 20 21 21 with stdenv.lib; 22 22 ··· 682 682 WW_MUTEX_SELFTEST? n 683 683 ''} 684 684 685 - ${kernelPlatform.kernelExtraConfig or ""} 686 685 ${extraConfig} 687 686 ''
+7 -7
pkgs/os-specific/linux/kernel/generate-config.pl
··· 13 13 use IPC::Open2; 14 14 use Cwd; 15 15 16 - my $wd = getcwd; 17 - 16 + # exported via nix 18 17 my $debug = $ENV{'DEBUG'}; 19 18 my $autoModules = $ENV{'AUTO_MODULES'}; 20 19 my $preferBuiltin = $ENV{'PREFER_BUILTIN'}; 21 - 20 + my $ignoreConfigErrors = $ENV{'ignoreConfigErrors'}; 21 + my $buildRoot = $ENV{'BUILD_ROOT'}; 22 22 $SIG{PIPE} = 'IGNORE'; 23 23 24 24 # Read the answers. 25 25 my %answers; 26 26 my %requiredAnswers; 27 - open ANSWERS, "<$ENV{KERNEL_CONFIG}" or die; 27 + open ANSWERS, "<$ENV{KERNEL_CONFIG}" or die "Could not open answer file"; 28 28 while (<ANSWERS>) { 29 29 chomp; 30 30 s/#.*//; ··· 40 40 sub runConfig { 41 41 42 42 # Run `make config'. 43 - my $pid = open2(\*IN, \*OUT, "make -C $ENV{SRC} O=$wd config SHELL=bash ARCH=$ENV{ARCH}"); 43 + my $pid = open2(\*IN, \*OUT, "make -C $ENV{SRC} O=$buildRoot config SHELL=bash ARCH=$ENV{ARCH}"); 44 44 45 45 # Parse the output, look for questions and then send an 46 46 # appropriate answer. ··· 122 122 # there. `make config' often overrides answers if later questions 123 123 # cause options to be selected. 124 124 my %config; 125 - open CONFIG, "<.config" or die; 125 + open CONFIG, "<$buildRoot/.config" or die "Could not read .config"; 126 126 while (<CONFIG>) { 127 127 chomp; 128 128 if (/^CONFIG_([A-Za-z0-9_]+)="(.*)"$/) { ··· 137 137 close CONFIG; 138 138 139 139 foreach my $name (sort (keys %answers)) { 140 - my $f = $requiredAnswers{$name} && $ENV{'ignoreConfigErrors'} ne "1" 140 + my $f = $requiredAnswers{$name} && $ignoreConfigErrors ne "1" 141 141 ? sub { die "error: " . $_[0]; } : sub { warn "warning: " . $_[0]; }; 142 142 &$f("unused option: $name\n") unless defined $config{$name}; 143 143 &$f("option not set correctly: $name (wanted '$answers{$name}', got '$config{$name}')\n")
+23 -11
pkgs/os-specific/linux/kernel/generic.nix
··· 1 + { buildPackages, runCommand, nettools, bc, perl, gmp, libmpc, mpfr, openssl 2 + , ncurses 3 + , libelf 4 + , utillinux 5 + , writeTextFile, ubootTools 6 + , callPackage 7 + }: 8 + 1 9 { stdenv, buildPackages, perl, buildLinux 2 10 3 11 , # The kernel source tarball. ··· 28 36 , extraMeta ? {} 29 37 , hostPlatform 30 38 , ... 31 - }: 39 + } @ args: 32 40 33 41 assert stdenv.isLinux; 34 42 ··· 45 53 } // features) kernelPatches; 46 54 47 55 config = import ./common-config.nix { 48 - inherit stdenv version extraConfig; 49 - kernelPlatform = hostPlatform; 56 + inherit stdenv version ; 57 + # append extraConfig for backwards compatibility but also means the user can't override the kernelExtraConfig part 58 + extraConfig = extraConfig + lib.optionalString (hostPlatform ? kernelExtraConfig ) hostPlatform.kernelExtraConfig; 59 + 50 60 features = kernelFeatures; # Ensure we know of all extra patches, etc. 51 61 }; 52 62 ··· 68 78 nativeBuildInputs = [ perl ]; 69 79 70 80 platformName = hostPlatform.platform.name; 81 + # e.g. "defconfig" 71 82 kernelBaseConfig = hostPlatform.platform.kernelBaseConfig; 83 + # e.g. "bzImage" 72 84 kernelTarget = hostPlatform.platform.kernelTarget; 73 85 autoModules = hostPlatform.platform.kernelAutoModules; 74 86 preferBuiltin = hostPlatform.platform.kernelPreferBuiltin or false; ··· 83 95 inherit (kernel) src patches preUnpack; 84 96 85 97 buildPhase = '' 86 - cd $buildRoot 98 + export buildRoot="''${buildRoot:-build}" 87 99 88 100 # Get a basic config file for later refinement with $generateConfig. 89 - make HOSTCC=${buildPackages.stdenv.cc.targetPrefix}gcc -C ../$sourceRoot O=$PWD $kernelBaseConfig ARCH=$arch 101 + make HOSTCC=${buildPackages.stdenv.cc.targetPrefix}gcc -C . O="$buildRoot" $kernelBaseConfig ARCH=$arch 90 102 91 103 # Create the config file. 92 104 echo "generating kernel configuration..." 93 - echo "$kernelConfig" > kernel-config 94 - DEBUG=1 ARCH=$arch KERNEL_CONFIG=kernel-config AUTO_MODULES=$autoModules \ 95 - PREFER_BUILTIN=$preferBuiltin SRC=../$sourceRoot perl -w $generateConfig 105 + echo "$kernelConfig" > "$buildRoot/kernel-config" 106 + DEBUG=1 ARCH=$arch KERNEL_CONFIG="$buildRoot/kernel-config" AUTO_MODULES=$autoModules \ 107 + PREFER_BUILTIN=$preferBuiltin BUILD_ROOT="$buildRoot" SRC=. perl -w $generateConfig 96 108 ''; 97 109 98 - installPhase = "mv .config $out"; 110 + installPhase = "mv $buildRoot/.config $out"; 99 111 100 112 enableParallelBuilding = true; 101 113 }; 102 114 103 - kernel = buildLinux { 104 - inherit version modDirVersion src kernelPatches stdenv extraMeta configfile; 115 + kernel = (callPackage ./manual-config.nix {}) { 116 + inherit version modDirVersion src kernelPatches stdenv extraMeta configfile hostPlatform; 105 117 106 118 config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; }; 107 119 };
+1 -1
pkgs/os-specific/linux/kernel/linux-4.13.nix
··· 1 1 { stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args: 2 2 3 - import ./generic.nix (args // rec { 3 + buildLinux (args // rec { 4 4 version = "4.13.16"; 5 5 extraMeta.branch = "4.13"; 6 6
+1 -1
pkgs/os-specific/linux/kernel/linux-4.14.nix
··· 2 2 3 3 with stdenv.lib; 4 4 5 - import ./generic.nix (args // rec { 5 + buildLinux (args // rec { 6 6 version = "4.14.17"; 7 7 8 8 # branchVersion needs to be x.y
+1 -1
pkgs/os-specific/linux/kernel/linux-4.15.nix
··· 2 2 3 3 with stdenv.lib; 4 4 5 - import ./generic.nix (args // rec { 5 + buildLinux (args // rec { 6 6 version = "4.15.1"; 7 7 8 8 # modDirVersion needs to be x.y.z, will automatically add .0 if needed
+1 -1
pkgs/os-specific/linux/kernel/linux-4.4.nix
··· 1 1 { stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args: 2 2 3 - import ./generic.nix (args // rec { 3 + buildLinux (args // rec { 4 4 version = "4.4.115"; 5 5 extraMeta.branch = "4.4"; 6 6
+1 -1
pkgs/os-specific/linux/kernel/linux-4.9.nix
··· 1 1 { stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args: 2 2 3 - import ./generic.nix (args // rec { 3 + buildLinux (args // rec { 4 4 version = "4.9.80"; 5 5 extraMeta.branch = "4.9"; 6 6
+1 -1
pkgs/os-specific/linux/kernel/linux-beagleboard.nix
··· 4 4 modDirVersion = "4.14.12"; 5 5 tag = "r23"; 6 6 in 7 - stdenv.lib.overrideDerivation (import ./generic.nix (args // rec { 7 + stdenv.lib.overrideDerivation (buildLinux (args // rec { 8 8 version = "${modDirVersion}-ti-${tag}"; 9 9 inherit modDirVersion; 10 10
+1 -1
pkgs/os-specific/linux/kernel/linux-hardened-copperhead.nix
··· 15 15 16 16 modDirVersion = "${modVersion}-hardened"; 17 17 in 18 - import ./generic.nix (args // { 18 + buildLinux (args // { 19 19 inherit modDirVersion; 20 20 21 21 version = "${version}-${revision}";
+3 -2
pkgs/os-specific/linux/kernel/linux-mptcp.nix
··· 1 1 { stdenv, buildPackages, hostPlatform, fetchFromGitHub, perl, buildLinux, ... } @ args: 2 2 3 - import ./generic.nix (rec { 3 + buildLinux (rec { 4 4 mptcpVersion = "0.93"; 5 5 modDirVersion = "4.9.60"; 6 6 version = "${modDirVersion}-mptcp_v${mptcpVersion}"; 7 + # autoModules= true; 7 8 8 9 extraMeta = { 9 10 branch = "4.4"; ··· 43 44 TCP_CONG_BALIA m 44 45 45 46 '' + (args.extraConfig or ""); 46 - } // args // (args.argsOverride or {})) 47 + } // args)
+1 -1
pkgs/os-specific/linux/kernel/linux-rpi.nix
··· 4 4 modDirVersion = "4.9.59"; 5 5 tag = "1.20171029"; 6 6 in 7 - stdenv.lib.overrideDerivation (import ./generic.nix (args // rec { 7 + stdenv.lib.overrideDerivation (buildLinux (args // rec { 8 8 version = "${modDirVersion}-${tag}"; 9 9 inherit modDirVersion; 10 10
+1 -1
pkgs/os-specific/linux/kernel/linux-samus-4.12.nix
··· 1 1 { stdenv, buildPackages, hostPlatform, fetchFromGitHub, perl, buildLinux, ncurses, ... } @ args: 2 2 3 - import ./generic.nix (args // rec { 3 + buildLinux (args // rec { 4 4 version = "4.12.2"; 5 5 extraMeta.branch = "4.12-2"; 6 6
+1 -1
pkgs/os-specific/linux/kernel/linux-testing-bcachefs.nix
··· 1 1 { stdenv, buildPackages, hostPlatform, fetchgit, perl, buildLinux, ... } @ args: 2 2 3 - import ./generic.nix (args // rec { 3 + buildLinux (args // rec { 4 4 version = "4.11.2017.08.23"; 5 5 modDirVersion = "4.11.0"; 6 6 extraMeta.branch = "master";
+1 -1
pkgs/os-specific/linux/kernel/linux-testing.nix
··· 1 1 { stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, libelf, utillinux, ... } @ args: 2 2 3 - import ./generic.nix (args // rec { 3 + buildLinux (args // rec { 4 4 version = "4.15-rc9"; 5 5 modDirVersion = "4.15.0-rc9"; 6 6 extraMeta.branch = "4.15";
+27 -7
pkgs/os-specific/linux/kernel/manual-config.nix
··· 1 1 { buildPackages, runCommand, nettools, bc, perl, gmp, libmpc, mpfr, openssl 2 + , ncurses ? null 2 3 , libelf 3 4 , utillinux 4 5 , writeTextFile, ubootTools 5 - , hostPlatform 6 6 }: 7 7 8 8 let ··· 34 34 # Use defaultMeta // extraMeta 35 35 extraMeta ? {}, 36 36 # Whether to utilize the controversial import-from-derivation feature to parse the config 37 - allowImportFromDerivation ? false 37 + allowImportFromDerivation ? false, 38 + 39 + hostPlatform 38 40 }: 39 41 40 42 let ··· 86 88 inherit src; 87 89 88 90 preUnpack = '' 89 - mkdir build 90 - export buildRoot="$(pwd)/build" 91 91 ''; 92 92 93 93 patches = map (p: p.patch) kernelPatches; ··· 102 102 103 103 configurePhase = '' 104 104 runHook preConfigure 105 + 106 + mkdir build 107 + export buildRoot="$(pwd)/build" 108 + 109 + echo "manual-config configurePhase buildRoot=$buildRoot pwd=$PWD" 110 + 111 + if [[ -z "$buildRoot" || ! -d "$buildRoot" ]]; then 112 + echo "set $buildRoot to the build folder please" 113 + exit 1 114 + fi 115 + 116 + if [ -f "$buildRoot/.config" ]; then 117 + echo "Could not link $buildRoot/.config : file exists" 118 + exit 1 119 + fi 105 120 ln -sv ${configfile} $buildRoot/.config 121 + 122 + # reads the existing .config file and prompts the user for options in 123 + # the current kernel source that are not found in the file. 106 124 make $makeFlags "''${makeFlagsArray[@]}" oldconfig 107 125 runHook postConfigure 108 126 ··· 115 133 116 134 # Note: we can get rid of this once http://permalink.gmane.org/gmane.linux.kbuild.devel/13800 is merged. 117 135 buildFlagsArray+=("KBUILD_BUILD_TIMESTAMP=$(date -u -d @$SOURCE_DATE_EPOCH)") 136 + 137 + cd $buildRoot 118 138 ''; 119 139 120 140 buildFlags = [ ··· 136 156 137 157 postInstall = '' 138 158 mkdir -p $dev 139 - cp $buildRoot/vmlinux $dev/ 159 + cp vmlinux $dev/ 140 160 '' + (optionalString installsFirmware '' 141 161 mkdir -p $out/lib/firmware 142 162 '') + (if (platform ? kernelDTB && platform.kernelDTB) then '' ··· 151 171 unlink $out/lib/modules/${modDirVersion}/source 152 172 153 173 mkdir -p $dev/lib/modules/${modDirVersion}/build 154 - cp -dpR ../$sourceRoot $dev/lib/modules/${modDirVersion}/source 174 + cp -dpR .. $dev/lib/modules/${modDirVersion}/source 155 175 cd $dev/lib/modules/${modDirVersion}/source 156 176 157 177 cp $buildRoot/{.config,Module.symvers} $dev/lib/modules/${modDirVersion}/build ··· 170 190 # from drivers/ in the future; it adds 50M to keep all of its 171 191 # headers on 3.10 though. 172 192 173 - chmod u+w -R ../source 193 + chmod u+w -R .. 174 194 arch=$(cd $dev/lib/modules/${modDirVersion}/build/arch; ls) 175 195 176 196 # Remove unused arches
+3 -3
pkgs/os-specific/linux/kernel/update.sh
··· 50 50 # Rewrite the expression 51 51 sed -i -e '/version = /d' -e '/modDirVersion = /d' $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 52 52 if grep -q '^[0-9]\+.[0-9]\+$' <<< "$V"; then 53 - sed -i "\#import ./generic.nix (args // rec {#a \ modDirVersion = \"${V}.0\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 53 + sed -i "\#buildLinux (args // rec {#a \ modDirVersion = \"${V}.0\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 54 54 fi 55 - sed -i "\#import ./generic.nix (args // rec {#a \ version = \"$V\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 55 + sed -i "\#buildLinux (args // rec {#a \ version = \"$V\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 56 56 57 57 # Commit the changes 58 58 git add -u $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 59 59 git commit -m "kernel: $OLDVER -> $V" >/dev/null 2>&1 60 - 60 + 61 61 echo "Updated $OLDVER -> $V" 62 62 done
+1 -1
pkgs/top-level/all-packages.nix
··· 13197 13197 13198 13198 # A function to build a manually-configured kernel 13199 13199 linuxManualConfig = pkgs.buildLinux; 13200 - buildLinux = makeOverridable (callPackage ../os-specific/linux/kernel/manual-config.nix {}); 13200 + buildLinux = makeOverridable (callPackage ../os-specific/linux/kernel/generic.nix {}); 13201 13201 13202 13202 keyutils = callPackage ../os-specific/linux/keyutils { }; 13203 13203