default.nix (3117B)
1 { stdenv 2 , buildPackages 3 , runCommand 4 , writeText 5 , lib 6 7 , config 8 , src 9 , extraPatchPhase ? "echo" 10 } : 11 let 12 writeConfig = import ./write-kconfig.nix { inherit lib writeText; }; 13 kconfigFile = writeConfig "kconfig" config; 14 inherit lib; in 15 stdenv.mkDerivation rec { 16 name = "kernel"; 17 inherit src extraPatchPhase; 18 hardeningDisable = ["all"]; 19 nativeBuildInputs = [buildPackages.stdenv.cc] ++ 20 (with buildPackages.pkgs; [ 21 rsync bc bison flex pkgconfig 22 openssl ncurses.all perl 23 ]); 24 CC = "${stdenv.cc.bintools.targetPrefix}gcc"; 25 HOSTCC = with buildPackages.pkgs; 26 "gcc -I${openssl}/include -I${ncurses}/include"; 27 HOST_EXTRACFLAGS = with buildPackages.pkgs; 28 "-I${openssl.dev}/include -L${openssl.out}/lib -L${ncurses.out}/lib"; 29 PKG_CONFIG_PATH = "./pkgconfig"; 30 CROSS_COMPILE = stdenv.cc.bintools.targetPrefix; 31 ARCH = "mips"; # kernel uses "mips" here for both mips and mipsel 32 KBUILD_BUILD_HOST = "liminix.builder"; 33 34 dontStrip = true; 35 dontPatchELF = true; 36 outputs = ["out" "headers" "modulesupport"]; 37 phases = [ 38 "unpackPhase" 39 "butcherPkgconfig" 40 "extraPatchPhase" 41 "patchPhase" 42 "patchScripts" 43 "configurePhase" 44 "checkConfigurationPhase" 45 "buildPhase" 46 "installPhase" 47 ]; 48 49 patches = [ 50 ./cmdline-cookie.patch 51 ]; 52 53 # this is here to work around what I think is a bug in nixpkgs 54 # packaging of ncurses: it installs pkg-config data files which 55 # don't produce any -L options when queried with "pkg-config --lib 56 # ncurses". For a regular build you'll never even notice, this only 57 # becomes an issue if you do a nix-shell in this derivation and 58 # expect "make nconfig" to work. 59 butcherPkgconfig = '' 60 cp -r ${buildPackages.pkgs.ncurses.dev}/lib/pkgconfig . 61 chmod +w pkgconfig pkgconfig/*.pc 62 for i in pkgconfig/*.pc; do test -f $i && sed -i 's/^Libs:/Libs: -L''${libdir} /' $i;done 63 ''; 64 65 patchScripts = '' 66 # Make kexec pass dtb in register when invoking new kernel. The 67 # code to do this is already present, but bracketed by UHI_BOOT 68 # which we can't enable. 69 sed -i arch/mips/kernel/machine_kexec.c -e 's/CONFIG_UHI_BOOT/CONFIG_MIPS/g' 70 71 patchShebangs scripts/ 72 ''; 73 74 configurePhase = '' 75 export KBUILD_OUTPUT=`pwd` 76 cp ${kconfigFile} .config 77 cp ${kconfigFile} .config.orig 78 make V=1 olddefconfig 79 ''; 80 81 checkConfigurationPhase = '' 82 echo Checking required config items: 83 if comm -2 -3 <(grep 'CONFIG' ${kconfigFile} |sort) <(grep 'CONFIG' .config|sort) |grep '.' ; then 84 echo -e "^^^ Some configuration lost :-(\nPerhaps you have mutually incompatible settings, or have disabled options on which these depend.\n" 85 exit 0 86 fi 87 echo "OK" 88 ''; 89 90 buildPhase = '' 91 make vmlinux modules_prepare 92 ''; 93 94 installPhase = '' 95 ${CROSS_COMPILE}strip -d vmlinux 96 cp vmlinux $out 97 mkdir -p $headers 98 cp -a include .config $headers/ 99 mkdir -p $modulesupport 100 cp modules.* $modulesupport 101 make clean modules_prepare 102 cp -a . $modulesupport 103 ''; 104 105 }