2005-02-21 21:42:07 +01:00
|
|
|
# This file constructs the standard build environment for the
|
|
|
|
# Linux/i686 platform. It's completely pure; that is, it relies on no
|
|
|
|
# external (non-Nix) tools, such as /usr/bin/gcc, and it contains a C
|
|
|
|
# compiler and linker that do not search in default locations,
|
|
|
|
# ensuring purity of components produced by it.
|
|
|
|
|
2008-05-19 17:12:03 +02:00
|
|
|
# The function defaults are for easy testing.
|
2011-12-14 15:31:56 +01:00
|
|
|
{ system ? builtins.currentSystem
|
2011-12-12 15:02:12 +01:00
|
|
|
, allPackages ? import ../../top-level/all-packages.nix
|
2014-09-11 00:24:03 +02:00
|
|
|
, platform ? null, config ? {}, lib ? (import ../../../lib) }:
|
2005-02-21 21:42:07 +01:00
|
|
|
|
2004-11-04 13:19:32 +01:00
|
|
|
rec {
|
2004-10-19 17:16:14 +02:00
|
|
|
|
2009-02-01 22:44:56 +01:00
|
|
|
bootstrapFiles =
|
2014-04-20 01:27:15 +02:00
|
|
|
if system == "i686-linux" then import ./bootstrap/i686.nix
|
|
|
|
else if system == "x86_64-linux" then import ./bootstrap/x86_64.nix
|
|
|
|
else if system == "armv5tel-linux" then import ./bootstrap/armv5tel.nix
|
|
|
|
else if system == "armv6l-linux" then import ./bootstrap/armv6l.nix
|
|
|
|
else if system == "armv7l-linux" then import ./bootstrap/armv6l.nix
|
|
|
|
else if system == "mips64el-linux" then import ./bootstrap/loongson2f.nix
|
2006-10-24 22:57:06 +02:00
|
|
|
else abort "unsupported platform for the pure Linux stdenv";
|
2006-08-23 18:18:02 +02:00
|
|
|
|
|
|
|
|
2009-03-25 18:34:38 +01:00
|
|
|
commonPreHook =
|
|
|
|
''
|
|
|
|
export NIX_ENFORCE_PURITY=1
|
|
|
|
${if system == "x86_64-linux" then "NIX_LIB64_IN_SELF_RPATH=1" else ""}
|
2012-01-21 01:34:51 +01:00
|
|
|
${if system == "mips64el-linux" then "NIX_LIB32_IN_SELF_RPATH=1" else ""}
|
2009-03-25 18:34:38 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
|
2005-02-21 21:42:07 +01:00
|
|
|
# The bootstrap process proceeds in several steps.
|
|
|
|
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2014-08-23 21:26:37 +02:00
|
|
|
# Create a standard environment by downloading pre-built binaries of
|
|
|
|
# coreutils, GCC, etc.
|
2005-02-22 10:55:03 +01:00
|
|
|
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2009-02-01 22:44:56 +01:00
|
|
|
# Download and unpack the bootstrap tools (coreutils, GCC, Glibc, ...).
|
|
|
|
bootstrapTools = derivation {
|
|
|
|
name = "bootstrap-tools";
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2009-02-01 22:44:56 +01:00
|
|
|
builder = bootstrapFiles.sh;
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2012-01-19 16:56:17 +01:00
|
|
|
args =
|
2014-06-27 11:15:28 +02:00
|
|
|
if system == "armv5tel-linux" || system == "armv6l-linux"
|
2013-01-05 19:49:31 +01:00
|
|
|
|| system == "armv7l-linux"
|
2012-01-19 16:56:17 +01:00
|
|
|
then [ ./scripts/unpack-bootstrap-tools-arm.sh ]
|
|
|
|
else [ ./scripts/unpack-bootstrap-tools.sh ];
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2014-04-20 01:16:12 +02:00
|
|
|
# FIXME: get rid of curl.
|
2009-02-01 22:44:56 +01:00
|
|
|
inherit (bootstrapFiles) bzip2 mkdir curl cpio;
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2014-04-20 00:46:22 +02:00
|
|
|
tarball = import <nix/fetchurl.nix> {
|
2009-02-01 22:44:56 +01:00
|
|
|
inherit (bootstrapFiles.bootstrapTools) url sha256;
|
|
|
|
};
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2006-10-24 22:57:06 +02:00
|
|
|
inherit system;
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2009-02-01 22:44:56 +01:00
|
|
|
# Needed by the GCC wrapper.
|
|
|
|
langC = true;
|
|
|
|
langCC = true;
|
2004-11-04 13:19:32 +01:00
|
|
|
};
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2004-11-04 13:19:32 +01:00
|
|
|
|
2009-02-01 22:44:56 +01:00
|
|
|
# This function builds the various standard environments used during
|
2014-08-23 21:26:37 +02:00
|
|
|
# the bootstrap. In all stages, we build an stdenv and the package
|
|
|
|
# set that can be built with that stdenv.
|
|
|
|
stageFun =
|
2014-09-11 01:18:14 +02:00
|
|
|
{gccPlain, glibc, binutils, coreutils, name, overrides ? (pkgs: {}), extraBuildInputs ? []}:
|
2004-11-04 13:19:32 +01:00
|
|
|
|
2014-08-23 21:26:37 +02:00
|
|
|
let
|
2014-08-24 18:08:23 +02:00
|
|
|
|
|
|
|
thisStdenv = import ../generic {
|
2014-09-14 19:37:32 +02:00
|
|
|
inherit system config extraBuildInputs;
|
2014-08-24 18:08:23 +02:00
|
|
|
name = "stdenv-linux-boot";
|
|
|
|
preHook =
|
|
|
|
''
|
|
|
|
# Don't patch #!/interpreter because it leads to retained
|
|
|
|
# dependencies on the bootstrapTools in the final stdenv.
|
|
|
|
dontPatchShebangs=1
|
|
|
|
${commonPreHook}
|
|
|
|
'';
|
|
|
|
shell = "${bootstrapTools}/bin/sh";
|
2014-09-14 19:32:58 +02:00
|
|
|
initialPath = [bootstrapTools];
|
2014-08-24 18:08:23 +02:00
|
|
|
fetchurlBoot = import ../../build-support/fetchurl {
|
|
|
|
stdenv = stage0.stdenv;
|
|
|
|
curl = bootstrapTools;
|
|
|
|
};
|
2014-09-11 01:18:14 +02:00
|
|
|
|
|
|
|
gcc = if isNull gccPlain
|
|
|
|
then "/no-such-path"
|
|
|
|
else lib.makeOverridable (import ../../build-support/gcc-wrapper) {
|
|
|
|
nativeTools = false;
|
|
|
|
nativeLibc = false;
|
|
|
|
gcc = gccPlain;
|
|
|
|
libc = glibc;
|
|
|
|
inherit binutils coreutils;
|
|
|
|
name = name;
|
|
|
|
stdenv = stage0.stdenv;
|
|
|
|
};
|
|
|
|
|
|
|
|
extraAttrs = {
|
|
|
|
# Having the proper 'platform' in all the stdenvs allows getting proper
|
|
|
|
# linuxHeaders for example.
|
|
|
|
inherit platform;
|
|
|
|
|
|
|
|
# stdenv.glibc is used by GCC build to figure out the system-level
|
|
|
|
# /usr/include directory.
|
|
|
|
inherit glibc;
|
|
|
|
};
|
2014-08-24 18:08:23 +02:00
|
|
|
overrides = pkgs: (overrides pkgs) // { fetchurl = thisStdenv.fetchurlBoot; };
|
2014-08-23 20:34:01 +02:00
|
|
|
};
|
2004-11-04 13:19:32 +01:00
|
|
|
|
2014-08-24 18:08:23 +02:00
|
|
|
thisPkgs = allPackages {
|
|
|
|
inherit system platform;
|
|
|
|
bootStdenv = thisStdenv;
|
|
|
|
};
|
2009-02-01 22:44:56 +01:00
|
|
|
|
2014-08-23 21:26:37 +02:00
|
|
|
in { stdenv = thisStdenv; pkgs = thisPkgs; };
|
2009-02-01 22:44:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Build a dummy stdenv with no GCC or working fetchurl. This is
|
|
|
|
# because we need a stdenv to build the GCC wrapper and fetchurl.
|
2014-08-23 21:26:37 +02:00
|
|
|
stage0 = stageFun {
|
2014-09-11 01:18:14 +02:00
|
|
|
gccPlain = null;
|
|
|
|
glibc = null;
|
|
|
|
binutils = null;
|
|
|
|
coreutils = null;
|
|
|
|
name = null;
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2014-08-23 21:26:37 +02:00
|
|
|
overrides = pkgs: {
|
|
|
|
# The Glibc include directory cannot have the same prefix as the
|
|
|
|
# GCC include directory, since GCC gets confused otherwise (it
|
|
|
|
# will search the Glibc headers before the GCC headers). So
|
|
|
|
# create a dummy Glibc here, which will be used in the stdenv of
|
|
|
|
# stage1.
|
|
|
|
glibc = stage0.stdenv.mkDerivation {
|
|
|
|
name = "bootstrap-glibc";
|
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out
|
|
|
|
ln -s ${bootstrapTools}/lib $out/lib
|
|
|
|
ln -s ${bootstrapTools}/include-glibc $out/include
|
|
|
|
'';
|
|
|
|
};
|
2004-11-04 13:19:32 +01:00
|
|
|
};
|
2009-02-01 22:44:56 +01:00
|
|
|
};
|
2005-02-21 21:42:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Create the first "real" standard environment. This one consists
|
2009-02-01 22:44:56 +01:00
|
|
|
# of bootstrap tools only, and a minimal Glibc to keep the GCC
|
|
|
|
# configure script happy.
|
2014-08-24 15:55:14 +02:00
|
|
|
#
|
|
|
|
# For clarity, we only use the previous stage when specifying these
|
|
|
|
# stages. So stageN should only ever have references for stage{N-1}.
|
|
|
|
#
|
|
|
|
# If we ever need to use a package from more than one stage back, we
|
|
|
|
# simply re-export those packages in the middle stage(s) using the
|
|
|
|
# overrides attribute and the inherit syntax.
|
2014-08-23 21:26:37 +02:00
|
|
|
stage1 = stageFun {
|
2014-09-11 01:18:14 +02:00
|
|
|
gccPlain = bootstrapTools;
|
|
|
|
inherit (stage0.pkgs) glibc;
|
|
|
|
binutils = bootstrapTools;
|
|
|
|
coreutils = bootstrapTools;
|
|
|
|
name = "bootstrap-gcc-wrapper";
|
|
|
|
|
2014-08-23 21:26:37 +02:00
|
|
|
# Rebuild binutils to use from stage2 onwards.
|
|
|
|
overrides = pkgs: {
|
|
|
|
binutils = pkgs.binutils.override { gold = false; };
|
2014-08-24 15:55:14 +02:00
|
|
|
inherit (stage0.pkgs) glibc;
|
2014-09-11 01:18:14 +02:00
|
|
|
|
2014-09-04 16:17:39 +02:00
|
|
|
# A threaded perl build needs glibc/libpthread_nonshared.a,
|
|
|
|
# which is not included in bootstrapTools, so disable threading.
|
|
|
|
# This is not an issue for the final stdenv, because this perl
|
|
|
|
# won't be included in the final stdenv and won't be exported to
|
|
|
|
# top-level pkgs as an override either.
|
|
|
|
perl = pkgs.perl.override { enableThreading = false; };
|
2010-01-19 12:25:33 +01:00
|
|
|
};
|
2005-02-21 21:42:07 +01:00
|
|
|
};
|
|
|
|
|
2014-01-07 17:46:47 +01:00
|
|
|
|
2014-08-23 21:26:37 +02:00
|
|
|
# 2nd stdenv that contains our own rebuilt binutils and is used for
|
|
|
|
# compiling our own Glibc.
|
|
|
|
stage2 = stageFun {
|
2014-09-11 01:18:14 +02:00
|
|
|
gccPlain = bootstrapTools;
|
|
|
|
inherit (stage1.pkgs) glibc;
|
|
|
|
binutils = stage1.pkgs.binutils;
|
|
|
|
coreutils = bootstrapTools;
|
|
|
|
name = "bootstrap-gcc-wrapper";
|
|
|
|
|
2011-12-14 15:31:56 +01:00
|
|
|
overrides = pkgs: {
|
2014-08-24 15:55:14 +02:00
|
|
|
inherit (stage1.pkgs) perl binutils paxctl;
|
2014-08-23 21:26:37 +02:00
|
|
|
# This also contains the full, dynamically linked, final Glibc.
|
2011-12-14 15:31:56 +01:00
|
|
|
};
|
2010-08-25 15:22:48 +02:00
|
|
|
};
|
|
|
|
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2014-08-23 21:26:37 +02:00
|
|
|
# Construct a third stdenv identical to the 2nd, except that this
|
|
|
|
# one uses the rebuilt Glibc from stage2. It still uses the recent
|
|
|
|
# binutils and rest of the bootstrap tools, including GCC.
|
|
|
|
stage3 = stageFun {
|
2014-09-11 01:18:14 +02:00
|
|
|
gccPlain = bootstrapTools;
|
|
|
|
inherit (stage2.pkgs) glibc binutils;
|
|
|
|
coreutils = bootstrapTools;
|
|
|
|
name = "bootstrap-gcc-wrapper";
|
|
|
|
|
2011-12-14 15:31:56 +01:00
|
|
|
overrides = pkgs: {
|
2014-08-29 22:09:01 +02:00
|
|
|
inherit (stage2.pkgs) binutils glibc perl patchelf linuxHeaders;
|
2011-12-14 15:31:56 +01:00
|
|
|
# Link GCC statically against GMP etc. This makes sense because
|
|
|
|
# these builds of the libraries are only used by GCC, so it
|
|
|
|
# reduces the size of the stdenv closure.
|
|
|
|
gmp = pkgs.gmp.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
|
|
|
|
mpfr = pkgs.mpfr.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
|
|
|
|
mpc = pkgs.mpc.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
|
|
|
|
isl = pkgs.isl.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
|
|
|
|
cloog = pkgs.cloog.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
|
|
|
|
ppl = pkgs.ppl.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
|
2014-09-11 01:18:14 +02:00
|
|
|
gccPlain = pkgs.gcc.gcc;
|
2012-12-31 10:13:55 +01:00
|
|
|
};
|
2014-09-14 19:37:32 +02:00
|
|
|
extraBuildInputs = [ stage2.pkgs.patchelf stage2.pkgs.paxctl ];
|
2005-02-21 21:42:07 +01:00
|
|
|
};
|
|
|
|
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2014-08-23 21:26:37 +02:00
|
|
|
# Construct a fourth stdenv that uses the new GCC. But coreutils is
|
|
|
|
# still from the bootstrap tools.
|
|
|
|
stage4 = stageFun {
|
2014-09-11 01:18:14 +02:00
|
|
|
inherit (stage3.pkgs) gccPlain glibc binutils;
|
|
|
|
coreutils = bootstrapTools;
|
|
|
|
name = "";
|
|
|
|
|
2011-12-14 15:31:56 +01:00
|
|
|
overrides = pkgs: {
|
2014-09-11 01:10:49 +02:00
|
|
|
# Zlib has to be inherited and not rebuilt in this stage,
|
|
|
|
# because gcc (since JAR support) already depends on zlib, and
|
|
|
|
# then if we already have a zlib we want to use that for the
|
|
|
|
# other purposes (binutils and top-level pkgs) too.
|
2014-08-29 22:09:01 +02:00
|
|
|
inherit (stage3.pkgs) gettext gnum4 gmp perl glibc zlib linuxHeaders;
|
|
|
|
|
2014-09-11 01:18:14 +02:00
|
|
|
# Accidental historical garbage
|
|
|
|
#
|
|
|
|
# TODO(errge): this historical mistake accidentally disables
|
|
|
|
# tests for the production coreutils, we definitely don't want
|
|
|
|
# that, so fix this in another commit! (But will change drv and
|
|
|
|
# out hashes.)
|
|
|
|
coreutils = pkgs.coreutils.override { stdenv = stage4.stdenv.override { extraAttrs = { inherit platform; }; }; };
|
|
|
|
|
|
|
|
gcc = import ../../build-support/gcc-wrapper {
|
|
|
|
nativeTools = false;
|
|
|
|
nativeLibc = false;
|
2014-08-29 22:09:01 +02:00
|
|
|
gcc = stage4.stdenv.gcc.gcc;
|
|
|
|
libc = stage4.pkgs.glibc;
|
|
|
|
inherit (stage4.pkgs) binutils coreutils;
|
|
|
|
name = "";
|
2014-09-11 01:18:14 +02:00
|
|
|
stdenv = stage0.stdenv; # TODO(errge): legacy
|
|
|
|
shell = stage4.pkgs.bash + "/bin/bash";
|
|
|
|
};
|
2010-01-19 12:25:33 +01:00
|
|
|
};
|
2014-09-14 19:37:32 +02:00
|
|
|
extraBuildInputs = [ stage3.pkgs.patchelf stage3.pkgs.xz ];
|
2005-02-21 21:42:07 +01:00
|
|
|
};
|
|
|
|
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2014-08-23 21:26:37 +02:00
|
|
|
# Construct the final stdenv. It uses the Glibc and GCC, and adds
|
|
|
|
# in a new binutils that doesn't depend on bootstrap-tools, as well
|
|
|
|
# as dynamically linked versions of all other tools.
|
2009-02-01 22:44:56 +01:00
|
|
|
#
|
2014-08-23 21:26:37 +02:00
|
|
|
# When updating stdenvLinux, make sure that the result has no
|
|
|
|
# dependency (`nix-store -qR') on bootstrapTools or the first
|
|
|
|
# binutils built.
|
2010-08-06 12:34:34 +02:00
|
|
|
stdenvLinux = import ../generic rec {
|
2012-12-28 16:36:09 +01:00
|
|
|
inherit system config;
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2014-01-07 13:57:42 +01:00
|
|
|
preHook =
|
|
|
|
''
|
|
|
|
# Make "strip" produce deterministic output, by setting
|
|
|
|
# timestamps etc. to a fixed value.
|
|
|
|
commonStripFlags="--enable-deterministic-archives"
|
|
|
|
${commonPreHook}
|
|
|
|
'';
|
2012-12-28 16:41:56 +01:00
|
|
|
|
|
|
|
initialPath =
|
2014-09-08 18:24:58 +02:00
|
|
|
((import ../common-path.nix) {pkgs = stage4.pkgs;});
|
2014-06-27 11:15:28 +02:00
|
|
|
|
2014-09-08 18:24:58 +02:00
|
|
|
extraBuildInputs = [ stage4.pkgs.patchelf stage4.pkgs.paxctl ];
|
2009-11-15 17:48:36 +01:00
|
|
|
|
2014-08-29 22:09:01 +02:00
|
|
|
gcc = stage4.pkgs.gcc;
|
2005-02-21 21:42:07 +01:00
|
|
|
|
2014-08-29 22:09:01 +02:00
|
|
|
shell = gcc.shell;
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2014-08-25 09:35:06 +02:00
|
|
|
inherit (stage4.stdenv) fetchurlBoot;
|
2012-12-28 16:41:56 +01:00
|
|
|
|
2006-02-09 18:04:18 +01:00
|
|
|
extraAttrs = {
|
2014-08-23 21:26:37 +02:00
|
|
|
inherit (stage4.pkgs) glibc;
|
2012-12-30 12:29:02 +01:00
|
|
|
inherit platform bootstrapTools;
|
2014-08-23 21:26:37 +02:00
|
|
|
shellPackage = stage4.pkgs.bash;
|
2010-08-06 12:34:34 +02:00
|
|
|
};
|
|
|
|
|
2014-08-29 22:09:01 +02:00
|
|
|
allowedRequisites = with stage4.pkgs;
|
|
|
|
[ gzip bzip2 xz bash binutils coreutils diffutils findutils gawk
|
|
|
|
glibc gnumake gnused gnutar gnugrep gnupatch patchelf attr acl
|
|
|
|
paxctl zlib pcre linuxHeaders ed gcc gcc.gcc libsigsegv ];
|
|
|
|
|
2011-12-14 15:31:56 +01:00
|
|
|
overrides = pkgs: {
|
2010-08-06 12:34:34 +02:00
|
|
|
inherit gcc;
|
2014-08-23 21:26:37 +02:00
|
|
|
inherit (stage4.pkgs)
|
2014-08-24 15:55:14 +02:00
|
|
|
gzip bzip2 xz bash binutils coreutils diffutils findutils gawk
|
|
|
|
glibc gnumake gnused gnutar gnugrep gnupatch patchelf
|
2014-09-11 01:10:49 +02:00
|
|
|
attr acl paxctl zlib;
|
2006-02-09 18:04:18 +01:00
|
|
|
};
|
2005-02-21 21:42:07 +01:00
|
|
|
};
|
|
|
|
|
2004-10-19 17:16:14 +02:00
|
|
|
}
|