Simplified much more the expressions for cross building and multiplatform.

I introduce the new nixpkgs parameter "platform", defaulting to "pc",
which was before defined as an attribute of nixpkgs.

I made the crossSystem nixpkgs attribute set parameter contain its own 'platform'.

This allows cross-building a kernel for a given crossSystem.platform in a non-PC
platform.

The actual native platform can be taken from stdenv.platform, and this way we also
avoid the constant passing of 'platform' to packages for platform-dependant builds
(kernel, initrd, ...).

I will update nixos accordingly to these changes, for non-PC platforms to work.

I think we are gaining on flexibility and clearness. I could cross build succesfully
an ultrasparc kernel and a mipsel kernel on PC. But since this change, I should be able
to do this also in non-PC.

Before this change, there was no possibility of distinguishing the "target platform" or
the "native build platform" when cross building, being the single "platform" attribute
always interpreted as target platform.

The platform is a quite relevant attribute set, as it determines the linuxHeaders used
(in the case, by now the only one supported, of linux targets).

The platform attributes are quite linux centric still. Let's hope for more generality to come.

svn path=/nixpkgs/trunk/; revision=20273
This commit is contained in:
Lluís Batlle i Rossell 2010-02-27 17:35:47 +00:00
parent fca769846a
commit 11aa65c28a
5 changed files with 437 additions and 408 deletions

View File

