kernel: Reduce peak disk usage during build

Since commit f620b1b693ec25af, the build directory is located inside the
source directory. Thus, the `cp -dpR` copies gigabytes worth of .o files
only to be deleted later on when we trim all non-essential files from
`$dev/lib/modules/${modDirVersion}/source/` thus causing a significant
amount of wasted I/O and peak disk usage.

As `cp` doesn't come with a `--exclude` flag, use rsync. And throw out
the Documentation folder while at it.

+10 -4
+10 -4
pkgs/os-specific/linux/kernel/manual-config.nix
··· 1 - { buildPackages, runCommand, nettools, bc, bison, flex, perl, gmp, libmpc, mpfr, openssl 1 + { buildPackages, runCommand, nettools, bc, bison, flex, perl, rsync, gmp, libmpc, mpfr, openssl 2 2 , libelf 3 3 , utillinux 4 4 , writeTextFile ··· 164 164 unlink $out/lib/modules/${modDirVersion}/build 165 165 unlink $out/lib/modules/${modDirVersion}/source 166 166 167 - mkdir -p $dev/lib/modules/${modDirVersion}/build 168 - cp -dpR .. $dev/lib/modules/${modDirVersion}/source 167 + mkdir -p $dev/lib/modules/${modDirVersion}/{build,source} 168 + 169 + # To save space, exclude a bunch of unneeded stuff when copying. 170 + (cd .. && rsync --archive --prune-empty-dirs \ 171 + --exclude='/build/' \ 172 + --exclude='/Documentation/' \ 173 + * $dev/lib/modules/${modDirVersion}/source/) 174 + 169 175 cd $dev/lib/modules/${modDirVersion}/source 170 176 171 177 cp $buildRoot/{.config,Module.symvers} $dev/lib/modules/${modDirVersion}/build ··· 251 257 enableParallelBuilding = true; 252 258 253 259 depsBuildBuild = [ buildPackages.stdenv.cc ]; 254 - nativeBuildInputs = [ perl bc nettools openssl gmp libmpc mpfr ] 260 + nativeBuildInputs = [ perl bc nettools openssl rsync gmp libmpc mpfr ] 255 261 ++ optional (stdenv.hostPlatform.platform.kernelTarget == "uImage") buildPackages.ubootTools 256 262 ++ optional (stdenv.lib.versionAtLeast version "4.14") libelf 257 263 ++ optional (stdenv.lib.versionAtLeast version "4.15") utillinux