1{
2 lib,
3 localSystem,
4 crossSystem,
5 config,
6 overlays,
7 crossOverlays ? [ ],
8}:
9
10assert crossSystem == localSystem;
11
12let
13 inherit (localSystem) system;
14
15 shell =
16 if system == "i686-freebsd" || system == "x86_64-freebsd" then
17 "/usr/local/bin/bash"
18 else
19 "/bin/bash";
20
21 path =
22 (lib.optionals (system == "i686-solaris") [ "/usr/gnu" ])
23 ++ (lib.optionals (system == "i686-netbsd") [ "/usr/pkg" ])
24 ++ (lib.optionals (system == "x86_64-solaris") [ "/opt/local/gnu" ])
25 ++ [
26 "/"
27 "/usr"
28 "/usr/local"
29 ];
30
31 prehookBase = ''
32 # Disable purity tests; it's allowed (even needed) to link to
33 # libraries outside the Nix store (like the C library).
34 export NIX_ENFORCE_PURITY=
35 export NIX_ENFORCE_NO_NATIVE="''${NIX_ENFORCE_NO_NATIVE-1}"
36 '';
37
38 prehookFreeBSD = ''
39 ${prehookBase}
40
41 alias make=gmake
42 alias tar=gtar
43 alias sed=gsed
44 export MAKE=gmake
45 shopt -s expand_aliases
46 '';
47
48 prehookOpenBSD = ''
49 ${prehookBase}
50
51 alias make=gmake
52 alias grep=ggrep
53 alias mv=gmv
54 alias ln=gln
55 alias sed=gsed
56 alias tar=gtar
57
58 export MAKE=gmake
59 shopt -s expand_aliases
60 '';
61
62 prehookNetBSD = ''
63 ${prehookBase}
64
65 alias make=gmake
66 alias sed=gsed
67 alias tar=gtar
68 export MAKE=gmake
69 shopt -s expand_aliases
70 '';
71
72 # prevent libtool from failing to find dynamic libraries
73 prehookCygwin = ''
74 ${prehookBase}
75
76 shopt -s expand_aliases
77 export lt_cv_deplibs_check_method=pass_all
78 '';
79
80 extraNativeBuildInputsCygwin = [
81 ../cygwin/all-buildinputs-as-runtimedep.sh
82 ../cygwin/wrap-exes-to-find-dlls.sh
83 ]
84 ++ (
85 if system == "i686-cygwin" then
86 [
87 ../cygwin/rebase-i686.sh
88 ]
89 else if system == "x86_64-cygwin" then
90 [
91 ../cygwin/rebase-x86_64.sh
92 ]
93 else
94 [ ]
95 );
96
97 # A function that builds a "native" stdenv (one that uses tools in
98 # /usr etc.).
99 makeStdenv =
100 {
101 cc,
102 fetchurl,
103 extraPath ? [ ],
104 overrides ? (self: super: { }),
105 extraNativeBuildInputs ? [ ],
106 }:
107
108 import ../generic {
109 buildPlatform = localSystem;
110 hostPlatform = localSystem;
111 targetPlatform = localSystem;
112
113 preHook =
114 if system == "i686-freebsd" then
115 prehookFreeBSD
116 else if system == "x86_64-freebsd" then
117 prehookFreeBSD
118 else if system == "i686-openbsd" then
119 prehookOpenBSD
120 else if system == "i686-netbsd" then
121 prehookNetBSD
122 else if system == "i686-cygwin" then
123 prehookCygwin
124 else if system == "x86_64-cygwin" then
125 prehookCygwin
126 else
127 prehookBase;
128
129 extraNativeBuildInputs =
130 extraNativeBuildInputs
131 ++ (
132 if system == "i686-cygwin" then
133 extraNativeBuildInputsCygwin
134 else if system == "x86_64-cygwin" then
135 extraNativeBuildInputsCygwin
136 else
137 [ ]
138 );
139
140 initialPath = extraPath ++ path;
141
142 fetchurlBoot = fetchurl;
143
144 inherit
145 shell
146 cc
147 overrides
148 config
149 ;
150 };
151
152in
153
154[
155
156 (
157 { }:
158 rec {
159 __raw = true;
160
161 stdenv = makeStdenv {
162 cc = null;
163 fetchurl = null;
164 };
165 stdenvNoCC = stdenv;
166
167 cc =
168 let
169 nativePrefix =
170 {
171 # switch
172 i686-solaris = "/usr/gnu";
173 x86_64-solaris = "/opt/local/gcc47";
174 }
175 .${system} or "/usr";
176 in
177 import ../../build-support/cc-wrapper {
178 name = "cc-native";
179 nativeTools = true;
180 nativeLibc = true;
181 inherit lib nativePrefix;
182 bintools = import ../../build-support/bintools-wrapper {
183 name = "bintools";
184 inherit lib stdenvNoCC nativePrefix;
185 nativeTools = true;
186 nativeLibc = true;
187 };
188 inherit stdenvNoCC;
189 };
190
191 fetchurl = import ../../build-support/fetchurl {
192 inherit lib stdenvNoCC;
193 # Curl should be in /usr/bin or so.
194 curl = null;
195 };
196
197 }
198 )
199
200 # First build a stdenv based only on tools outside the store.
201 (prevStage: {
202 inherit config overlays;
203 stdenv =
204 makeStdenv {
205 inherit (prevStage) cc fetchurl;
206 overrides = self: super: { inherit (prevStage) fetchurl; };
207 }
208 // {
209 inherit (prevStage) fetchurl;
210 };
211 })
212
213 # Using that, build a stdenv that adds the ‘xz’ command (which most systems
214 # don't have, so we mustn't rely on the native environment providing it).
215 (prevStage: {
216 inherit config overlays;
217 stdenv = makeStdenv {
218 inherit (prevStage.stdenv) cc fetchurl;
219 extraPath = [ prevStage.xz ];
220 overrides = self: super: { inherit (prevStage) fetchurl xz; };
221 extraNativeBuildInputs = if localSystem.isLinux then [ prevStage.patchelf ] else [ ];
222 };
223 })
224
225]