lol
1{ system ? builtins.currentSystem }:
2
3with import ../../.. {inherit system;};
4
5rec {
6
7
8 coreutilsMinimal = coreutils.override (args: {
9 # We want coreutils without ACL/attr support.
10 aclSupport = false;
11 attrSupport = false;
12 # Our tooling currently can't handle scripts in bin/, only ELFs and symlinks.
13 singleBinary = "symlinks";
14 });
15
16 tarMinimal = gnutar.override { acl = null; };
17
18 busyboxMinimal = busybox.override {
19 useMusl = true;
20 enableStatic = true;
21 enableMinimal = true;
22 extraConfig = ''
23 CONFIG_ASH y
24 CONFIG_ASH_ECHO y
25 CONFIG_ASH_TEST y
26 CONFIG_ASH_OPTIMIZE_FOR_SIZE y
27 CONFIG_MKDIR y
28 CONFIG_TAR y
29 CONFIG_UNXZ y
30 '';
31 };
32
33 build =
34
35 stdenv.mkDerivation {
36 name = "stdenv-bootstrap-tools";
37
38 buildInputs = [nukeReferences cpio];
39
40 buildCommand = ''
41 set -x
42 mkdir -p $out/bin $out/lib $out/libexec
43
44 # Copy what we need of Glibc.
45 cp -d ${glibc.out}/lib/ld*.so* $out/lib
46 cp -d ${glibc.out}/lib/libc*.so* $out/lib
47 cp -d ${glibc.out}/lib/libc_nonshared.a $out/lib
48 cp -d ${glibc.out}/lib/libm*.so* $out/lib
49 cp -d ${glibc.out}/lib/libdl*.so* $out/lib
50 cp -d ${glibc.out}/lib/librt*.so* $out/lib
51 cp -d ${glibc.out}/lib/libpthread*.so* $out/lib
52 cp -d ${glibc.out}/lib/libnsl*.so* $out/lib
53 cp -d ${glibc.out}/lib/libutil*.so* $out/lib
54 cp -d ${glibc.out}/lib/libnss*.so* $out/lib
55 cp -d ${glibc.out}/lib/libresolv*.so* $out/lib
56 cp -d ${glibc.out}/lib/crt?.o $out/lib
57
58 cp -rL ${glibc.dev}/include $out
59 chmod -R u+w "$out"
60
61 # glibc can contain linker scripts: find them, copy their deps,
62 # and get rid of absolute paths (nuke-refs would make them useless)
63 local lScripts=$(grep --files-with-matches --max-count=1 'GNU ld script' -R "$out/lib")
64 cp -d -t "$out/lib/" $(cat $lScripts | tr " " "\n" | grep -F '${glibc.out}' | sort -u)
65 for f in $lScripts; do
66 substituteInPlace "$f" --replace '${glibc.out}/lib/' ""
67 done
68
69 # Hopefully we won't need these.
70 rm -rf $out/include/mtd $out/include/rdma $out/include/sound $out/include/video
71 find $out/include -name .install -exec rm {} \;
72 find $out/include -name ..install.cmd -exec rm {} \;
73 mv $out/include $out/include-glibc
74
75 # Copy coreutils, bash, etc.
76 cp ${coreutilsMinimal.out}/bin/* $out/bin
77 (cd $out/bin && rm vdir dir sha*sum pinky factor pathchk runcon shuf who whoami shred users)
78
79 cp ${bash.out}/bin/bash $out/bin
80 cp ${findutils.out}/bin/find $out/bin
81 cp ${findutils.out}/bin/xargs $out/bin
82 cp -d ${diffutils.out}/bin/* $out/bin
83 cp -d ${gnused.out}/bin/* $out/bin
84 cp -d ${gnugrep.out}/bin/grep $out/bin
85 cp ${gawk.out}/bin/gawk $out/bin
86 cp -d ${gawk.out}/bin/awk $out/bin
87 cp ${tarMinimal.out}/bin/tar $out/bin
88 cp ${gzip.out}/bin/gzip $out/bin
89 cp ${bzip2.bin}/bin/bzip2 $out/bin
90 cp -d ${gnumake.out}/bin/* $out/bin
91 cp -d ${patch}/bin/* $out/bin
92 cp ${patchelf}/bin/* $out/bin
93
94 cp -d ${gnugrep.pcre.out}/lib/libpcre*.so* $out/lib # needed by grep
95
96 # Copy what we need of GCC.
97 cp -d ${gcc.cc.out}/bin/gcc $out/bin
98 cp -d ${gcc.cc.out}/bin/cpp $out/bin
99 cp -d ${gcc.cc.out}/bin/g++ $out/bin
100 cp -d ${gcc.cc.lib}/lib*/libgcc_s.so* $out/lib
101 cp -d ${gcc.cc.lib}/lib*/libstdc++.so* $out/lib
102 cp -rd ${gcc.cc.out}/lib/gcc $out/lib
103 chmod -R u+w $out/lib
104 rm -f $out/lib/gcc/*/*/include*/linux
105 rm -f $out/lib/gcc/*/*/include*/sound
106 rm -rf $out/lib/gcc/*/*/include*/root
107 rm -f $out/lib/gcc/*/*/include-fixed/asm
108 rm -rf $out/lib/gcc/*/*/plugin
109 #rm -f $out/lib/gcc/*/*/*.a
110 cp -rd ${gcc.cc.out}/libexec/* $out/libexec
111 chmod -R u+w $out/libexec
112 rm -rf $out/libexec/gcc/*/*/plugin
113 mkdir $out/include
114 cp -rd ${gcc.cc.out}/include/c++ $out/include
115 chmod -R u+w $out/include
116 rm -rf $out/include/c++/*/ext/pb_ds
117 rm -rf $out/include/c++/*/ext/parallel
118
119 cp -d ${gmpxx.out}/lib/libgmp*.so* $out/lib
120 cp -d ${mpfr.out}/lib/libmpfr*.so* $out/lib
121 cp -d ${libmpc}/lib/libmpc*.so* $out/lib
122 cp -d ${zlib.out}/lib/libz.so* $out/lib
123 cp -d ${libelf}/lib/libelf.so* $out/lib
124
125 cp -d ${bzip2.out}/lib/libbz2.so* $out/lib
126
127 # Copy binutils.
128 for i in as ld ar ranlib nm strip readelf objdump; do
129 cp ${binutils.out}/bin/$i $out/bin
130 done
131 cp -d ${binutils.lib}/lib/lib*.so* $out/lib
132
133 chmod -R u+w $out
134
135 # Strip executables even further.
136 for i in $out/bin/* $out/libexec/gcc/*/*/*; do
137 if test -x $i -a ! -L $i; then
138 chmod +w $i
139 strip -s $i || true
140 fi
141 done
142
143 nuke-refs $out/bin/*
144 nuke-refs $out/lib/*
145 nuke-refs $out/libexec/gcc/*/*/*
146
147 mkdir $out/.pack
148 mv $out/* $out/.pack
149 mv $out/.pack $out/pack
150
151 mkdir $out/on-server
152 tar cvfJ $out/on-server/bootstrap-tools.tar.xz --hard-dereference --sort=name --numeric-owner --owner=0 --group=0 --mtime=@1 -C $out/pack .
153 cp ${busyboxMinimal}/bin/busybox $out/on-server
154 chmod u+w $out/on-server/busybox
155 nuke-refs $out/on-server/busybox
156 ''; # */
157
158 # The result should not contain any references (store paths) so
159 # that we can safely copy them out of the store and to other
160 # locations in the store.
161 allowedReferences = [];
162 };
163
164 dist = stdenv.mkDerivation {
165 name = "stdenv-bootstrap-tools";
166
167 buildCommand = ''
168 mkdir -p $out/nix-support
169 echo "file tarball ${build}/on-server/bootstrap-tools.tar.xz" >> $out/nix-support/hydra-build-products
170 echo "file busybox ${build}/on-server/busybox" >> $out/nix-support/hydra-build-products
171 '';
172 };
173
174 bootstrapFiles = {
175 # Make them their own store paths to test that busybox still works when the binary is named /nix/store/HASH-busybox
176 busybox = runCommand "busybox" {} "cp ${build}/on-server/busybox $out";
177 bootstrapTools = runCommand "bootstrap-tools.tar.xz" {} "cp ${build}/on-server/bootstrap-tools.tar.xz $out";
178 };
179
180 bootstrapTools = import ./bootstrap-tools { inherit system bootstrapFiles; };
181
182 test = derivation {
183 name = "test-bootstrap-tools";
184 inherit system;
185 builder = bootstrapFiles.busybox;
186 args = [ "ash" "-e" "-c" "eval \"$buildCommand\"" ];
187
188 buildCommand = ''
189 export PATH=${bootstrapTools}/bin
190
191 ls -l
192 mkdir $out
193 mkdir $out/bin
194 sed --version
195 find --version
196 diff --version
197 patch --version
198 make --version
199 awk --version
200 grep --version
201 gcc --version
202
203 ldlinux=$(echo ${bootstrapTools}/lib/ld-linux*.so.?)
204 export CPP="cpp -idirafter ${bootstrapTools}/include-glibc -B${bootstrapTools}"
205 export CC="gcc -idirafter ${bootstrapTools}/include-glibc -B${bootstrapTools} -Wl,-dynamic-linker,$ldlinux -Wl,-rpath,${bootstrapTools}/lib"
206 export CXX="g++ -idirafter ${bootstrapTools}/include-glibc -B${bootstrapTools} -Wl,-dynamic-linker,$ldlinux -Wl,-rpath,${bootstrapTools}/lib"
207
208 echo '#include <stdio.h>' >> foo.c
209 echo '#include <limits.h>' >> foo.c
210 echo 'int main() { printf("Hello World\\n"); return 0; }' >> foo.c
211 $CC -o $out/bin/foo foo.c
212 $out/bin/foo
213
214 echo '#include <iostream>' >> bar.cc
215 echo 'int main() { std::cout << "Hello World\\n"; }' >> bar.cc
216 $CXX -v -o $out/bin/bar bar.cc
217 $out/bin/bar
218
219 tar xvf ${hello.src}
220 cd hello-*
221 ./configure --prefix=$out
222 make
223 make install
224 '';
225 };
226}