2021-12-19 01:06:50 +00:00
|
|
|
let lib = import ../../../lib; stdenv-overridable = lib.makeOverridable (
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-12-19 01:06:50 +00:00
|
|
|
argsStdenv@{ name ? "stdenv", preHook ? "", initialPath
|
2020-04-24 23:36:52 +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
|
|
|
|
, allowedRequisites ? null, extraAttrs ? {}, overrides ? (self: super: {}), config
|
2022-08-12 12:06:08 +00:00
|
|
|
, disallowedRequisites ? []
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
, # The `fetchurl' to use for downloading curl and its dependencies
|
|
|
|
# (see all-packages.nix).
|
|
|
|
fetchurlBoot
|
|
|
|
|
|
|
|
, setupScript ? ./setup.sh
|
|
|
|
|
|
|
|
, extraNativeBuildInputs ? []
|
|
|
|
, extraBuildInputs ? []
|
|
|
|
, __stdenvImpureHostDeps ? []
|
|
|
|
, __extraImpureHostDeps ? []
|
|
|
|
, stdenvSandboxProfile ? ""
|
|
|
|
, extraSandboxProfile ? ""
|
|
|
|
|
|
|
|
## 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-22 07:53:02 +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; }
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
defaultNativeBuildInputs = extraNativeBuildInputs ++
|
|
|
|
[ ../../build-support/setup-hooks/move-docs.sh
|
|
|
|
../../build-support/setup-hooks/make-symlinks-relative.sh
|
|
|
|
../../build-support/setup-hooks/compress-man-pages.sh
|
|
|
|
../../build-support/setup-hooks/strip.sh
|
|
|
|
../../build-support/setup-hooks/patch-shebangs.sh
|
|
|
|
../../build-support/setup-hooks/prune-libtool-files.sh
|
|
|
|
]
|
|
|
|
# FIXME this on Darwin; see
|
|
|
|
# https://github.com/NixOS/nixpkgs/commit/94d164dd7#commitcomment-22030369
|
2020-10-16 20:44:37 +00:00
|
|
|
++ lib.optionals hostPlatform.isLinux [
|
|
|
|
../../build-support/setup-hooks/audit-tmpdir.sh
|
|
|
|
../../build-support/setup-hooks/move-systemd-user-units.sh
|
|
|
|
]
|
2020-04-24 23:36:52 +00:00
|
|
|
++ [
|
|
|
|
../../build-support/setup-hooks/multiple-outputs.sh
|
|
|
|
../../build-support/setup-hooks/move-sbin.sh
|
|
|
|
../../build-support/setup-hooks/move-lib64.sh
|
|
|
|
../../build-support/setup-hooks/set-source-date-epoch-to-latest.sh
|
2020-12-03 08:41:04 +00:00
|
|
|
../../build-support/setup-hooks/reproducible-builds.sh
|
2020-04-24 23:36:52 +00:00
|
|
|
# TODO use lib.optional instead
|
|
|
|
(if hasCC then cc else null)
|
|
|
|
];
|
|
|
|
|
|
|
|
defaultBuildInputs = extraBuildInputs;
|
|
|
|
|
2021-12-19 01:06:50 +00:00
|
|
|
stdenv = (stdenv-overridable argsStdenv);
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# The stdenv that we are producing.
|
2021-12-19 01:06:50 +00:00
|
|
|
in
|
2020-04-24 23:36:52 +00:00
|
|
|
derivation (
|
|
|
|
lib.optionalAttrs (allowedRequisites != null) {
|
|
|
|
allowedRequisites = allowedRequisites
|
|
|
|
++ defaultNativeBuildInputs ++ defaultBuildInputs;
|
|
|
|
}
|
2022-04-27 09:35:20 +00:00
|
|
|
// lib.optionalAttrs config.contentAddressedByDefault {
|
2021-05-03 20:48:10 +00:00
|
|
|
__contentAddressed = true;
|
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
outputHashMode = "recursive";
|
|
|
|
}
|
2020-04-24 23:36:52 +00:00
|
|
|
// {
|
|
|
|
inherit name;
|
2022-08-12 12:06:08 +00:00
|
|
|
inherit disallowedRequisites;
|
2020-04-24 23:36:52 +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;
|
|
|
|
|
|
|
|
builder = shell;
|
|
|
|
|
|
|
|
args = ["-e" ./builder.sh];
|
|
|
|
|
|
|
|
setup = setupScript;
|
|
|
|
|
|
|
|
# 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.
|
2022-01-26 04:04:25 +00:00
|
|
|
preHook = preHook + lib.optionalString buildPlatform.isDarwin ''
|
2020-06-18 07:06:33 +00:00
|
|
|
export NIX_DONT_SET_RPATH_FOR_BUILD=1
|
2020-04-24 23:36:52 +00:00
|
|
|
'' + lib.optionalString (hostPlatform.isDarwin || (hostPlatform.parsed.kernel.execFormat != lib.systems.parse.execFormats.elf && hostPlatform.parsed.kernel.execFormat != lib.systems.parse.execFormats.macho)) ''
|
|
|
|
export NIX_DONT_SET_RPATH=1
|
|
|
|
export NIX_NO_SELF_RPATH=1
|
2021-04-26 19:14:03 +00:00
|
|
|
'' + lib.optionalString (hostPlatform.isDarwin && hostPlatform.isMacOS) ''
|
|
|
|
export MACOSX_DEPLOYMENT_TARGET=${hostPlatform.darwinMinVersion}
|
2020-04-24 23:36:52 +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-06-18 07:06:33 +00:00
|
|
|
# export NIX_DONT_SET_RPATH_FOR_TARGET=1
|
2020-04-24 23:36:52 +00:00
|
|
|
# ''
|
|
|
|
;
|
|
|
|
|
|
|
|
inherit initialPath shell
|
|
|
|
defaultNativeBuildInputs defaultBuildInputs;
|
|
|
|
}
|
|
|
|
// lib.optionalAttrs buildPlatform.isDarwin {
|
|
|
|
__sandboxProfile = stdenvSandboxProfile;
|
|
|
|
__impureHostDeps = __stdenvImpureHostDeps;
|
|
|
|
})
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "The default build environment for Unix packages in Nixpkgs";
|
|
|
|
platforms = lib.platforms.all;
|
|
|
|
};
|
|
|
|
|
|
|
|
inherit buildPlatform hostPlatform targetPlatform;
|
|
|
|
|
|
|
|
inherit extraNativeBuildInputs extraBuildInputs
|
|
|
|
__extraImpureHostDeps extraSandboxProfile;
|
|
|
|
|
|
|
|
# Utility flags to test the type of platform.
|
|
|
|
inherit (hostPlatform)
|
2021-04-22 02:08:21 +00:00
|
|
|
isDarwin isLinux isSunOS isCygwin isBSD isFreeBSD isOpenBSD
|
2020-04-24 23:36:52 +00:00
|
|
|
isi686 isx86_32 isx86_64
|
|
|
|
is32bit is64bit
|
|
|
|
isAarch32 isAarch64 isMips isBigEndian;
|
|
|
|
|
2020-07-18 16:06:22 +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;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-08-22 07:53:02 +00:00
|
|
|
mkDerivation = mkDerivationFromStdenv stdenv;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
inherit fetchurlBoot;
|
|
|
|
|
|
|
|
inherit overrides;
|
|
|
|
|
|
|
|
inherit cc hasCC;
|
2022-01-26 04:04:25 +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";
|
2022-12-17 10:02:37 +00:00
|
|
|
|
|
|
|
tests = {
|
|
|
|
succeedOnFailure = import ../tests/succeedOnFailure.nix { inherit stdenv; };
|
|
|
|
};
|
|
|
|
passthru.tests = lib.warn "Use `stdenv.tests` instead. `passthru` is a `mkDerivation` detail." stdenv.tests;
|
2020-04-24 23:36:52 +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-12-19 01:06:50 +00:00
|
|
|
// extraAttrs
|
|
|
|
); in stdenv-overridable
|