2021-11-26 23:23:32 +01:00
|
|
|
let lib = import ../../../lib; stdenv-overridable = lib.makeOverridable (
|
2014-02-04 17:18:38 +01:00
|
|
|
|
2021-11-26 23:23:32 +01: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-25 00:07:20 +01: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 17:10:47 +01:00
|
|
|
, allowedRequisites ? null, extraAttrs ? {}, overrides ? (self: super: {}), config
|
2022-04-14 08:13:33 +02:00
|
|
|
, disallowedRequisites ? []
|
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
|
2021-08-17 03:16:29 +02: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
|
2024-03-11 17:06:02 +01:00
|
|
|
mkDerivationFromStdenv ? stdenv: (import ./make-derivation.nix { inherit lib config; } stdenv).mkDerivation
|
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 ++
|
2022-12-13 00:10:52 +01:00
|
|
|
[
|
2019-08-19 16:05:44 +02:00
|
|
|
../../build-support/setup-hooks/audit-tmpdir.sh
|
2022-12-13 00:10:52 +01:00
|
|
|
../../build-support/setup-hooks/compress-man-pages.sh
|
|
|
|
../../build-support/setup-hooks/make-symlinks-relative.sh
|
|
|
|
../../build-support/setup-hooks/move-docs.sh
|
|
|
|
../../build-support/setup-hooks/move-lib64.sh
|
|
|
|
../../build-support/setup-hooks/move-sbin.sh
|
2019-08-19 16:05:44 +02:00
|
|
|
../../build-support/setup-hooks/move-systemd-user-units.sh
|
2014-08-30 08:27:43 +02:00
|
|
|
../../build-support/setup-hooks/multiple-outputs.sh
|
2022-12-13 00:10:52 +01:00
|
|
|
../../build-support/setup-hooks/patch-shebangs.sh
|
|
|
|
../../build-support/setup-hooks/prune-libtool-files.sh
|
2020-10-31 17:29:54 +01:00
|
|
|
../../build-support/setup-hooks/reproducible-builds.sh
|
2022-12-13 00:10:52 +01:00
|
|
|
../../build-support/setup-hooks/set-source-date-epoch-to-latest.sh
|
2023-07-31 11:20:15 +02:00
|
|
|
../../build-support/setup-hooks/strip.sh
|
2022-12-12 23:34:48 +01:00
|
|
|
] ++ lib.optionals hasCC [ cc ];
|
2014-06-27 13:33:05 +02:00
|
|
|
|
2017-08-15 17:30:45 +02:00
|
|
|
defaultBuildInputs = extraBuildInputs;
|
|
|
|
|
2021-11-26 23:23:32 +01:00
|
|
|
stdenv = (stdenv-overridable argsStdenv);
|
|
|
|
|
2014-02-04 17:18:38 +01:00
|
|
|
# The stdenv that we are producing.
|
2021-11-26 23:23:32 +01:00
|
|
|
in
|
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;
|
|
|
|
}
|
2022-04-27 22:21:32 +02:00
|
|
|
// lib.optionalAttrs config.contentAddressedByDefault {
|
2021-04-26 17:21:17 +02:00
|
|
|
__contentAddressed = true;
|
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
outputHashMode = "recursive";
|
|
|
|
}
|
2017-08-15 17:30:45 +02:00
|
|
|
// {
|
2017-07-06 03:47:48 +02:00
|
|
|
inherit name;
|
2022-04-14 08:13:33 +02:00
|
|
|
inherit disallowedRequisites;
|
2017-07-06 03:47:48 +02: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 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.
|
2021-12-19 01:32:35 +01:00
|
|
|
preHook = preHook + lib.optionalString buildPlatform.isDarwin ''
|
2020-04-28 06:08:48 +02:00
|
|
|
export NIX_DONT_SET_RPATH_FOR_BUILD=1
|
2024-01-08 02:43:33 +01:00
|
|
|
'' + lib.optionalString (hostPlatform.isDarwin || (!hostPlatform.isElf && !hostPlatform.isMacho)) ''
|
2019-01-30 03:01:24 +01:00
|
|
|
export NIX_DONT_SET_RPATH=1
|
|
|
|
export NIX_NO_SELF_RPATH=1
|
2021-02-05 08:24:43 +01:00
|
|
|
'' + lib.optionalString (hostPlatform.isDarwin && hostPlatform.isMacOS) ''
|
|
|
|
export MACOSX_DEPLOYMENT_TARGET=${hostPlatform.darwinMinVersion}
|
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)
|
2021-04-18 22:12:09 +02:00
|
|
|
isDarwin isLinux isSunOS isCygwin isBSD 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
|
|
|
|
2021-08-17 03:16:29 +02:00
|
|
|
mkDerivation = mkDerivationFromStdenv stdenv;
|
2014-07-01 16:43:52 +02:00
|
|
|
|
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;
|
2021-12-19 01:32:35 +01: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";
|
2022-11-14 19:03:35 +01:00
|
|
|
|
|
|
|
tests = {
|
|
|
|
succeedOnFailure = import ../tests/succeedOnFailure.nix { inherit stdenv; };
|
|
|
|
};
|
|
|
|
passthru.tests = lib.warn "Use `stdenv.tests` instead. `passthru` is a `mkDerivation` detail." stdenv.tests;
|
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 ...).
|
2021-11-26 23:23:32 +01:00
|
|
|
// extraAttrs
|
|
|
|
); in stdenv-overridable
|