Skip to content

Commit

Permalink
linuxManualConfig: unpack directly into $dev
Browse files Browse the repository at this point in the history
linux is unusual in that we include its sources in an output.  There's
no point unpacking into /build when we're going to copy the sources
into $dev later.  Let's unpack directly into the final destination of
the code, and save copying a whole kernel source tree (often across
filesystems!).

This also means that Kbuild knows the location of the sources, which
will allow us to install the GDB scripts — some scripts are generated,
and some are not, so the generated ones end up in the build directory,
accompanied by symlinks to the non-generated ones in the source
directory.
  • Loading branch information
alyssais committed Mar 19, 2023
1 parent d75cff2 commit 7de3f08
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions pkgs/os-specific/linux/kernel/manual-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ let
hash = "sha256-bBOyJcP6jUvozFJU0SPTOf3cmnTQ6ZZ4PlHjiniHXLU=";
});

preUnpack = ''
# The same preUnpack is used to build the configfile,
# which does not have $dev.
if [ -n "$dev" ]; then
mkdir -p $dev/lib/modules/${modDirVersion}
cd $dev/lib/modules/${modDirVersion}
fi
'';

postUnpack = ''
mv -Tv "$sourceRoot" source 2>/dev/null || :
export sourceRoot=$PWD/source
'';

postPatch = ''
sed -i Makefile -e 's|= depmod|= ${buildPackages.kmod}/bin/depmod|'
Expand Down Expand Up @@ -185,6 +199,12 @@ let

buildFlags = [
"KBUILD_BUILD_VERSION=1-NixOS"

# Set by default in the kernel since a73619a845d5,
# replicated here to apply to older versions.
# Makes __FILE__ relative to the build directory.
"KCPPFLAGS=-fmacro-prefix-map=$(sourceRoot)/="

kernelConf.target
"vmlinux" # for "perf" and things like that
] ++ optional isModular "modules"
Expand Down Expand Up @@ -261,7 +281,6 @@ let
];

postInstall = optionalString isModular ''
mkdir -p $dev
cp vmlinux $dev/
if [ -z "''${dontStrip-}" ]; then
installFlagsArray+=("INSTALL_MOD_STRIP=1")
Expand All @@ -271,12 +290,7 @@ let
unlink $out/lib/modules/${modDirVersion}/build
unlink $out/lib/modules/${modDirVersion}/source
mkdir -p $dev/lib/modules/${modDirVersion}/{build,source}
# To save space, exclude a bunch of unneeded stuff when copying.
(cd "$NIX_BUILD_TOP" && cd "$sourceRoot" &&
rsync --archive --prune-empty-dirs \
* $dev/lib/modules/${modDirVersion}/source/)
mkdir $dev/lib/modules/${modDirVersion}/build
cd $dev/lib/modules/${modDirVersion}/source
Expand Down

0 comments on commit 7de3f08

Please sign in to comment.