2 lib = import ../../../lib;
3 stdenv-overridable = lib.makeOverridable (
10 # If we don't have a C compiler, we might either have `cc = null` or `cc =
11 # throw ...`, but if we do have a C compiler we should definiely have `cc !=
14 # TODO(@Ericson2314): Add assert without creating infinite recursion
19 allowedRequisites ? null,
21 overrides ? (self: super: { }),
23 disallowedRequisites ? [ ],
25 # The `fetchurl' to use for downloading curl and its dependencies
26 # (see all-packages.nix).
29 setupScript ? ./setup.sh,
31 extraNativeBuildInputs ? [ ],
32 extraBuildInputs ? [ ],
33 __stdenvImpureHostDeps ? [ ],
34 __extraImpureHostDeps ? [ ],
35 stdenvSandboxProfile ? "",
36 extraSandboxProfile ? "",
38 ## Platform parameters
40 ## The "build" "host" "target" terminology below comes from GNU Autotools. See
41 ## its documentation for more information on what those words mean. Note that
42 ## each should always be defined, even when not cross compiling.
44 ## For purposes of bootstrapping, think of each stage as a "sliding window"
45 ## over a list of platforms. Specifically, the host platform of the previous
46 ## stage becomes the build platform of the current one, and likewise the
47 ## target platform of the previous stage becomes the host platform of the
51 # The platform on which packages are built. Consists of `system`, a
52 # string (e.g.,`i686-linux') identifying the most import attributes of the
53 # build platform, and `platform` a set of other details.
56 # The platform on which packages run.
59 # The platform which build tools (especially compilers) build for in this stage,
62 # The implementation of `mkDerivation`, parameterized with the final stdenv so we can tie the knot.
63 # This is convient to have as a parameter so the stdenv "adapters" work better
64 mkDerivationFromStdenv ?
65 stdenv: (import ./make-derivation.nix { inherit lib config; } stdenv).mkDerivation,
69 defaultNativeBuildInputs =
70 extraNativeBuildInputs
72 ../../build-support/setup-hooks/audit-tmpdir.sh
73 ../../build-support/setup-hooks/compress-man-pages.sh
74 ../../build-support/setup-hooks/make-symlinks-relative.sh
75 ../../build-support/setup-hooks/move-docs.sh
76 ../../build-support/setup-hooks/move-lib64.sh
77 ../../build-support/setup-hooks/move-sbin.sh
78 ../../build-support/setup-hooks/move-systemd-user-units.sh
79 ../../build-support/setup-hooks/multiple-outputs.sh
80 ../../build-support/setup-hooks/patch-shebangs.sh
81 ../../build-support/setup-hooks/prune-libtool-files.sh
82 ../../build-support/setup-hooks/reproducible-builds.sh
83 ../../build-support/setup-hooks/set-source-date-epoch-to-latest.sh
84 ../../build-support/setup-hooks/strip.sh
86 ++ lib.optionals hasCC [ cc ];
88 defaultBuildInputs = extraBuildInputs;
90 stdenv = (stdenv-overridable argsStdenv);
93 # The stdenv that we are producing.
95 lib.optionalAttrs (allowedRequisites != null) {
96 allowedRequisites = allowedRequisites ++ defaultNativeBuildInputs ++ defaultBuildInputs;
98 // lib.optionalAttrs config.contentAddressedByDefault {
99 __contentAddressed = true;
100 outputHashAlgo = "sha256";
101 outputHashMode = "recursive";
105 inherit disallowedRequisites;
107 # Nix itself uses the `system` field of a derivation to decide where to
108 # build it. This is a bit confusing for cross compilation.
109 inherit (buildPlatform) system;
120 # We pretty much never need rpaths on Darwin, since all library path references
121 # are absolute unless we go out of our way to make them relative (like with CF)
122 # TODO: This really wants to be in stdenv/darwin but we don't have hostPlatform
123 # there (yet?) so it goes here until then.
126 + lib.optionalString buildPlatform.isDarwin ''
127 export NIX_DONT_SET_RPATH_FOR_BUILD=1
129 + lib.optionalString (hostPlatform.isDarwin || (!hostPlatform.isElf && !hostPlatform.isMacho)) ''
130 export NIX_DONT_SET_RPATH=1
131 export NIX_NO_SELF_RPATH=1
133 + lib.optionalString (hostPlatform.isDarwin && hostPlatform.isMacOS) ''
134 export MACOSX_DEPLOYMENT_TARGET=${hostPlatform.darwinMinVersion}
136 # TODO this should be uncommented, but it causes stupid mass rebuilds due to
137 # `pkgsCross.*.buildPackages` not being the same, resulting in cross-compiling
138 # for a target rebuilding all of `nativeBuildInputs` for that target.
140 # I think the best solution would just be to fixup linux RPATHs so we don't
141 # need to set `-rpath` anywhere.
142 # + lib.optionalString targetPlatform.isDarwin ''
143 # export NIX_DONT_SET_RPATH_FOR_TARGET=1
150 defaultNativeBuildInputs
154 // lib.optionalAttrs buildPlatform.isDarwin {
155 __sandboxProfile = stdenvSandboxProfile;
156 __impureHostDeps = __stdenvImpureHostDeps;
163 description = "The default build environment for Unix packages in Nixpkgs";
164 platforms = lib.platforms.all;
167 inherit buildPlatform hostPlatform targetPlatform;
170 extraNativeBuildInputs
172 __extraImpureHostDeps
176 # Utility flags to test the type of platform.
177 inherit (hostPlatform)
196 # Override `system` so that packages can get the system of the host
197 # platform through `stdenv.system`. `system` is originally set to the
198 # build platform within the derivation above so that Nix directs the build
199 # to correct type of machine.
200 inherit (hostPlatform) system;
202 mkDerivation = mkDerivationFromStdenv stdenv;
204 inherit fetchurlBoot;
210 # Convenience for doing some very basic shell syntax checking by parsing a script
211 # without running any commands. Because this will also skip `shopt -s extglob`
212 # commands and extglob affects the Bash parser, we enable extglob always.
213 shellDryRun = "${stdenv.shell} -n -O extglob";
216 succeedOnFailure = import ../tests/succeedOnFailure.nix { inherit stdenv; };
218 passthru.tests = lib.warn "Use `stdenv.tests` instead. `passthru` is a `mkDerivation` detail." stdenv.tests;
221 # Propagate any extra attributes. For instance, we use this to
222 # "lift" packages like curl from the final stdenv for Linux to
223 # all-packages.nix for that platform (meaning that it has a line
224 # like curl = if stdenv ? curl then stdenv.curl else ...).