@ -12,15 +12,19 @@
# `contents = {object = ...; symlink = /init;}' is a typical
# argument.
{stdenv, perl, cpio, contents, platform}:
{stdenv, perl, cpio, contents, ubootChooser}:
let
inputsFun = ubootName : [perl cpio]
++ stdenv.lib.optional (ubootName != null) [ ubootChooser ubootName ];
makeUInitrdFun = ubootName : (ubootName != null);
in
stdenv.mkDerivation {
name = "initrd";
builder = ./make-initrd.sh;
buildInputs = [perl cpio]
++ stdenv.lib.optional (platform.uboot != null) [ platform.uboot ];
buildNativeInputs = inputsFun stdenv.platform.uboot;
makeUInitrd = if (platform.uboot != null) then true else false;
makeUInitrd = makeUInitrdFun stdenv.platform.uboot;
# !!! should use XML.
objects = map (x: x.object) contents;
@ -31,4 +35,9 @@ stdenv.mkDerivation {
exportReferencesGraph =
map (x: [("closure-" + baseNameOf x.symlink) x.object]) contents;
pathsFromGraph = ./paths-from-graph.pl;
crossAttrs = {
buildNativeInputs = inputsFun stdenv.cross.platform.uboot;
makeUInitrd = makeUInitrdFun stdenv.cross.platform.uboot;
};
}

View File

@ -1,19 +1,8 @@
args @ { stdenv, fetchurl, platform, userModeLinux ? false, extraConfig ? ""
args @ { stdenv, fetchurl, userModeLinux ? false, extraConfig ? ""
, ... }:
import ./generic.nix (
rec {
version = "2.6.32.9";
src = fetchurl {
url = "mirror://kernel/linux/kernel/v2.6/linux-${version}.tar.bz2";
sha256 = "1g6hs7j5kmifb3phbnckdmrnxd0cpqrijnnbry86z26npsh9my7l";
};
features.iwlwifi = true;
config =
let
configWithPlatform = kernelPlatform :
''
# Don't include any debug features.
DEBUG_KERNEL n
@ -202,9 +191,31 @@ import ./generic.nix (
X86_CHECK_BIOS_CORRUPTION y
X86_MCE y
${if platform ? kernelExtraConfig then platform.kernelExtraConfig else ""}
${if kernelPlatform ? kernelExtraConfig then kernelPlatform.kernelExtraConfig else ""}
${extraConfig}
'';
in
import ./generic.nix (
rec {
version = "2.6.32.9";
src = fetchurl {
url = "mirror://kernel/linux/kernel/v2.6/linux-${version}.tar.bz2";
sha256 = "1g6hs7j5kmifb3phbnckdmrnxd0cpqrijnnbry86z26npsh9my7l";
};
config = configWithPlatform stdenv.platform;
platform = stdenv.platform;
crossAttrs = {
config = configWithPlatform stdenv.cross.platform;
platform = stdenv.cross.platform;
};
features.iwlwifi = true;
}
// removeAttrs args ["extraConfig"]

View File

@ -1,19 +1,8 @@
args @ { stdenv, fetchurl, platform, userModeLinux ? false, extraConfig ? ""
args @ { stdenv, fetchurl, userModeLinux ? false, extraConfig ? ""
, ... }:
import ./generic.nix (
rec {
version = "2.6.33";
src = fetchurl {
url = "mirror://kernel/linux/kernel/v2.6/linux-${version}.tar.bz2";
sha256 = "1inmam21w13nyf5imgdb5palhiap41zcxf9k32i4ck1w7gg3gqk3";
};
features.iwlwifi = true;
config =
let
configWithPlatform = kernelPlatform :
''
# Don't include any debug features.
DEBUG_KERNEL n
@ -200,9 +189,31 @@ import ./generic.nix (
X86_CHECK_BIOS_CORRUPTION y
X86_MCE y
${if platform ? kernelExtraConfig then platform.kernelExtraConfig else ""}
${if kernelPlatform ? kernelExtraConfig then kernelPlatform.kernelExtraConfig else ""}
${extraConfig}
'';
in
import ./generic.nix (
rec {
version = "2.6.33";
src = fetchurl {
url = "mirror://kernel/linux/kernel/v2.6/linux-${version}.tar.bz2";
sha256 = "1inmam21w13nyf5imgdb5palhiap41zcxf9k32i4ck1w7gg3gqk3";
};
config = configWithPlatform stdenv.platform;
platform = stdenv.platform;
crossAttrs = {
config = configWithPlatform stdenv.cross.platform;
platform = stdenv.cross.platform;
};
features.iwlwifi = true;
}
// removeAttrs args ["extraConfig"]

View File

@ -35,6 +35,7 @@
config ? null
, crossSystem ? null
, platform ? (import ./platforms.nix).pc
}:
@ -180,7 +181,7 @@ let
allPackages = args: import ./all-packages.nix ({ inherit config; } // args);
};
defaultStdenv = allStdenvs.stdenv;
defaultStdenv = allStdenvs.stdenv // { inherit platform; };
stdenvCross = makeStdenvCross defaultStdenv crossSystem (binutilsCross crossSystem)
(gccCrossStageFinal crossSystem);
@ -291,7 +292,7 @@ let
};
makeInitrd = {contents}: import ../build-support/kernel/make-initrd.nix {
inherit stdenv perl cpio contents platform;
inherit stdenv perl cpio contents ubootChooser;
};
makeWrapper = makeSetupHook ../build-support/make-wrapper/make-wrapper.sh;
@ -326,11 +327,7 @@ let
inherit pkgs lib;
};
platforms = import ./platforms.nix {
inherit system pkgs;
};
platform = platforms.pc;
platforms = import ./platforms.nix;
### TOOLS
@ -5845,7 +5842,8 @@ let
linuxHeaders = linuxHeaders_2_6_28;
linuxHeadersCross = cross : forceBuildDrv (import ../os-specific/linux/kernel-headers/2.6.32.nix {
inherit stdenv fetchurl cross perl platform;
inherit stdenv fetchurl cross perl;
platform = cross.platform;
});
linuxHeaders_2_6_18 = import ../os-specific/linux/kernel-headers/2.6.18.5.nix {
@ -5903,12 +5901,11 @@ let
};
linux_2_6_32 = makeOverridable (import ../os-specific/linux/kernel/linux-2.6.32.nix) {
inherit fetchurl stdenv perl mktemp module_init_tools;
inherit fetchurl stdenv perl mktemp module_init_tools ubootChooser;
kernelPatches =
[ kernelPatches.fbcondecor_2_6_31
kernelPatches.sec_perm_2_6_24
];
inherit platform;
};
linux_2_6_32_zen4 = makeOverridable (import ../os-specific/linux/zen-kernel/2.6.32-zen4.nix) {
@ -5928,12 +5925,11 @@ let
};
linux_2_6_33 = makeOverridable (import ../os-specific/linux/kernel/linux-2.6.33.nix) {
inherit fetchurl stdenv perl mktemp module_init_tools;
inherit fetchurl stdenv perl mktemp module_init_tools ubootChooser;
kernelPatches =
[ kernelPatches.fbcondecor_2_6_33
kernelPatches.sec_perm_2_6_24
];
inherit platform;
};
/* Linux kernel modules are inherently tied to a specific kernel. So
@ -6347,7 +6343,11 @@ let
inherit (xlibs) libX11 xproto;
};*/
uboot = makeOverridable (import ../misc/uboot) {
ubootChooser = name : if (name == "upstream") then ubootUpstream
else if (name == "sheevaplug") then ubootSheevaplug
else throw "Unknown uboot";
ubootUpstream = makeOverridable (import ../misc/uboot) {
inherit fetchurl stdenv unzip platform;
};

View File

@ -1,7 +1,5 @@
{ system, pkgs}:
with pkgs;
rec {
pc = assert system == "i686-linux" || system == "x86_64-linux"; {
pc = {
name = "pc";
uboot = null;
kernelBaseConfig = "defconfig";
@ -60,7 +58,7 @@ rec {
IP_PNP y
'';
kernelTarget = "uImage";
uboot = ubootSheevaplug;
uboot = "sheevaplug";
# Only for uboot = uboot :
ubootConfig = "sheevaplug_config";
};
@ -133,7 +131,7 @@ rec {
integratorCPuboot = integratorCP // {
name = "integratorCPuboot";
kernelTarget = "uImage";
uboot = uboot;
uboot = "upstream";
ubootConfig = "integratorcp_config";
};
}