1 let lib = import ../../../lib; stdenv-overridable = lib.makeOverridable (
3 argsStdenv@{ name ? "stdenv", preHook ? "", initialPath
5 , # If we don't have a C compiler, we might either have `cc = null` or `cc =
6 # throw ...`, but if we do have a C compiler we should definiely have `cc !=
9 # TODO(@Ericson2314): Add assert without creating infinite recursion
10 hasCC ? cc != null, cc
13 , allowedRequisites ? null, extraAttrs ? {}, overrides ? (self: super: {}), config
14 , disallowedRequisites ? []
16 , # The `fetchurl' to use for downloading curl and its dependencies
17 # (see all-packages.nix).
20 , setupScript ? ./setup.sh
22 , extraNativeBuildInputs ? []
23 , extraBuildInputs ? []
24 , __stdenvImpureHostDeps ? []
25 , __extraImpureHostDeps ? []
26 , stdenvSandboxProfile ? ""
27 , extraSandboxProfile ? ""
29 ## Platform parameters
31 ## The "build" "host" "target" terminology below comes from GNU Autotools. See
32 ## its documentation for more information on what those words mean. Note that
33 ## each should always be defined, even when not cross compiling.
35 ## For purposes of bootstrapping, think of each stage as a "sliding window"
36 ## over a list of platforms. Specifically, the host platform of the previous
37 ## stage becomes the build platform of the current one, and likewise the
38 ## target platform of the previous stage becomes the host platform of the
42 , # The platform on which packages are built. Consists of `system`, a
43 # string (e.g.,`i686-linux') identifying the most import attributes of the
44 # build platform, and `platform` a set of other details.
47 , # The platform on which packages run.
50 , # The platform which build tools (especially compilers) build for in this stage,
53 , # The implementation of `mkDerivation`, parameterized with the final stdenv so we can tie the knot.
54 # This is convient to have as a parameter so the stdenv "adapters" work better
55 mkDerivationFromStdenv ? stdenv: (import ./make-derivation.nix { inherit lib config; } stdenv).mkDerivation
59 defaultNativeBuildInputs = extraNativeBuildInputs ++
61 ../../build-support/setup-hooks/audit-tmpdir.sh
62 ../../build-support/setup-hooks/compress-man-pages.sh
63 ../../build-support/setup-hooks/make-symlinks-relative.sh
64 ../../build-support/setup-hooks/move-docs.sh
65 ../../build-support/setup-hooks/move-lib64.sh
66 ../../build-support/setup-hooks/move-sbin.sh
67 ../../build-support/setup-hooks/move-systemd-user-units.sh
68 ../../build-support/setup-hooks/multiple-outputs.sh
69 ../../build-support/setup-hooks/patch-shebangs.sh
70 ../../build-support/setup-hooks/prune-libtool-files.sh
71 ../../build-support/setup-hooks/reproducible-builds.sh
72 ../../build-support/setup-hooks/set-source-date-epoch-to-latest.sh
73 ../../build-support/setup-hooks/strip.sh
74 ] ++ lib.optionals hasCC [ cc ];
76 defaultBuildInputs = extraBuildInputs;
78 stdenv = (stdenv-overridable argsStdenv);
80 # The stdenv that we are producing.
83 lib.optionalAttrs (allowedRequisites != null) {
84 allowedRequisites = allowedRequisites
85 ++ defaultNativeBuildInputs ++ defaultBuildInputs;
87 // lib.optionalAttrs config.contentAddressedByDefault {
88 __contentAddressed = true;
89 outputHashAlgo = "sha256";
90 outputHashMode = "recursive";
94 inherit disallowedRequisites;
96 # Nix itself uses the `system` field of a derivation to decide where to
97 # build it. This is a bit confusing for cross compilation.
98 inherit (buildPlatform) system;
102 args = ["-e" ./builder.sh];
106 # We pretty much never need rpaths on Darwin, since all library path references
107 # are absolute unless we go out of our way to make them relative (like with CF)
108 # TODO: This really wants to be in stdenv/darwin but we don't have hostPlatform
109 # there (yet?) so it goes here until then.
110 preHook = preHook + lib.optionalString buildPlatform.isDarwin ''
111 export NIX_DONT_SET_RPATH_FOR_BUILD=1
112 '' + lib.optionalString (hostPlatform.isDarwin || (!hostPlatform.isElf && !hostPlatform.isMacho)) ''
113 export NIX_DONT_SET_RPATH=1
114 export NIX_NO_SELF_RPATH=1
115 '' + lib.optionalString (hostPlatform.isDarwin && hostPlatform.isMacOS) ''
116 export MACOSX_DEPLOYMENT_TARGET=${hostPlatform.darwinMinVersion}
118 # TODO this should be uncommented, but it causes stupid mass rebuilds. I
119 # think the best solution would just be to fixup linux RPATHs so we don't
120 # need to set `-rpath` anywhere.
121 # + lib.optionalString targetPlatform.isDarwin ''
122 # export NIX_DONT_SET_RPATH_FOR_TARGET=1
126 inherit initialPath shell
127 defaultNativeBuildInputs defaultBuildInputs;
129 // lib.optionalAttrs buildPlatform.isDarwin {
130 __sandboxProfile = stdenvSandboxProfile;
131 __impureHostDeps = __stdenvImpureHostDeps;
137 description = "The default build environment for Unix packages in Nixpkgs";
138 platforms = lib.platforms.all;
141 inherit buildPlatform hostPlatform targetPlatform;
143 inherit extraNativeBuildInputs extraBuildInputs
144 __extraImpureHostDeps extraSandboxProfile;
146 # Utility flags to test the type of platform.
147 inherit (hostPlatform)
148 isDarwin isLinux isSunOS isCygwin isBSD isFreeBSD isOpenBSD
149 isi686 isx86_32 isx86_64
151 isAarch32 isAarch64 isMips isBigEndian;
153 # Override `system` so that packages can get the system of the host
154 # platform through `stdenv.system`. `system` is originally set to the
155 # build platform within the derivation above so that Nix directs the build
156 # to correct type of machine.
157 inherit (hostPlatform) system;
159 mkDerivation = mkDerivationFromStdenv stdenv;
161 inherit fetchurlBoot;
167 # Convenience for doing some very basic shell syntax checking by parsing a script
168 # without running any commands. Because this will also skip `shopt -s extglob`
169 # commands and extglob affects the Bash parser, we enable extglob always.
170 shellDryRun = "${stdenv.shell} -n -O extglob";
173 succeedOnFailure = import ../tests/succeedOnFailure.nix { inherit stdenv; };
175 passthru.tests = lib.warn "Use `stdenv.tests` instead. `passthru` is a `mkDerivation` detail." stdenv.tests;
178 # Propagate any extra attributes. For instance, we use this to
179 # "lift" packages like curl from the final stdenv for Linux to
180 # all-packages.nix for that platform (meaning that it has a line
181 # like curl = if stdenv ? curl then stdenv.curl else ...).
183 ); in stdenv-overridable