2021-11-26 22:23:32 +00:00
|
|
|
let lib = import ../../../lib; stdenv-overridable = lib.makeOverridable (
|
2014-02-04 16:18:38 +00:00
|
|
|
|
2021-11-26 22:23:32 +00:00
|
|
|
argsStdenv@{ name ? "stdenv", preHook ? "", initialPath
|
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-24 23:07:20 +00:00
|
|
|
|
|
|
|
, # 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 16:10:47 +00:00
|
|
|
, allowedRequisites ? null, extraAttrs ? {}, overrides ? (self: super: {}), config
|
2022-04-14 06:13:33 +00:00
|
|
|
, disallowedRequisites ? []
|
2009-02-02 15:03:38 +00:00
|
|
|
|
|
|
|
, # The `fetchurl' to use for downloading curl and its dependencies
|
|
|
|
# (see all-packages.nix).
|
|
|
|
fetchurlBoot
|
2014-02-04 16:18:38 +00:00
|
|
|
|
|
|
|
, setupScript ? ./setup.sh
|
|
|
|
|
2017-08-15 15:30:45 +00:00
|
|
|
, extraNativeBuildInputs ? []
|
2014-02-04 16:18:38 +00:00
|
|
|
, extraBuildInputs ? []
|
2015-06-12 00:58:26 +00:00
|
|
|
, __stdenvImpureHostDeps ? []
|
|
|
|
, __extraImpureHostDeps ? []
|
2015-11-21 20:06:41 +00:00
|
|
|
, stdenvSandboxProfile ? ""
|
|
|
|
, extraSandboxProfile ? ""
|
2017-05-22 01:37:16 +00:00
|
|
|
|
2017-07-06 01:47:48 +00: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
|
2021-08-17 01:16:29 +00:00
|
|
|
|
|
|
|
, # The implementation of `mkDerivation`, parameterized with the final stdenv so we can tie the knot.
|
|
|
|
# This is convient to have as a parameter so the stdenv "adapters" work better
|
|
|
|
mkDerivationFromStdenv ? import ./make-derivation.nix { inherit lib config; }
|
2004-07-02 10:05:53 +00:00
|
|
|
}:
|
|
|
|
|
2009-04-25 14:08:29 +00:00
|
|
|
let
|
2017-08-15 15:30:45 +00:00
|
|
|
defaultNativeBuildInputs = extraNativeBuildInputs ++
|
2014-07-08 12:26:35 +00:00
|
|
|
[ ../../build-support/setup-hooks/move-docs.sh
|
2019-11-25 12:23:14 +00:00
|
|
|
../../build-support/setup-hooks/make-symlinks-relative.sh
|
2014-07-08 12:26:35 +00:00
|
|
|
../../build-support/setup-hooks/compress-man-pages.sh
|
2014-06-27 11:33:05 +00:00
|
|
|
../../build-support/setup-hooks/strip.sh
|
|
|
|
../../build-support/setup-hooks/patch-shebangs.sh
|
2018-12-09 22:45:15 +00:00
|
|
|
../../build-support/setup-hooks/prune-libtool-files.sh
|
2017-05-06 11:18:28 +00:00
|
|
|
]
|
|
|
|
# FIXME this on Darwin; see
|
|
|
|
# https://github.com/NixOS/nixpkgs/commit/94d164dd7#commitcomment-22030369
|
2019-08-19 14:05:44 +00:00
|
|
|
++ lib.optionals hostPlatform.isLinux [
|
|
|
|
../../build-support/setup-hooks/audit-tmpdir.sh
|
|
|
|
../../build-support/setup-hooks/move-systemd-user-units.sh
|
|
|
|
]
|
2017-05-06 11:18:28 +00:00
|
|
|
++ [
|
2014-08-30 06:27:43 +00:00
|
|
|
../../build-support/setup-hooks/multiple-outputs.sh
|
2014-10-07 12:43:56 +00:00
|
|
|
../../build-support/setup-hooks/move-sbin.sh
|
2014-10-07 13:04:13 +00:00
|
|
|
../../build-support/setup-hooks/move-lib64.sh
|
2016-01-05 14:32:59 +00:00
|
|
|
../../build-support/setup-hooks/set-source-date-epoch-to-latest.sh
|
2020-10-31 16:29:54 +00: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-24 23:07:20 +00:00
|
|
|
# TODO use lib.optional instead
|
|
|
|
(if hasCC then cc else null)
|
2014-06-27 11:33:05 +00:00
|
|
|
];
|
|
|
|
|
2017-08-15 15:30:45 +00:00
|
|
|
defaultBuildInputs = extraBuildInputs;
|
|
|
|
|
2021-11-26 22:23:32 +00:00
|
|
|
stdenv = (stdenv-overridable argsStdenv);
|
|
|
|
|
2014-02-04 16:18:38 +00:00
|
|
|
# The stdenv that we are producing.
|
2021-11-26 22:23:32 +00:00
|
|
|
in
|
2014-08-29 20:09:01 +00:00
|
|
|
derivation (
|
2017-08-15 15:30:45 +00:00
|
|
|
lib.optionalAttrs (allowedRequisites != null) {
|
|
|
|
allowedRequisites = allowedRequisites
|
|
|
|
++ defaultNativeBuildInputs ++ defaultBuildInputs;
|
|
|
|
}
|
2022-04-27 20:21:32 +00:00
|
|
|
// lib.optionalAttrs config.contentAddressedByDefault {
|
2021-04-26 15:21:17 +00:00
|
|
|
__contentAddressed = true;
|
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
outputHashMode = "recursive";
|
|
|
|
}
|
2017-08-15 15:30:45 +00:00
|
|
|
// {
|
2017-07-06 01:47:48 +00:00
|
|
|
inherit name;
|
2022-04-14 06:13:33 +00:00
|
|
|
inherit disallowedRequisites;
|
2017-07-06 01:47:48 +00:00
|
|
|
|
|
|
|
# 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 16:18:38 +00:00
|
|
|
|
|
|
|
builder = shell;
|
|
|
|
|
|
|
|
args = ["-e" ./builder.sh];
|
|
|
|
|
|
|
|
setup = setupScript;
|
|
|
|
|
2017-10-06 05:26:19 +00: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.
|
2021-12-19 00:32:35 +00:00
|
|
|
preHook = preHook + lib.optionalString buildPlatform.isDarwin ''
|
2020-04-28 04:08:48 +00:00
|
|
|
export NIX_DONT_SET_RPATH_FOR_BUILD=1
|
2019-04-17 03:55:31 +00: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 02:01:24 +00:00
|
|
|
export NIX_DONT_SET_RPATH=1
|
|
|
|
export NIX_NO_SELF_RPATH=1
|
2021-02-05 07:24:43 +00:00
|
|
|
'' + lib.optionalString (hostPlatform.isDarwin && hostPlatform.isMacOS) ''
|
|
|
|
export MACOSX_DEPLOYMENT_TARGET=${hostPlatform.darwinMinVersion}
|
2018-05-22 17:25:35 +00: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 04:08:48 +00:00
|
|
|
# export NIX_DONT_SET_RPATH_FOR_TARGET=1
|
2018-05-22 17:25:35 +00:00
|
|
|
# ''
|
|
|
|
;
|
2017-10-06 05:26:19 +00:00
|
|
|
|
|
|
|
inherit initialPath shell
|
2017-08-15 15:30:45 +00:00
|
|
|
defaultNativeBuildInputs defaultBuildInputs;
|
2015-06-18 17:03:32 +00:00
|
|
|
}
|
2017-07-06 01:47:48 +00:00
|
|
|
// lib.optionalAttrs buildPlatform.isDarwin {
|
2015-11-21 20:06:41 +00:00
|
|
|
__sandboxProfile = stdenvSandboxProfile;
|
2015-06-18 17:03:32 +00:00
|
|
|
__impureHostDeps = __stdenvImpureHostDeps;
|
2014-08-29 20:09:01 +00:00
|
|
|
})
|
2014-02-04 16:18:38 +00:00
|
|
|
|
2019-08-13 21:52:01 +00:00
|
|
|
// {
|
2014-02-04 16:18:38 +00:00
|
|
|
|
2016-08-28 14:56:31 +00:00
|
|
|
meta = {
|
|
|
|
description = "The default build environment for Unix packages in Nixpkgs";
|
|
|
|
platforms = lib.platforms.all;
|
|
|
|
};
|
2014-02-04 16:18:38 +00:00
|
|
|
|
2017-07-06 01:47:48 +00:00
|
|
|
inherit buildPlatform hostPlatform targetPlatform;
|
|
|
|
|
2017-08-15 15:30:45 +00:00
|
|
|
inherit extraNativeBuildInputs extraBuildInputs
|
|
|
|
__extraImpureHostDeps extraSandboxProfile;
|
2017-07-05 23:58:24 +00:00
|
|
|
|
2014-02-04 16:18:38 +00:00
|
|
|
# Utility flags to test the type of platform.
|
2017-05-22 01:37:16 +00:00
|
|
|
inherit (hostPlatform)
|
2021-04-18 20:12:09 +00:00
|
|
|
isDarwin isLinux isSunOS isCygwin isBSD isFreeBSD isOpenBSD
|
2019-01-06 18:57:36 +00:00
|
|
|
isi686 isx86_32 isx86_64
|
|
|
|
is32bit is64bit
|
|
|
|
isAarch32 isAarch64 isMips isBigEndian;
|
2014-02-04 16:18:38 +00:00
|
|
|
|
2020-07-11 20:06:08 +00: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 18:39:58 +00:00
|
|
|
|
2021-08-17 01:16:29 +00:00
|
|
|
mkDerivation = mkDerivationFromStdenv stdenv;
|
2014-07-01 14:43:52 +00:00
|
|
|
|
2014-02-04 16:18:38 +00:00
|
|
|
inherit fetchurlBoot;
|
|
|
|
|
|
|
|
inherit overrides;
|
2014-07-01 14:17:23 +00: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-24 23:07:20 +00:00
|
|
|
inherit cc hasCC;
|
2021-12-19 00:32:35 +00:00
|
|
|
|
|
|
|
# Convenience for doing some very basic shell syntax checking by parsing a script
|
|
|
|
# without running any commands. Because this will also skip `shopt -s extglob`
|
|
|
|
# commands and extglob affects the Bash parser, we enable extglob always.
|
|
|
|
shellDryRun = "${stdenv.shell} -n -O extglob";
|
2014-02-04 16:18:38 +00: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 ...).
|
2021-11-26 22:23:32 +00:00
|
|
|
// extraAttrs
|
|
|
|
); in stdenv-overridable
|