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
|
|
|
|
|
2012-08-01 12:18:03 +02:00
|
|
|
# Function to parse the config file into a nix expression
|
|
|
|
readConfig = configFile:
|
2012-07-29 07:23:51 +02:00
|
|
|
let
|
2012-08-01 12:18:03 +02: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 21:54:31 +02:00
|
|
|
''}";
|
2012-07-29 07:23:51 +02:00
|
|
|
|
2012-08-01 12:18:03 +02: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 07:23:51 +02:00
|
|
|
|
2012-08-01 12:18:03 +02: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 07:23:51 +02:00
|
|
|
|
|
|
|
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
|
2012-08-02 05:02:17 +02:00
|
|
|
kernelPatches ? [],
|
2012-07-29 10:31:40 +02:00
|
|
|
# The kernel .config file
|
2012-08-01 12:18:03 +02:00
|
|
|
configfile,
|
|
|
|
# Manually specified nixexpr representing the config
|
2012-07-29 10:52:34 +02:00
|
|
|
# If unspecified, this will be autodetected from the .config
|
2012-08-01 12:18:03 +02:00
|
|
|
config ? optionalAttrs allowImportFromDerivation (readConfig configfile),
|
2012-07-29 19:26:39 +02:00
|
|
|
# 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
|
2012-08-01 20:15:26 +02:00
|
|
|
installkernel = name: writeTextFile { name = "installkernel"; executable=true; text = ''
|
2012-07-29 10:48:50 +02:00
|
|
|
#!/bin/sh
|
|
|
|
mkdir $4
|
2012-08-07 12:36:50 +02:00
|
|
|
cp -av $2 $4/${name}
|
|
|
|
cp -av $3 $4
|
2012-07-29 10:48:50 +02:00
|
|
|
'';};
|
2012-08-01 12:18:03 +02:00
|
|
|
|
|
|
|
isModular = config.isYes "MODULES";
|
|
|
|
|
|
|
|
installsFirmware = (config.isEnabled "FW_LOADER") &&
|
2012-08-01 17:21:32 +02:00
|
|
|
(isModular || (config.isDisabled "FIRMWARE_IN_KERNEL"));
|
2012-08-01 20:15:26 +02:00
|
|
|
|
|
|
|
commonMakeFlags = [
|
2012-08-12 03:02:09 +02:00
|
|
|
"O=$(buildRoot)"
|
2012-08-01 20:15:26 +02:00
|
|
|
"INSTALL_PATH=$(out)"
|
2012-08-07 12:36:50 +02:00
|
|
|
] ++ (optional isModular "INSTALL_MOD_PATH=$(out)")
|
2012-08-01 20:15:26 +02:00
|
|
|
++ optional installsFirmware "INSTALL_FW_PATH=$(out)/lib/firmware";
|
2012-07-29 10:48:50 +02:00
|
|
|
in
|
2012-07-29 10:31:40 +02:00
|
|
|
|
2012-08-12 03:21:06 +02:00
|
|
|
stdenv.mkDerivation {
|
2012-07-29 07:23:51 +02:00
|
|
|
name = "linux-${version}";
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
passthru = {
|
2012-08-12 03:02:09 +02:00
|
|
|
inherit version modDirVersion config kernelPatches src;
|
2012-08-12 03:21:06 +02:00
|
|
|
};
|
2012-08-12 03:02:09 +02:00
|
|
|
|
2012-08-12 03:21:06 +02:00
|
|
|
sourceRoot = stdenv.mkDerivation {
|
|
|
|
name = "linux-${version}-source";
|
2012-08-12 03:02:09 +02:00
|
|
|
|
2012-08-12 03:21:06 +02:00
|
|
|
inherit src;
|
2012-07-29 07:23:51 +02:00
|
|
|
|
2012-08-12 03:21:06 +02:00
|
|
|
patches = map (p: p.patch) kernelPatches;
|
2012-08-02 05:02:17 +02:00
|
|
|
|
2012-08-12 03:21:06 +02:00
|
|
|
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
|
2012-08-12 03:02:09 +02:00
|
|
|
|
2012-08-12 03:21:06 +02:00
|
|
|
prePatch = ''
|
|
|
|
for mf in $(find -name Makefile -o -name Makefile.include -o -name install.sh); do
|
|
|
|
echo "stripping FHS paths in \`$mf'..."
|
|
|
|
sed -i "$mf" -e 's|/usr/bin/||g ; s|/bin/||g ; s|/sbin/||g'
|
|
|
|
done
|
|
|
|
sed -i Makefile -e 's|= depmod|= ${kmod}/sbin/depmod|'
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
cd ..
|
|
|
|
mv $sourceRoot $out
|
|
|
|
'';
|
2012-08-12 03:02:09 +02:00
|
|
|
};
|
2012-07-29 07:23:51 +02:00
|
|
|
|
2012-08-12 03:02:09 +02:00
|
|
|
unpackPhase = ''
|
|
|
|
mkdir build
|
|
|
|
export buildRoot="$(pwd)/build"
|
2012-08-12 03:21:06 +02:00
|
|
|
ln -sv ${configfile} $buildRoot/.config
|
2012-08-12 03:02:09 +02:00
|
|
|
cd $sourceRoot
|
2012-07-29 07:23:51 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
2012-07-29 09:49:52 +02:00
|
|
|
make $makeFlags "''${makeFlagsArray[@]}" oldconfig
|
2012-07-29 07:23:51 +02:00
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
2012-08-07 12:36:50 +02:00
|
|
|
buildNativeInputs = [ perl nettools ];
|
2012-07-29 10:59:38 +02:00
|
|
|
|
2012-08-01 20:15:26 +02:00
|
|
|
makeFlags = commonMakeFlags ++ [
|
|
|
|
"INSTALLKERNEL=${installkernel stdenv.platform.kernelTarget}"
|
|
|
|
];
|
|
|
|
|
|
|
|
crossAttrs = {
|
|
|
|
makeFlags = commonMakeFlags ++ [
|
|
|
|
"INSTALLKERNEL=${installkernel stdenv.cross.platform.kernelTarget}"
|
|
|
|
];
|
|
|
|
};
|
2012-07-29 07:23:51 +02:00
|
|
|
|
2012-08-07 12:36:50 +02:00
|
|
|
postInstall = optionalString installsFirmware ''
|
2012-08-01 17:56:12 +02:00
|
|
|
mkdir -p $out/lib/firmware
|
|
|
|
'' + (if isModular then ''
|
2012-07-29 08:57:58 +02:00
|
|
|
make modules_install $makeFlags "''${makeFlagsArray[@]}" \
|
|
|
|
$installFlags "''${installFlagsArray[@]}"
|
2012-08-12 03:07:37 +02:00
|
|
|
rm -f $out/lib/modules/${modDirVersion}/build
|
2012-08-12 03:02:09 +02:00
|
|
|
mv $buildRoot $out/lib/modules/${modDirVersion}/build
|
2012-08-01 12:18:03 +02:00
|
|
|
'' else optionalString installsFirmware ''
|
|
|
|
make firmware_install $makeFlags "''${makeFlagsArray[@]}" \
|
|
|
|
$installFlags "''${installFlagsArray[@]}"
|
2012-08-01 17:56:12 +02:00
|
|
|
'');
|
2012-07-29 10:23:28 +02:00
|
|
|
|
2012-08-01 12:18:03 +02:00
|
|
|
postFixup = optionalString isModular ''
|
2012-07-29 10:23:28 +02:00
|
|
|
if [ -z "$dontStrip" ]; then
|
2012-08-02 05:32:02 +02:00
|
|
|
find $out -name "*.ko" -print0 | xargs -0 -r strip -S
|
2012-07-29 10:23:28 +02:00
|
|
|
fi
|
|
|
|
'';
|
2012-08-01 12:18:03 +02:00
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "The Linux kernel";
|
|
|
|
license = "GPLv2";
|
|
|
|
homepage = http://www.kernel.org/;
|
|
|
|
maintainers = [
|
|
|
|
maintainers.shlevy
|
|
|
|
];
|
|
|
|
platforms = lib.platforms.linux;
|
|
|
|
};
|
2012-08-12 03:21:06 +02:00
|
|
|
}
|