2014-02-04 17:18:38 +01:00
|
|
|
let lib = import ../../../lib; in lib.makeOverridable (
|
|
|
|
|
stdenv: Introduce hasCC attribute
Before, we'd always use `cc = null`, and check for that. The problem is
this breaks for cross compilation to platforms that don't support a C
compiler.
It's a very subtle issue. One might think there is no problem because we
have `stdenvNoCC`, and presumably one would only build derivations that
use that. The problem is that one still wants to use tools at build-time
that are themselves built with a C compiler, and those are gotten via
"splicing". The runtime version of those deps will explode, but the
build time / `buildPackages` versions of those deps will be fine, and
splicing attempts to work this by using `builtins.tryEval` to filter out
any broken "higher priority" packages (runtime is the default and
highest priority) so that both `foo` and `foo.nativeDrv` works.
However, `tryEval` only catches certain evaluation failures (e.g.
exceptions), and not arbitrary failures (such as `cc.attr` when `cc` is
null). This means `tryEval` fails to let us use our build time deps, and
everything comes apart.
The right solution is, as usually, to get rid of splicing. Or, baring
that, to make it so `foo` never works and one has to explicitly do
`foo.*`. But that is a much larger change, and certaily one unsuitable
to be backported to stable.
Given that, we instead make an exception-throwing `cc` attribute, and
create a `hasCC` attribute for those derivations which wish to
condtionally use a C compiler: instead of doing `stdenv.cc or null ==
null` or something similar, one does `stdenv.hasCC`. This allows quering
without "tripping" the exception, while also allowing `tryEval` to work.
No platform without a C compiler is yet wired up by default. That will
be done in a following commit.
2019-11-25 00:07:20 +01:00
|
|
|
{ name ? "stdenv", preHook ? "", initialPath
|
|
|
|
|
|
|
|
, # If we don't have a C compiler, we might either have `cc = null` or `cc =
|
|
|
|
# throw ...`, but if we do have a C compiler we should definiely have `cc !=
|
|
|
|
# null`.
|
|
|
|
#
|
|
|
|
# TODO(@Ericson2314): Add assert without creating infinite recursion
|
|
|
|
hasCC ? cc != null, cc
|
|
|
|
|
|
|
|
, shell
|
2016-12-19 17:10:47 +01:00
|
|
|
, allowedRequisites ? null, extraAttrs ? {}, overrides ? (self: super: {}), config
|
2009-02-02 16:03:38 +01:00
|
|
|
|
|
|
|
, # The `fetchurl' to use for downloading curl and its dependencies
|
|
|
|
# (see all-packages.nix).
|
|
|
|
fetchurlBoot
|
2014-02-04 17:18:38 +01:00
|
|
|
|
|
|
|
, setupScript ? ./setup.sh
|
|
|
|
|
2017-08-15 17:30:45 +02:00
|
|
|
, extraNativeBuildInputs ? []
|
2014-02-04 17:18:38 +01:00
|
|
|
, extraBuildInputs ? []
|
2015-06-12 02:58:26 +02:00
|
|
|
, __stdenvImpureHostDeps ? []
|
|
|
|
, __extraImpureHostDeps ? []
|
2015-11-21 21:06:41 +01:00
|
|
|
, stdenvSandboxProfile ? ""
|
|
|
|
, extraSandboxProfile ? ""
|
2017-05-22 03:37:16 +02:00
|
|
|
|
2017-07-06 03:47:48 +02:00
|
|
|
## Platform parameters
|
|
|
|
##
|
|
|
|
## The "build" "host" "target" terminology below comes from GNU Autotools. See
|
|
|
|
## its documentation for more information on what those words mean. Note that
|
|
|
|
## each should always be defined, even when not cross compiling.
|
|
|
|
##
|
|
|
|
## For purposes of bootstrapping, think of each stage as a "sliding window"
|
|
|
|
## over a list of platforms. Specifically, the host platform of the previous
|
|
|
|
## stage becomes the build platform of the current one, and likewise the
|
|
|
|
## target platform of the previous stage becomes the host platform of the
|
|
|
|
## current one.
|
|
|
|
##
|
|
|
|
|
|
|
|
, # The platform on which packages are built. Consists of `system`, a
|
|
|
|
# string (e.g.,`i686-linux') identifying the most import attributes of the
|
|
|
|
# build platform, and `platform` a set of other details.
|
|
|
|
buildPlatform
|
|
|
|
|
|
|
|
, # The platform on which packages run.
|
|
|
|
hostPlatform
|
|
|
|
|
|
|
|
, # The platform which build tools (especially compilers) build for in this stage,
|
|
|
|
targetPlatform
|
2004-07-02 12:05:53 +02:00
|
|
|
}:
|
|
|
|
|
2009-04-25 16:08:29 +02:00
|
|
|
let
|
2017-08-15 17:30:45 +02:00
|
|
|
defaultNativeBuildInputs = extraNativeBuildInputs ++
|
2014-07-08 14:26:35 +02:00
|
|
|
[ ../../build-support/setup-hooks/move-docs.sh
|
2019-11-25 13:23:14 +01:00
|
|
|
../../build-support/setup-hooks/make-symlinks-relative.sh
|
2014-07-08 14:26:35 +02:00
|
|
|
../../build-support/setup-hooks/compress-man-pages.sh
|
2014-06-27 13:33:05 +02:00
|
|
|
../../build-support/setup-hooks/strip.sh
|
|
|
|
../../build-support/setup-hooks/patch-shebangs.sh
|
2018-12-09 23:45:15 +01:00
|
|
|
../../build-support/setup-hooks/prune-libtool-files.sh
|
2017-05-06 13:18:28 +02:00
|
|
|
]
|
|
|
|
# FIXME this on Darwin; see
|
|
|
|
# https://github.com/NixOS/nixpkgs/commit/94d164dd7#commitcomment-22030369
|
2019-08-19 16:05:44 +02:00
|
|
|
++ lib.optionals hostPlatform.isLinux [
|
|
|
|
../../build-support/setup-hooks/audit-tmpdir.sh
|
|
|
|
../../build-support/setup-hooks/move-systemd-user-units.sh
|
|
|
|
]
|
2017-05-06 13:18:28 +02:00
|
|
|
++ [
|
2014-08-30 08:27:43 +02:00
|
|
|
../../build-support/setup-hooks/multiple-outputs.sh
|
2014-10-07 14:43:56 +02:00
|
|
|
../../build-support/setup-hooks/move-sbin.sh
|
2014-10-07 15:04:13 +02:00
|
|
|
../../build-support/setup-hooks/move-lib64.sh
|
2016-01-05 15:32:59 +01:00
|
|
|
../../build-support/setup-hooks/set-source-date-epoch-to-latest.sh
|
2020-10-31 17:29:54 +01:00
|
|
|
../../build-support/setup-hooks/reproducible-builds.sh
|
stdenv: Introduce hasCC attribute
Before, we'd always use `cc = null`, and check for that. The problem is
this breaks for cross compilation to platforms that don't support a C
compiler.
It's a very subtle issue. One might think there is no problem because we
have `stdenvNoCC`, and presumably one would only build derivations that
use that. The problem is that one still wants to use tools at build-time
that are themselves built with a C compiler, and those are gotten via
"splicing". The runtime version of those deps will explode, but the
build time / `buildPackages` versions of those deps will be fine, and
splicing attempts to work this by using `builtins.tryEval` to filter out
any broken "higher priority" packages (runtime is the default and
highest priority) so that both `foo` and `foo.nativeDrv` works.
However, `tryEval` only catches certain evaluation failures (e.g.
exceptions), and not arbitrary failures (such as `cc.attr` when `cc` is
null). This means `tryEval` fails to let us use our build time deps, and
everything comes apart.
The right solution is, as usually, to get rid of splicing. Or, baring
that, to make it so `foo` never works and one has to explicitly do
`foo.*`. But that is a much larger change, and certaily one unsuitable
to be backported to stable.
Given that, we instead make an exception-throwing `cc` attribute, and
create a `hasCC` attribute for those derivations which wish to
condtionally use a C compiler: instead of doing `stdenv.cc or null ==
null` or something similar, one does `stdenv.hasCC`. This allows quering
without "tripping" the exception, while also allowing `tryEval` to work.
No platform without a C compiler is yet wired up by default. That will
be done in a following commit.
2019-11-25 00:07:20 +01:00
|
|
|
# TODO use lib.optional instead
|
|
|
|
(if hasCC then cc else null)
|
2014-06-27 13:33:05 +02:00
|
|
|
];
|
|
|
|
|
2017-08-15 17:30:45 +02:00
|
|
|
defaultBuildInputs = extraBuildInputs;
|
|
|
|
|
2014-02-04 17:18:38 +01:00
|
|
|
# The stdenv that we are producing.
|
2017-07-05 23:56:53 +02:00
|
|
|
stdenv =
|
2014-08-29 22:09:01 +02:00
|
|
|
derivation (
|
2017-08-15 17:30:45 +02:00
|
|
|
lib.optionalAttrs (allowedRequisites != null) {
|
|
|
|
allowedRequisites = allowedRequisites
|
|
|
|
++ defaultNativeBuildInputs ++ defaultBuildInputs;
|
|
|
|
}
|
|
|
|
// {
|
2017-07-06 03:47:48 +02:00
|
|
|
inherit name;
|
|
|
|
|
|
|
|
# Nix itself uses the `system` field of a derivation to decide where to
|
|
|
|
# build it. This is a bit confusing for cross compilation.
|
|
|
|
inherit (buildPlatform) system;
|
2014-02-04 17:18:38 +01:00
|
|
|
|
|
|
|
builder = shell;
|
|
|
|
|
|
|
|
args = ["-e" ./builder.sh];
|
|
|
|
|
|
|
|
setup = setupScript;
|
|
|
|
|
2017-10-06 07:26:19 +02:00
|
|
|
# We pretty much never need rpaths on Darwin, since all library path references
|
|
|
|
# are absolute unless we go out of our way to make them relative (like with CF)
|
|
|
|
# TODO: This really wants to be in stdenv/darwin but we don't have hostPlatform
|
|
|
|
# there (yet?) so it goes here until then.
|
|
|
|
preHook = preHook+ lib.optionalString buildPlatform.isDarwin ''
|
2020-04-28 06:08:48 +02:00
|
|
|
export NIX_DONT_SET_RPATH_FOR_BUILD=1
|
2019-04-17 05:55:31 +02:00
|
|
|
'' + lib.optionalString (hostPlatform.isDarwin || (hostPlatform.parsed.kernel.execFormat != lib.systems.parse.execFormats.elf && hostPlatform.parsed.kernel.execFormat != lib.systems.parse.execFormats.macho)) ''
|
2019-01-30 03:01:24 +01:00
|
|
|
export NIX_DONT_SET_RPATH=1
|
|
|
|
export NIX_NO_SELF_RPATH=1
|
2018-05-22 19:25:35 +02:00
|
|
|
''
|
|
|
|
# TODO this should be uncommented, but it causes stupid mass rebuilds. I
|
|
|
|
# think the best solution would just be to fixup linux RPATHs so we don't
|
|
|
|
# need to set `-rpath` anywhere.
|
|
|
|
# + lib.optionalString targetPlatform.isDarwin ''
|
2020-04-28 06:08:48 +02:00
|
|
|
# export NIX_DONT_SET_RPATH_FOR_TARGET=1
|
2018-05-22 19:25:35 +02:00
|
|
|
# ''
|
|
|
|
;
|
2017-10-06 07:26:19 +02:00
|
|
|
|
|
|
|
inherit initialPath shell
|
2017-08-15 17:30:45 +02:00
|
|
|
defaultNativeBuildInputs defaultBuildInputs;
|
2015-06-18 19:03:32 +02:00
|
|
|
}
|
2017-07-06 03:47:48 +02:00
|
|
|
// lib.optionalAttrs buildPlatform.isDarwin {
|
2015-11-21 21:06:41 +01:00
|
|
|
__sandboxProfile = stdenvSandboxProfile;
|
2015-06-18 19:03:32 +02:00
|
|
|
__impureHostDeps = __stdenvImpureHostDeps;
|
2014-08-29 22:09:01 +02:00
|
|
|
})
|
2014-02-04 17:18:38 +01:00
|
|
|
|
2019-08-13 23:52:01 +02:00
|
|
|
// {
|
2014-02-04 17:18:38 +01:00
|
|
|
|
2016-08-28 16:56:31 +02:00
|
|
|
meta = {
|
|
|
|
description = "The default build environment for Unix packages in Nixpkgs";
|
|
|
|
platforms = lib.platforms.all;
|
|
|
|
};
|
2014-02-04 17:18:38 +01:00
|
|
|
|
2017-07-06 03:47:48 +02:00
|
|
|
inherit buildPlatform hostPlatform targetPlatform;
|
|
|
|
|
2017-08-15 17:30:45 +02:00
|
|
|
inherit extraNativeBuildInputs extraBuildInputs
|
|
|
|
__extraImpureHostDeps extraSandboxProfile;
|
2017-07-06 01:58:24 +02:00
|
|
|
|
2014-02-04 17:18:38 +01:00
|
|
|
# Utility flags to test the type of platform.
|
2017-05-22 03:37:16 +02:00
|
|
|
inherit (hostPlatform)
|
2018-08-28 23:17:54 +02:00
|
|
|
isDarwin isLinux isSunOS isCygwin isFreeBSD isOpenBSD
|
2019-01-06 19:57:36 +01:00
|
|
|
isi686 isx86_32 isx86_64
|
|
|
|
is32bit is64bit
|
|
|
|
isAarch32 isAarch64 isMips isBigEndian;
|
2014-02-04 17:18:38 +01:00
|
|
|
|
2020-07-11 22:06:08 +02:00
|
|
|
# Override `system` so that packages can get the system of the host
|
|
|
|
# platform through `stdenv.system`. `system` is originally set to the
|
|
|
|
# build platform within the derivation above so that Nix directs the build
|
|
|
|
# to correct type of machine.
|
|
|
|
inherit (hostPlatform) system;
|
2018-08-27 20:39:58 +02:00
|
|
|
|
2017-07-05 23:56:53 +02:00
|
|
|
inherit (import ./make-derivation.nix {
|
|
|
|
inherit lib config stdenv;
|
|
|
|
}) mkDerivation;
|
2014-07-01 16:43:52 +02:00
|
|
|
|
2021-01-30 11:23:49 +01:00
|
|
|
# Slated for deprecation in 21.11
|
2021-01-31 04:03:11 +01:00
|
|
|
lib = builtins.trace
|
|
|
|
( "Warning: `stdenv.lib` is deprecated and will be removed in the next release."
|
|
|
|
+ " Please use `pkgs.lib` instead."
|
|
|
|
+ " For more information see https://github.com/NixOS/nixpkgs/issues/108938")
|
|
|
|
lib;
|
2014-02-04 17:18:38 +01:00
|
|
|
|
|
|
|
inherit fetchurlBoot;
|
|
|
|
|
|
|
|
inherit overrides;
|
2014-07-01 16:17:23 +02:00
|
|
|
|
stdenv: Introduce hasCC attribute
Before, we'd always use `cc = null`, and check for that. The problem is
this breaks for cross compilation to platforms that don't support a C
compiler.
It's a very subtle issue. One might think there is no problem because we
have `stdenvNoCC`, and presumably one would only build derivations that
use that. The problem is that one still wants to use tools at build-time
that are themselves built with a C compiler, and those are gotten via
"splicing". The runtime version of those deps will explode, but the
build time / `buildPackages` versions of those deps will be fine, and
splicing attempts to work this by using `builtins.tryEval` to filter out
any broken "higher priority" packages (runtime is the default and
highest priority) so that both `foo` and `foo.nativeDrv` works.
However, `tryEval` only catches certain evaluation failures (e.g.
exceptions), and not arbitrary failures (such as `cc.attr` when `cc` is
null). This means `tryEval` fails to let us use our build time deps, and
everything comes apart.
The right solution is, as usually, to get rid of splicing. Or, baring
that, to make it so `foo` never works and one has to explicitly do
`foo.*`. But that is a much larger change, and certaily one unsuitable
to be backported to stable.
Given that, we instead make an exception-throwing `cc` attribute, and
create a `hasCC` attribute for those derivations which wish to
condtionally use a C compiler: instead of doing `stdenv.cc or null ==
null` or something similar, one does `stdenv.hasCC`. This allows quering
without "tripping" the exception, while also allowing `tryEval` to work.
No platform without a C compiler is yet wired up by default. That will
be done in a following commit.
2019-11-25 00:07:20 +01:00
|
|
|
inherit cc hasCC;
|
2014-02-04 17:18:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Propagate any extra attributes. For instance, we use this to
|
|
|
|
# "lift" packages like curl from the final stdenv for Linux to
|
|
|
|
# all-packages.nix for that platform (meaning that it has a line
|
|
|
|
# like curl = if stdenv ? curl then stdenv.curl else ...).
|
|
|
|
// extraAttrs;
|
|
|
|
|
2017-07-05 23:56:53 +02:00
|
|
|
in stdenv)
|