2012-07-29 20:54:31 +01:00
|
|
|
{ stdenv, runCommand, nettools, perl, kmod, writeTextFile }:
|
2012-07-29 06:23:51 +01:00
|
|
|
|
|
|
|
with stdenv.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2012-08-01 11:18:03 +01:00
|
|
|
# Function to parse the config file into a nix expression
|
|
|
|
readConfig = configFile:
|
2012-07-29 06:23:51 +01:00
|
|
|
let
|
2012-08-01 11:18:03 +01:00
|
|
|
configAttrs = import "${runCommand "config.nix" {} ''
|
|
|
|
(. ${configFile}
|
|
|
|
echo "{"
|
|
|
|
for var in `set`; do
|
|
|
|
if [[ "$var" =~ ^CONFIG_ ]]; then
|
|
|
|
IFS="="
|
|
|
|
set -- $var
|
|
|
|
echo "\"$1\" = \"''${*:2}\";"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "}") > $out
|
2012-07-29 20:54:31 +01:00
|
|
|
''}";
|
2012-07-29 06:23:51 +01:00
|
|
|
|
2012-08-01 11:18:03 +01:00
|
|
|
config = configAttrs // rec {
|
|
|
|
attrName = attr: "CONFIG_" + attr;
|
|
|
|
|
|
|
|
isSet = attr: hasAttr (attrName attr) config;
|
|
|
|
|
|
|
|
getValue = attr: if isSet attr then getAttr (attrName attr) config else null;
|
|
|
|
|
|
|
|
isYes = attr: (isSet attr) && ((getValue attr) == "y");
|
|
|
|
|
|
|
|
isNo = attr: (isSet attr) && ((getValue attr) == "n");
|
2012-07-29 06:23:51 +01:00
|
|
|
|
2012-08-01 11:18:03 +01:00
|
|
|
isModule = attr: (isSet attr) && ((getValue attr) == "m");
|
|
|
|
|
|
|
|
isEnabled = attr: (isModule attr) || (isYes attr);
|
|
|
|
|
|
|
|
isDisabled = attr: (!(isSet attr)) || (isNo attr);
|
|
|
|
};
|
|
|
|
in
|
|
|
|
config;
|
2012-07-29 06:23:51 +01:00
|
|
|
|
|
|
|
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
|
2012-08-01 11:18:03 +01:00
|
|
|
configfile,
|
|
|
|
# Manually specified nixexpr representing the config
|
2012-07-29 09:52:34 +01:00
|
|
|
# If unspecified, this will be autodetected from the .config
|
2012-08-01 11:18:03 +01:00
|
|
|
config ? optionalAttrs allowImportFromDerivation (readConfig configfile),
|
2012-07-29 18:26:39 +01:00
|
|
|
# Whether to utilize the controversial import-from-derivation feature to parse the config
|
|
|
|
allowImportFromDerivation ? false
|
2012-07-29 09:31:40 +01:00
|
|
|
}:
|
|
|
|
|
2012-07-29 09:48:50 +01:00
|
|
|
let
|
2012-08-01 19:15:26 +01:00
|
|
|
installkernel = name: writeTextFile { name = "installkernel"; executable=true; text = ''
|
2012-07-29 09:48:50 +01:00
|
|
|
#!/bin/sh
|
|
|
|
mkdir $4
|
2012-08-01 19:15:26 +01:00
|
|
|
mv -v $2 $4/${name}
|
2012-07-29 09:48:50 +01:00
|
|
|
mv -v $3 $4
|
|
|
|
'';};
|
2012-08-01 11:18:03 +01:00
|
|
|
|
|
|
|
isModular = config.isYes "MODULES";
|
|
|
|
|
|
|
|
installsFirmware = (config.isEnabled "FW_LOADER") &&
|
2012-08-01 16:21:32 +01:00
|
|
|
(isModular || (config.isDisabled "FIRMWARE_IN_KERNEL"));
|
2012-08-01 19:15:26 +01:00
|
|
|
|
|
|
|
commonMakeFlags = [
|
|
|
|
"O=../build"
|
|
|
|
"INSTALL_PATH=$(out)"
|
|
|
|
] ++ (optional isModular "MODLIB=$(out)/lib/modules/${modDirVersion}")
|
|
|
|
++ optional installsFirmware "INSTALL_FW_PATH=$(out)/lib/firmware";
|
2012-07-29 09:48:50 +01:00
|
|
|
in
|
2012-07-29 09:31:40 +01:00
|
|
|
|
2012-08-01 11:18:03 +01:00
|
|
|
stdenv.mkDerivation {
|
2012-07-29 06:23:51 +01:00
|
|
|
name = "linux-${version}";
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
passthru = {
|
2012-08-01 11:18:03 +01:00
|
|
|
inherit version modDirVersion config;
|
2012-07-29 06:23:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
inherit patches src;
|
|
|
|
|
2012-07-29 08:49:52 +01:00
|
|
|
prePatch = ''
|
2012-08-01 19:15:26 +01:00
|
|
|
for mf in $(find -name Makefile -o -name Makefile.include -o -name install.sh); 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
|
2012-08-01 11:18:03 +01:00
|
|
|
ln -sv ${configfile} ../build/.config
|
2012-07-29 08:49:52 +01:00
|
|
|
make $makeFlags "''${makeFlagsArray[@]}" oldconfig
|
|
|
|
rm ../build/.config.old
|
2012-07-29 06:23:51 +01:00
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
2012-08-01 11:18:03 +01:00
|
|
|
buildNativeInputs = [ perl nettools ] ++ optional isModular kmod;
|
2012-07-29 09:59:38 +01:00
|
|
|
|
2012-08-01 19:15:26 +01:00
|
|
|
makeFlags = commonMakeFlags ++ [
|
|
|
|
"INSTALLKERNEL=${installkernel stdenv.platform.kernelTarget}"
|
|
|
|
];
|
|
|
|
|
|
|
|
crossAttrs = {
|
|
|
|
makeFlags = commonMakeFlags ++ [
|
|
|
|
"INSTALLKERNEL=${installkernel stdenv.cross.platform.kernelTarget}"
|
|
|
|
];
|
|
|
|
};
|
2012-07-29 06:23:51 +01:00
|
|
|
|
2012-08-01 16:56:12 +01:00
|
|
|
postInstall = stdenv.lib.optionalString installsFirmware ''
|
|
|
|
mkdir -p $out/lib/firmware
|
|
|
|
'' + (if isModular then ''
|
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 09:56:56 +01:00
|
|
|
unlink $out/lib/modules/${modDirVersion}/build/source
|
|
|
|
ln -sv $out/lib/modules/${modDirVersion}/{,build/}source
|
2012-08-01 11:18:03 +01:00
|
|
|
'' else optionalString installsFirmware ''
|
|
|
|
make firmware_install $makeFlags "''${makeFlagsArray[@]}" \
|
|
|
|
$installFlags "''${installFlagsArray[@]}"
|
2012-08-01 16:56:12 +01:00
|
|
|
'');
|
2012-07-29 09:23:28 +01:00
|
|
|
|
2012-08-01 11:18:03 +01:00
|
|
|
postFixup = optionalString isModular ''
|
2012-07-29 09:23:28 +01:00
|
|
|
if [ -z "$dontStrip" ]; then
|
|
|
|
find $out -name "*.ko" -print0 | xargs -0 strip -S
|
|
|
|
fi
|
|
|
|
'';
|
2012-08-01 11:18:03 +01:00
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "The Linux kernel";
|
|
|
|
license = "GPLv2";
|
|
|
|
homepage = http://www.kernel.org/;
|
|
|
|
maintainers = [
|
|
|
|
maintainers.shlevy
|
|
|
|
];
|
|
|
|
platforms = lib.platforms.linux;
|
|
|
|
};
|
|
|
|
}
|