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