2012-07-29 21:54:31 +02:00
|
|
|
{ stdenv, runCommand, nettools, perl, kmod, writeTextFile }:
|
2012-07-29 07:23:51 +02:00
|
|
|
|
|
|
|
with stdenv.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
# Function to parse the config file to get the features supported
|
|
|
|
readFeatures = config:
|
|
|
|
let
|
2012-07-29 21:54:31 +02:00
|
|
|
configAttrs = import "${runCommand "attrList.nix" {} ''
|
|
|
|
grep -E -v '(^#|^$)' < ${config} | \
|
|
|
|
sed 's/CONFIG_// ; s/=/ /' | \
|
|
|
|
awk \
|
|
|
|
'BEGIN { print "{" }
|
|
|
|
END { print "}" }
|
|
|
|
{ printf "\"%s\" = '"'''"'%s'"'''"';\n", $1, $2 }' > $out
|
|
|
|
''}";
|
2012-07-29 07:23:51 +02:00
|
|
|
getValue = option:
|
|
|
|
if hasAttr option configAttrs then getAttr option configAttrs else null;
|
|
|
|
|
|
|
|
isYes = option: (getValue option) == "y";
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
modular = isYes "MODULES";
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
2012-07-29 10:31:40 +02:00
|
|
|
{
|
|
|
|
# The kernel version
|
|
|
|
version,
|
|
|
|
# The version of the kernel module directory
|
|
|
|
modDirVersion ? version,
|
|
|
|
# The kernel source (tarball, git checkout, etc.)
|
|
|
|
src,
|
|
|
|
# Any patches
|
|
|
|
patches ? [],
|
|
|
|
# The kernel .config file
|
|
|
|
config,
|
|
|
|
# Manually specified features the kernel supports
|
2012-07-29 10:52:34 +02:00
|
|
|
# If unspecified, this will be autodetected from the .config
|
2012-07-29 19:26:39 +02:00
|
|
|
features ? optionalAttrs allowImportFromDerivation (readFeatures config),
|
|
|
|
# Whether to utilize the controversial import-from-derivation feature to parse the config
|
|
|
|
allowImportFromDerivation ? false
|
2012-07-29 10:31:40 +02:00
|
|
|
}:
|
|
|
|
|
2012-07-29 10:48:50 +02:00
|
|
|
let
|
|
|
|
commonMakeFlags = [
|
|
|
|
"O=../build"
|
|
|
|
"INSTALL_PATH=$(out)"
|
|
|
|
"INSTALLKERNEL=${installkernel}"
|
|
|
|
];
|
|
|
|
|
|
|
|
installkernel = writeTextFile { name = "installkernel"; executable=true; text = ''
|
|
|
|
#!/bin/sh
|
|
|
|
mkdir $4
|
|
|
|
mv -v $2 $4
|
|
|
|
mv -v $3 $4
|
|
|
|
'';};
|
|
|
|
in
|
2012-07-29 10:31:40 +02:00
|
|
|
|
2012-07-29 07:23:51 +02:00
|
|
|
stdenv.mkDerivation ({
|
|
|
|
name = "linux-${version}";
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit version modDirVersion features;
|
|
|
|
};
|
|
|
|
|
|
|
|
inherit patches src;
|
|
|
|
|
2012-07-29 09:49:52 +02:00
|
|
|
prePatch = ''
|
|
|
|
for mf in $(find -name Makefile -o -name Makefile.include); do
|
2012-07-29 07:23:51 +02:00
|
|
|
echo "stripping FHS paths in \`$mf'..."
|
2012-07-29 10:48:50 +02:00
|
|
|
sed -i "$mf" -e 's|/usr/bin/||g ; s|/bin/||g ; s|/sbin/||g'
|
2012-07-29 07:23:51 +02:00
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
2012-07-29 09:49:52 +02:00
|
|
|
mkdir ../build
|
|
|
|
make $makeFlags "''${makeFlagsArray[@]}" mrproper
|
|
|
|
ln -sv ${config} ../build/.config
|
|
|
|
make $makeFlags "''${makeFlagsArray[@]}" oldconfig
|
|
|
|
rm ../build/.config.old
|
2012-07-29 07:23:51 +02:00
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
2012-07-29 10:48:50 +02:00
|
|
|
buildNativeInputs = [ perl nettools kmod ];
|
2012-07-29 09:49:52 +02:00
|
|
|
|
|
|
|
makeFlags = commonMakeFlags;
|
2012-07-29 10:59:38 +02:00
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "The Linux kernel";
|
|
|
|
license = "GPLv2";
|
|
|
|
homepage = http://www.kernel.org/;
|
|
|
|
maintainers = [
|
|
|
|
maintainers.shlevy
|
|
|
|
];
|
|
|
|
platforms = lib.platforms.linux;
|
|
|
|
};
|
2012-07-29 10:52:34 +02:00
|
|
|
} // optionalAttrs (features ? modular && features.modular) {
|
2012-07-29 09:49:52 +02:00
|
|
|
makeFlags = commonMakeFlags ++ [
|
|
|
|
"MODLIB=\"$(out)/lib/modules/${modDirVersion}\""
|
|
|
|
];
|
2012-07-29 07:23:51 +02:00
|
|
|
|
|
|
|
postInstall = ''
|
2012-07-29 08:57:58 +02:00
|
|
|
make modules_install $makeFlags "''${makeFlagsArray[@]}" \
|
|
|
|
$installFlags "''${installFlagsArray[@]}"
|
2012-07-29 09:27:09 +02:00
|
|
|
rm -f $out/lib/modules/${modDirVersion}/{build,source}
|
|
|
|
cd ..
|
2012-07-29 09:49:52 +02:00
|
|
|
mv $sourceRoot $out/lib/modules/${modDirVersion}/source
|
|
|
|
mv build $out/lib/modules/${modDirVersion}/build
|
2012-07-29 10:56:56 +02:00
|
|
|
unlink $out/lib/modules/${modDirVersion}/build/source
|
|
|
|
ln -sv $out/lib/modules/${modDirVersion}/{,build/}source
|
2012-07-29 07:23:51 +02:00
|
|
|
'';
|
2012-07-29 10:23:28 +02:00
|
|
|
|
|
|
|
postFixup = ''
|
|
|
|
if [ -z "$dontStrip" ]; then
|
|
|
|
find $out -name "*.ko" -print0 | xargs -0 strip -S
|
|
|
|
fi
|
|
|
|
'';
|
2012-07-29 07:23:51 +02:00
|
|
|
})
|