2005-02-21 20:42:07 +00: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.
|
2016-12-16 13:22:02 +00:00
|
|
|
{ lib
|
2016-11-30 23:51:13 +00:00
|
|
|
, system, platform, crossSystem, config
|
2005-02-21 20:42:07 +00:00
|
|
|
|
2016-03-03 12:46:21 +00:00
|
|
|
, bootstrapFiles ?
|
2016-12-15 22:05:39 +00:00
|
|
|
if system == "i686-linux" then import ./bootstrap-files/i686.nix
|
|
|
|
else if system == "x86_64-linux" then import ./bootstrap-files/x86_64.nix
|
|
|
|
else if system == "armv5tel-linux" then import ./bootstrap-files/armv5tel.nix
|
|
|
|
else if system == "armv6l-linux" then import ./bootstrap-files/armv6l.nix
|
|
|
|
else if system == "armv7l-linux" then import ./bootstrap-files/armv7l.nix
|
|
|
|
else if system == "mips64el-linux" then import ./bootstrap-files/loongson2f.nix
|
2016-03-03 12:46:21 +00:00
|
|
|
else abort "unsupported platform for the pure Linux stdenv"
|
|
|
|
}:
|
2006-08-23 17:18:02 +01:00
|
|
|
|
2016-11-30 23:51:13 +00:00
|
|
|
assert crossSystem == null;
|
|
|
|
|
2016-03-03 12:46:21 +00:00
|
|
|
rec {
|
2006-08-23 17:18:02 +01:00
|
|
|
|
2009-03-25 17:34:38 +00:00
|
|
|
commonPreHook =
|
|
|
|
''
|
2016-02-29 11:10:26 +00:00
|
|
|
export NIX_ENFORCE_PURITY="''${NIX_ENFORCE_PURITY-1}"
|
2016-03-15 16:35:07 +00:00
|
|
|
export NIX_ENFORCE_NO_NATIVE="''${NIX_ENFORCE_NO_NATIVE-1}"
|
2009-03-25 17:34:38 +00:00
|
|
|
${if system == "x86_64-linux" then "NIX_LIB64_IN_SELF_RPATH=1" else ""}
|
2012-01-21 00:34:51 +00:00
|
|
|
${if system == "mips64el-linux" then "NIX_LIB32_IN_SELF_RPATH=1" else ""}
|
2009-03-25 17:34:38 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
|
2005-02-21 20:42:07 +00:00
|
|
|
# The bootstrap process proceeds in several steps.
|
|
|
|
|
2012-12-28 15:41:56 +00:00
|
|
|
|
2014-08-23 20:26:37 +01:00
|
|
|
# Create a standard environment by downloading pre-built binaries of
|
|
|
|
# coreutils, GCC, etc.
|
2005-02-22 09:55:03 +00:00
|
|
|
|
2012-12-28 15:41:56 +00:00
|
|
|
|
2009-02-01 21:44:56 +00:00
|
|
|
# Download and unpack the bootstrap tools (coreutils, GCC, Glibc, ...).
|
2016-12-15 22:09:29 +00:00
|
|
|
bootstrapTools = import ./bootstrap-tools { inherit system bootstrapFiles; };
|
2012-12-28 15:41:56 +00:00
|
|
|
|
2004-11-04 12:19:32 +00:00
|
|
|
|
2009-02-01 21:44:56 +00:00
|
|
|
# This function builds the various standard environments used during
|
2014-08-23 20:26:37 +01:00
|
|
|
# the bootstrap. In all stages, we build an stdenv and the package
|
|
|
|
# set that can be built with that stdenv.
|
2016-12-24 15:07:20 +00:00
|
|
|
stageFun = prevStage:
|
|
|
|
{ name, overrides ? (self: super: {}), extraBuildInputs ? [] }:
|
2004-11-04 12:19:32 +00:00
|
|
|
|
2014-08-23 20:26:37 +01:00
|
|
|
let
|
2014-08-24 17:08:23 +01:00
|
|
|
|
|
|
|
thisStdenv = import ../generic {
|
2014-09-14 18:37:32 +01:00
|
|
|
inherit system config extraBuildInputs;
|
2014-08-24 17:08:23 +01: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}
|
|
|
|
'';
|
2016-02-24 10:01:11 +00:00
|
|
|
shell = "${bootstrapTools}/bin/bash";
|
2014-09-14 18:32:58 +01:00
|
|
|
initialPath = [bootstrapTools];
|
2016-02-27 19:27:24 +00:00
|
|
|
|
|
|
|
fetchurlBoot = import ../../build-support/fetchurl/boot.nix {
|
|
|
|
inherit system;
|
2014-08-24 17:08:23 +01:00
|
|
|
};
|
2014-09-11 00:18:14 +01:00
|
|
|
|
2016-12-24 15:07:20 +00:00
|
|
|
cc = if isNull prevStage.gcc-unwrapped
|
2015-06-15 18:26:52 +01:00
|
|
|
then null
|
2015-01-09 19:22:12 +00:00
|
|
|
else lib.makeOverridable (import ../../build-support/cc-wrapper) {
|
2014-09-11 00:18:14 +01:00
|
|
|
nativeTools = false;
|
|
|
|
nativeLibc = false;
|
2016-12-24 15:07:20 +00:00
|
|
|
cc = prevStage.gcc-unwrapped;
|
2015-05-11 22:30:13 +01:00
|
|
|
isGNU = true;
|
2016-12-24 15:07:20 +00:00
|
|
|
libc = prevStage.glibc;
|
|
|
|
inherit (prevStage) binutils coreutils gnugrep;
|
2014-09-11 00:18:14 +01:00
|
|
|
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.
|
2016-12-24 15:07:20 +00:00
|
|
|
inherit (prevStage) glibc;
|
2014-09-11 00:18:14 +01:00
|
|
|
};
|
2016-12-19 16:10:47 +00:00
|
|
|
overrides = self: super: (overrides self super) // { fetchurl = thisStdenv.fetchurlBoot; };
|
2014-08-23 19:34:01 +01:00
|
|
|
};
|
2004-11-04 12:19:32 +00:00
|
|
|
|
2016-12-16 13:22:02 +00:00
|
|
|
in {
|
|
|
|
inherit system platform crossSystem config;
|
|
|
|
stdenv = thisStdenv;
|
|
|
|
};
|
2009-02-01 21:44:56 +00:00
|
|
|
|
2016-12-24 15:07:20 +00:00
|
|
|
baseCase = {
|
|
|
|
gcc-unwrapped = null;
|
2014-09-11 00:18:14 +01:00
|
|
|
glibc = null;
|
|
|
|
binutils = null;
|
|
|
|
coreutils = null;
|
2016-01-24 05:18:32 +00:00
|
|
|
gnugrep = null;
|
2016-12-24 15:07:20 +00: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.
|
|
|
|
stage0 = stageFun baseCase {
|
2014-09-11 00:18:14 +01:00
|
|
|
name = null;
|
2012-12-28 15:41:56 +00:00
|
|
|
|
2016-12-19 16:10:47 +00:00
|
|
|
overrides = self: super: {
|
2014-08-23 20:26:37 +01:00
|
|
|
# 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.
|
2016-12-19 16:10:47 +00:00
|
|
|
glibc = self.stdenv.mkDerivation {
|
2014-08-23 20:26:37 +01:00
|
|
|
name = "bootstrap-glibc";
|
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out
|
|
|
|
ln -s ${bootstrapTools}/lib $out/lib
|
|
|
|
ln -s ${bootstrapTools}/include-glibc $out/include
|
|
|
|
'';
|
|
|
|
};
|
2016-12-24 15:07:20 +00:00
|
|
|
gcc-unwrapped = bootstrapTools;
|
|
|
|
binutils = bootstrapTools;
|
|
|
|
coreutils = bootstrapTools;
|
|
|
|
gnugrep = bootstrapTools;
|
2004-11-04 12:19:32 +00:00
|
|
|
};
|
2009-02-01 21:44:56 +00:00
|
|
|
};
|
2005-02-21 20:42:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Create the first "real" standard environment. This one consists
|
2009-02-01 21:44:56 +00:00
|
|
|
# of bootstrap tools only, and a minimal Glibc to keep the GCC
|
|
|
|
# configure script happy.
|
2014-08-24 14:55:14 +01: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.
|
2016-12-24 15:07:20 +00:00
|
|
|
stage1 = prevStage: stageFun prevStage {
|
2014-09-11 00:18:14 +01:00
|
|
|
name = "bootstrap-gcc-wrapper";
|
|
|
|
|
2014-08-23 20:26:37 +01:00
|
|
|
# Rebuild binutils to use from stage2 onwards.
|
2016-12-19 16:10:47 +00:00
|
|
|
overrides = self: super: {
|
|
|
|
binutils = super.binutils.override { gold = false; };
|
2016-12-24 15:07:20 +00:00
|
|
|
inherit (prevStage) glibc gcc-unwrapped coreutils gnugrep;
|
2014-09-11 00:18:14 +01:00
|
|
|
|
2014-09-04 15:17:39 +01: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.
|
2016-12-19 16:10:47 +00:00
|
|
|
perl = super.perl.override { enableThreading = false; };
|
2010-01-19 11:25:33 +00:00
|
|
|
};
|
2005-02-21 20:42:07 +00:00
|
|
|
};
|
|
|
|
|
2014-01-07 16:46:47 +00:00
|
|
|
|
2014-08-23 20:26:37 +01:00
|
|
|
# 2nd stdenv that contains our own rebuilt binutils and is used for
|
|
|
|
# compiling our own Glibc.
|
2016-12-24 15:07:20 +00:00
|
|
|
stage2 = prevStage: stageFun prevStage {
|
2014-09-11 00:18:14 +01:00
|
|
|
name = "bootstrap-gcc-wrapper";
|
|
|
|
|
2016-12-19 16:10:47 +00:00
|
|
|
overrides = self: super: {
|
2016-12-24 15:07:20 +00:00
|
|
|
inherit (prevStage)
|
|
|
|
binutils gcc-unwrapped coreutils gnugrep
|
|
|
|
perl paxctl gnum4 bison;
|
2014-08-23 20:26:37 +01:00
|
|
|
# This also contains the full, dynamically linked, final Glibc.
|
2011-12-14 14:31:56 +00:00
|
|
|
};
|
2010-08-25 14:22:48 +01:00
|
|
|
};
|
|
|
|
|
2012-12-28 15:41:56 +00:00
|
|
|
|
2014-08-23 20:26:37 +01: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.
|
2016-12-24 15:07:20 +00:00
|
|
|
stage3 = prevStage: stageFun prevStage {
|
2014-09-11 00:18:14 +01:00
|
|
|
name = "bootstrap-gcc-wrapper";
|
|
|
|
|
2016-12-19 16:10:47 +00:00
|
|
|
overrides = self: super: rec {
|
2016-12-24 15:07:20 +00:00
|
|
|
inherit (prevStage)
|
|
|
|
binutils glibc coreutils gnugrep
|
|
|
|
perl patchelf linuxHeaders gnum4 bison;
|
2011-12-14 14:31:56 +00: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.
|
2016-12-19 16:10:47 +00:00
|
|
|
gmp = super.gmp.override { stdenv = self.makeStaticLibraries self.stdenv; };
|
|
|
|
mpfr = super.mpfr.override { stdenv = self.makeStaticLibraries self.stdenv; };
|
|
|
|
libmpc = super.libmpc.override { stdenv = self.makeStaticLibraries self.stdenv; };
|
|
|
|
isl_0_14 = super.isl_0_14.override { stdenv = self.makeStaticLibraries self.stdenv; };
|
2016-12-24 15:07:20 +00:00
|
|
|
gcc-unwrapped = super.gcc-unwrapped.override {
|
2016-02-28 14:20:14 +00:00
|
|
|
isl = isl_0_14;
|
2015-06-11 17:52:19 +01:00
|
|
|
};
|
2010-01-19 11:25:33 +00:00
|
|
|
};
|
2016-12-16 13:22:02 +00:00
|
|
|
extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ];
|
2005-02-21 20:42:07 +00:00
|
|
|
};
|
|
|
|
|
2012-12-28 15:41:56 +00:00
|
|
|
|
2014-08-23 20:26:37 +01:00
|
|
|
# Construct a fourth stdenv that uses the new GCC. But coreutils is
|
|
|
|
# still from the bootstrap tools.
|
2016-12-24 15:07:20 +00:00
|
|
|
stage4 = prevStage: stageFun prevStage {
|
2014-09-11 00:18:14 +01:00
|
|
|
name = "";
|
|
|
|
|
2016-12-19 16:10:47 +00:00
|
|
|
overrides = self: super: {
|
2014-09-11 00:10:49 +01: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.
|
2016-12-16 13:22:02 +00:00
|
|
|
inherit (prevStage) gettext gnum4 bison gmp perl glibc zlib linuxHeaders;
|
2014-08-29 21:09:01 +01:00
|
|
|
|
2015-01-09 19:22:12 +00:00
|
|
|
gcc = lib.makeOverridable (import ../../build-support/cc-wrapper) {
|
2014-09-11 00:18:14 +01:00
|
|
|
nativeTools = false;
|
|
|
|
nativeLibc = false;
|
2015-05-11 22:30:13 +01:00
|
|
|
isGNU = true;
|
2016-12-24 15:07:20 +00:00
|
|
|
cc = prevStage.gcc-unwrapped;
|
2016-12-19 16:10:47 +00:00
|
|
|
libc = self.glibc;
|
|
|
|
inherit (self) stdenv binutils coreutils gnugrep;
|
2014-08-29 21:09:01 +01:00
|
|
|
name = "";
|
2016-12-19 16:10:47 +00:00
|
|
|
shell = self.bash + "/bin/bash";
|
2014-09-11 00:18:14 +01:00
|
|
|
};
|
2010-01-19 11:25:33 +00:00
|
|
|
};
|
2016-12-16 13:22:02 +00:00
|
|
|
extraBuildInputs = [ prevStage.patchelf prevStage.xz ];
|
2005-02-21 20:42:07 +00:00
|
|
|
};
|
|
|
|
|
2012-12-28 15:41:56 +00:00
|
|
|
|
2014-08-23 20:26:37 +01: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 21:44:56 +00:00
|
|
|
#
|
2014-08-23 20:26:37 +01:00
|
|
|
# When updating stdenvLinux, make sure that the result has no
|
|
|
|
# dependency (`nix-store -qR') on bootstrapTools or the first
|
|
|
|
# binutils built.
|
2016-12-16 13:22:02 +00:00
|
|
|
stdenvLinux = prevStage: import ../generic rec {
|
2012-12-28 15:36:09 +00:00
|
|
|
inherit system config;
|
2012-12-28 15:41:56 +00:00
|
|
|
|
2014-01-07 12:57:42 +00:00
|
|
|
preHook =
|
|
|
|
''
|
|
|
|
# Make "strip" produce deterministic output, by setting
|
|
|
|
# timestamps etc. to a fixed value.
|
|
|
|
commonStripFlags="--enable-deterministic-archives"
|
|
|
|
${commonPreHook}
|
|
|
|
'';
|
2012-12-28 15:41:56 +00:00
|
|
|
|
|
|
|
initialPath =
|
2016-12-16 13:22:02 +00:00
|
|
|
((import ../common-path.nix) {pkgs = prevStage;});
|
2014-06-27 10:15:28 +01:00
|
|
|
|
2016-12-16 13:22:02 +00:00
|
|
|
extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ];
|
2009-11-15 16:48:36 +00:00
|
|
|
|
2016-12-16 13:22:02 +00:00
|
|
|
cc = prevStage.gcc;
|
2005-02-21 20:42:07 +00:00
|
|
|
|
2014-12-17 18:11:30 +00:00
|
|
|
shell = cc.shell;
|
2012-12-28 15:41:56 +00:00
|
|
|
|
2016-12-16 13:22:02 +00:00
|
|
|
inherit (prevStage.stdenv) fetchurlBoot;
|
2012-12-28 15:41:56 +00:00
|
|
|
|
2006-02-09 17:04:18 +00:00
|
|
|
extraAttrs = {
|
2016-12-16 13:22:02 +00:00
|
|
|
inherit (prevStage) glibc;
|
2012-12-30 11:29:02 +00:00
|
|
|
inherit platform bootstrapTools;
|
2016-12-16 13:22:02 +00:00
|
|
|
shellPackage = prevStage.bash;
|
2010-08-06 11:34:34 +01:00
|
|
|
};
|
|
|
|
|
2015-04-18 10:00:58 +01:00
|
|
|
/* outputs TODO
|
2016-12-16 13:22:02 +00:00
|
|
|
allowedRequisites = with prevStage;
|
2014-08-29 21:09:01 +01:00
|
|
|
[ gzip bzip2 xz bash binutils coreutils diffutils findutils gawk
|
|
|
|
glibc gnumake gnused gnutar gnugrep gnupatch patchelf attr acl
|
2015-01-15 04:44:00 +00:00
|
|
|
paxctl zlib pcre linuxHeaders ed gcc gcc.cc libsigsegv
|
2014-11-06 12:33:08 +00:00
|
|
|
];
|
2015-04-18 10:00:58 +01:00
|
|
|
*/
|
2014-08-29 21:09:01 +01:00
|
|
|
|
2016-12-19 16:10:47 +00:00
|
|
|
overrides = self: super: {
|
2015-01-03 14:54:02 +00:00
|
|
|
gcc = cc;
|
|
|
|
|
2016-12-16 13:22:02 +00:00
|
|
|
inherit (prevStage)
|
2014-08-24 14:55:14 +01:00
|
|
|
gzip bzip2 xz bash binutils coreutils diffutils findutils gawk
|
|
|
|
glibc gnumake gnused gnutar gnugrep gnupatch patchelf
|
2014-10-06 19:49:10 +01:00
|
|
|
attr acl paxctl zlib pcre;
|
2006-02-09 17:04:18 +00:00
|
|
|
};
|
2005-02-21 20:42:07 +00:00
|
|
|
};
|
|
|
|
|
2016-12-16 13:22:02 +00:00
|
|
|
stagesLinux = [
|
|
|
|
({}: stage0)
|
|
|
|
stage1
|
|
|
|
stage2
|
|
|
|
stage3
|
|
|
|
stage4
|
|
|
|
(prevStage: {
|
|
|
|
inherit system crossSystem platform config;
|
|
|
|
stdenv = stdenvLinux prevStage;
|
|
|
|
})
|
|
|
|
];
|
2004-10-19 16:16:14 +01:00
|
|
|
}
|