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