From 29b84841d2a83a846a27ab2cea03fc84eec57e51 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Wed, 18 Jul 2018 13:24:36 +0300 Subject: [PATCH] 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. --- pkgs/os-specific/linux/kernel/manual-config.nix | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix index 5d08ab05d97f..80721c4b401d 100644 --- a/pkgs/os-specific/linux/kernel/manual-config.nix +++ b/pkgs/os-specific/linux/kernel/manual-config.nix @@ -1,4 +1,4 @@ -{ buildPackages, runCommand, nettools, bc, bison, flex, perl, gmp, libmpc, mpfr, openssl +{ buildPackages, runCommand, nettools, bc, bison, flex, perl, rsync, gmp, libmpc, mpfr, openssl , libelf , utillinux , writeTextFile @@ -164,8 +164,14 @@ let unlink $out/lib/modules/${modDirVersion}/build unlink $out/lib/modules/${modDirVersion}/source - mkdir -p $dev/lib/modules/${modDirVersion}/build - cp -dpR .. $dev/lib/modules/${modDirVersion}/source + mkdir -p $dev/lib/modules/${modDirVersion}/{build,source} + + # To save space, exclude a bunch of unneeded stuff when copying. + (cd .. && rsync --archive --prune-empty-dirs \ + --exclude='/build/' \ + --exclude='/Documentation/' \ + * $dev/lib/modules/${modDirVersion}/source/) + cd $dev/lib/modules/${modDirVersion}/source cp $buildRoot/{.config,Module.symvers} $dev/lib/modules/${modDirVersion}/build @@ -251,7 +257,7 @@ stdenv.mkDerivation ((drvAttrs config hostPlatform.platform kernelPatches config enableParallelBuilding = true; depsBuildBuild = [ buildPackages.stdenv.cc ]; - nativeBuildInputs = [ perl bc nettools openssl gmp libmpc mpfr ] + nativeBuildInputs = [ perl bc nettools openssl rsync gmp libmpc mpfr ] ++ optional (stdenv.hostPlatform.platform.kernelTarget == "uImage") buildPackages.ubootTools ++ optional (stdenv.lib.versionAtLeast version "4.14") libelf ++ optional (stdenv.lib.versionAtLeast version "4.15") utillinux