2012-07-29 09:48:50 +01:00
|
|
|
{ stdenv, runCommand, nettools, perl, kmod, writeTextFile }:
|
2012-07-29 06:23:51 +01:00
|
|
|
|
|
|
|
with stdenv.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
# Function to parse the config file to get the features supported
|
|
|
|
readFeatures = config:
|
|
|
|
let
|
|
|
|
# !!! Original causes recursion too deep, need to import from derivation
|
|
|
|
# linesWithComments = splitString "\n" (builtins.readFile config);
|
|
|
|
lines = import "${runCommand "lines.nix" {} ''
|
|
|
|
echo "[" >> $out
|
|
|
|
while read line; do
|
2012-07-29 08:09:44 +01:00
|
|
|
if [ -n "$line" ] && [ "#" != ''${line:0:1} ]; then
|
|
|
|
echo "'''" >> $out
|
|
|
|
echo $(echo $line | sed "s/'''/''''/g")"'''" >> $out
|
2012-07-29 06:23:51 +01:00
|
|
|
fi
|
|
|
|
done < ${config}
|
|
|
|
echo "]" >> $out
|
|
|
|
''}";
|
|
|
|
|
|
|
|
nvpairs = map (s: let split = splitString "=" s; fst = head split; in {
|
|
|
|
name = substring (stringLength "CONFIG_") (stringLength fst) fst;
|
|
|
|
value = head (tail split);
|
|
|
|
}) lines;
|
|
|
|
|
|
|
|
configAttrs = listToAttrs nvpairs;
|
|
|
|
|
|
|
|
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 09:31:40 +01: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 09:52:34 +01:00
|
|
|
# If unspecified, this will be autodetected from the .config
|
2012-07-29 09:31:40 +01:00
|
|
|
features ? readFeatures config
|
|
|
|
}:
|
|
|
|
|
2012-07-29 09:48:50 +01: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 09:31:40 +01:00
|
|
|
|
2012-07-29 06:23:51 +01:00
|
|
|
stdenv.mkDerivation ({
|
|
|
|
name = "linux-${version}";
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit version modDirVersion features;
|
|
|
|
};
|
|
|
|
|
|
|
|
inherit patches src;
|
|
|
|
|
2012-07-29 08:49:52 +01:00
|
|
|
prePatch = ''
|
|
|
|
for mf in $(find -name Makefile -o -name Makefile.include); do
|
2012-07-29 06:23:51 +01:00
|
|
|
echo "stripping FHS paths in \`$mf'..."
|
2012-07-29 09:48:50 +01:00
|
|
|
sed -i "$mf" -e 's|/usr/bin/||g ; s|/bin/||g ; s|/sbin/||g'
|
2012-07-29 06:23:51 +01:00
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
2012-07-29 08:49:52 +01:00
|
|
|
mkdir ../build
|
|
|
|
make $makeFlags "''${makeFlagsArray[@]}" mrproper
|
|
|
|
ln -sv ${config} ../build/.config
|
|
|
|
make $makeFlags "''${makeFlagsArray[@]}" oldconfig
|
|
|
|
rm ../build/.config.old
|
2012-07-29 06:23:51 +01:00
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
2012-07-29 09:48:50 +01:00
|
|
|
buildNativeInputs = [ perl nettools kmod ];
|
2012-07-29 08:49:52 +01:00
|
|
|
|
|
|
|
makeFlags = commonMakeFlags;
|
2012-07-29 09:52:34 +01:00
|
|
|
} // optionalAttrs (features ? modular && features.modular) {
|
2012-07-29 08:49:52 +01:00
|
|
|
makeFlags = commonMakeFlags ++ [
|
|
|
|
"MODLIB=\"$(out)/lib/modules/${modDirVersion}\""
|
|
|
|
];
|
2012-07-29 06:23:51 +01:00
|
|
|
|
|
|
|
postInstall = ''
|
2012-07-29 07:57:58 +01:00
|
|
|
make modules_install $makeFlags "''${makeFlagsArray[@]}" \
|
|
|
|
$installFlags "''${installFlagsArray[@]}"
|
2012-07-29 08:27:09 +01:00
|
|
|
rm -f $out/lib/modules/${modDirVersion}/{build,source}
|
|
|
|
cd ..
|
2012-07-29 08:49:52 +01:00
|
|
|
mv $sourceRoot $out/lib/modules/${modDirVersion}/source
|
|
|
|
mv build $out/lib/modules/${modDirVersion}/build
|
2012-07-29 06:23:51 +01:00
|
|
|
'';
|
2012-07-29 09:23:28 +01:00
|
|
|
|
|
|
|
postFixup = ''
|
|
|
|
if [ -z "$dontStrip" ]; then
|
|
|
|
find $out -name "*.ko" -print0 | xargs -0 strip -S
|
|
|
|
fi
|
|
|
|
'';
|
2012-07-29 06:23:51 +01:00
|
|
|
})
|