Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1let
2 lib = import ../../../lib;
3 stdenv-overridable = lib.makeOverridable (
4
5 argsStdenv@{
6 name ? "stdenv",
7 preHook ? "",
8 initialPath,
9
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 !=
12 # null`.
13 #
14 # TODO(@Ericson2314): Add assert without creating infinite recursion
15 hasCC ? cc != null,
16 cc,
17
18 shell,
19 allowedRequisites ? null,
20 extraAttrs ? { },
21 overrides ? (self: super: { }),
22 config,
23 disallowedRequisites ? [ ],
24
25 # The `fetchurl' to use for downloading curl and its dependencies
26 # (see all-packages.nix).
27 fetchurlBoot,
28
29 setupScript ? ./setup.sh,
30
31 extraNativeBuildInputs ? [ ],
32 extraBuildInputs ? [ ],
33 __stdenvImpureHostDeps ? [ ],
34 __extraImpureHostDeps ? [ ],
35 stdenvSandboxProfile ? "",
36 extraSandboxProfile ? "",
37
38 ## Platform parameters
39 ##
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.
43 ##
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
48 ## current one.
49 ##
50
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.
54 buildPlatform,
55
56 # The platform on which packages run.
57 hostPlatform,
58
59 # The platform which build tools (especially compilers) build for in this stage,
60 targetPlatform,
61
62 # The implementation of `mkDerivation`, parameterized with the final stdenv so we can tie the knot.
63 # This is convenient to have as a parameter so the stdenv "adapters" work better
64 mkDerivationFromStdenv ?
65 stdenv: (import ./make-derivation.nix { inherit lib config; } stdenv).mkDerivation,
66 }:
67
68 let
69 defaultNativeBuildInputs =
70 extraNativeBuildInputs
71 ++ [
72 ../../build-support/setup-hooks/no-broken-symlinks.sh
73 ../../build-support/setup-hooks/audit-tmpdir.sh
74 ../../build-support/setup-hooks/compress-man-pages.sh
75 ../../build-support/setup-hooks/make-symlinks-relative.sh
76 ../../build-support/setup-hooks/move-docs.sh
77 ../../build-support/setup-hooks/move-lib64.sh
78 ../../build-support/setup-hooks/move-sbin.sh
79 ../../build-support/setup-hooks/move-systemd-user-units.sh
80 ../../build-support/setup-hooks/multiple-outputs.sh
81 ../../build-support/setup-hooks/patch-shebangs.sh
82 ../../build-support/setup-hooks/prune-libtool-files.sh
83 ../../build-support/setup-hooks/reproducible-builds.sh
84 ../../build-support/setup-hooks/set-source-date-epoch-to-latest.sh
85 ../../build-support/setup-hooks/strip.sh
86 ]
87 ++ lib.optionals hasCC [ cc ];
88
89 defaultBuildInputs = extraBuildInputs;
90
91 stdenv = (stdenv-overridable argsStdenv);
92
93 in
94 # The stdenv that we are producing.
95 derivation (
96 lib.optionalAttrs (allowedRequisites != null) {
97 allowedRequisites = allowedRequisites ++ defaultNativeBuildInputs ++ defaultBuildInputs;
98 }
99 // lib.optionalAttrs config.contentAddressedByDefault {
100 __contentAddressed = true;
101 outputHashAlgo = "sha256";
102 outputHashMode = "recursive";
103 }
104 // {
105 inherit name;
106 inherit disallowedRequisites;
107
108 # Nix itself uses the `system` field of a derivation to decide where to
109 # build it. This is a bit confusing for cross compilation.
110 inherit (buildPlatform) system;
111
112 builder = shell;
113
114 args = [
115 "-e"
116 ./builder.sh
117 ];
118
119 setup = setupScript;
120
121 # We pretty much never need rpaths on Darwin, since all library path references
122 # are absolute unless we go out of our way to make them relative (like with CF)
123 # TODO: This really wants to be in stdenv/darwin but we don't have hostPlatform
124 # there (yet?) so it goes here until then.
125 preHook =
126 preHook
127 + lib.optionalString buildPlatform.isDarwin ''
128 export NIX_DONT_SET_RPATH_FOR_BUILD=1
129 ''
130 + lib.optionalString (hostPlatform.isDarwin || (!hostPlatform.isElf && !hostPlatform.isMacho)) ''
131 export NIX_DONT_SET_RPATH=1
132 export NIX_NO_SELF_RPATH=1
133 ''
134 + lib.optionalString (hostPlatform.isDarwin && hostPlatform.isMacOS) ''
135 export MACOSX_DEPLOYMENT_TARGET=${hostPlatform.darwinMinVersion}
136 ''
137 # TODO this should be uncommented, but it causes stupid mass rebuilds due to
138 # `pkgsCross.*.buildPackages` not being the same, resulting in cross-compiling
139 # for a target rebuilding all of `nativeBuildInputs` for that target.
140 #
141 # I think the best solution would just be to fixup linux RPATHs so we don't
142 # need to set `-rpath` anywhere.
143 # + lib.optionalString targetPlatform.isDarwin ''
144 # export NIX_DONT_SET_RPATH_FOR_TARGET=1
145 # ''
146 ;
147
148 inherit
149 initialPath
150 shell
151 defaultNativeBuildInputs
152 defaultBuildInputs
153 ;
154 }
155 // lib.optionalAttrs buildPlatform.isDarwin {
156 __sandboxProfile = stdenvSandboxProfile;
157 __impureHostDeps = __stdenvImpureHostDeps;
158 }
159 )
160
161 // {
162
163 meta = {
164 description = "The default build environment for Unix packages in Nixpkgs";
165 platforms = lib.platforms.all;
166 };
167
168 inherit buildPlatform hostPlatform targetPlatform;
169
170 inherit
171 extraNativeBuildInputs
172 extraBuildInputs
173 __extraImpureHostDeps
174 extraSandboxProfile
175 ;
176
177 # Utility flags to test the type of platform.
178 inherit (hostPlatform)
179 isDarwin
180 isLinux
181 isSunOS
182 isCygwin
183 isBSD
184 isFreeBSD
185 isOpenBSD
186 isi686
187 isx86_32
188 isx86_64
189 is32bit
190 is64bit
191 isAarch32
192 isAarch64
193 isMips
194 isBigEndian
195 ;
196
197 # Override `system` so that packages can get the system of the host
198 # platform through `stdenv.system`. `system` is originally set to the
199 # build platform within the derivation above so that Nix directs the build
200 # to correct type of machine.
201 inherit (hostPlatform) system;
202
203 mkDerivation = mkDerivationFromStdenv stdenv;
204
205 inherit fetchurlBoot;
206
207 inherit overrides;
208
209 inherit cc hasCC;
210
211 # Convenience for doing some very basic shell syntax checking by parsing a script
212 # without running any commands. Because this will also skip `shopt -s extglob`
213 # commands and extglob affects the Bash parser, we enable extglob always.
214 shellDryRun = "${stdenv.shell} -n -O extglob";
215
216 tests = {
217 succeedOnFailure = import ../tests/succeedOnFailure.nix { inherit stdenv; };
218 };
219 passthru.tests = lib.warn "Use `stdenv.tests` instead. `passthru` is a `mkDerivation` detail." stdenv.tests;
220 }
221
222 # Propagate any extra attributes. For instance, we use this to
223 # "lift" packages like curl from the final stdenv for Linux to
224 # all-packages.nix for that platform (meaning that it has a line
225 # like curl = if stdenv ? curl then stdenv.curl else ...).
226 // extraAttrs
227 );
228in
229stdenv-overridable