2014-10-29 13:36:03 +01:00
|
|
|
{ system ? builtins.currentSystem }:
|
2007-12-03 16:40:29 +01:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
with import ../../top-level/all-packages.nix {inherit system;};
|
2006-10-19 20:03:13 +02:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
rec {
|
2006-10-19 20:03:13 +02:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
|
|
|
|
# We want coreutils without ACL support.
|
2014-10-29 13:36:03 +01:00
|
|
|
coreutilsMinimal = coreutils.override (args: {
|
2009-01-30 10:27:15 +01:00
|
|
|
aclSupport = false;
|
|
|
|
});
|
|
|
|
|
2014-10-29 13:36:03 +01:00
|
|
|
curlMinimal = curl.override {
|
2009-01-30 10:27:15 +01:00
|
|
|
zlibSupport = false;
|
|
|
|
sslSupport = false;
|
2014-10-29 13:36:03 +01:00
|
|
|
scpSupport = false;
|
2006-10-23 22:20:25 +02:00
|
|
|
};
|
|
|
|
|
2014-10-29 13:36:03 +01:00
|
|
|
busyboxMinimal = busybox.override {
|
|
|
|
enableStatic = true;
|
|
|
|
enableMinimal = true;
|
2010-08-21 14:50:49 +02:00
|
|
|
extraConfig = ''
|
|
|
|
CONFIG_ASH y
|
|
|
|
CONFIG_ASH_BUILTIN_ECHO y
|
|
|
|
CONFIG_ASH_BUILTIN_TEST y
|
2014-10-29 13:36:03 +01:00
|
|
|
CONFIG_ASH_OPTIMIZE_FOR_SIZE y
|
2010-08-21 14:50:49 +02:00
|
|
|
CONFIG_MKDIR y
|
2014-10-29 13:36:03 +01:00
|
|
|
CONFIG_TAR y
|
|
|
|
CONFIG_UNXZ y
|
2010-08-21 14:50:49 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-10-27 12:31:53 +01:00
|
|
|
build =
|
2006-10-28 00:50:58 +02:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "build";
|
|
|
|
|
|
|
|
buildInputs = [nukeReferences cpio];
|
|
|
|
|
|
|
|
buildCommand = ''
|
2014-10-27 12:31:53 +01:00
|
|
|
set -x
|
2012-01-18 21:16:00 +01:00
|
|
|
mkdir -p $out/bin $out/lib $out/libexec
|
2009-01-30 10:27:15 +01:00
|
|
|
|
|
|
|
# Copy what we need of Glibc.
|
2010-08-21 14:50:49 +02:00
|
|
|
cp -d ${glibc}/lib/ld*.so* $out/lib
|
2009-01-30 10:27:15 +01:00
|
|
|
cp -d ${glibc}/lib/libc*.so* $out/lib
|
|
|
|
cp -d ${glibc}/lib/libc_nonshared.a $out/lib
|
|
|
|
cp -d ${glibc}/lib/libm*.so* $out/lib
|
|
|
|
cp -d ${glibc}/lib/libdl*.so* $out/lib
|
|
|
|
cp -d ${glibc}/lib/librt*.so* $out/lib
|
|
|
|
cp -d ${glibc}/lib/libpthread*.so* $out/lib
|
|
|
|
cp -d ${glibc}/lib/libnsl*.so* $out/lib
|
|
|
|
cp -d ${glibc}/lib/libutil*.so* $out/lib
|
|
|
|
cp -d ${glibc}/lib/crt?.o $out/lib
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
cp -rL ${glibc}/include $out
|
|
|
|
chmod -R u+w $out/include
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
# Hopefully we won't need these.
|
|
|
|
rm -rf $out/include/mtd $out/include/rdma $out/include/sound $out/include/video
|
2009-06-22 16:28:07 +02:00
|
|
|
find $out/include -name .install -exec rm {} \;
|
|
|
|
find $out/include -name ..install.cmd -exec rm {} \;
|
2009-01-30 10:27:15 +01:00
|
|
|
mv $out/include $out/include-glibc
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
# Copy coreutils, bash, etc.
|
2014-10-29 13:36:03 +01:00
|
|
|
cp ${coreutilsMinimal}/bin/* $out/bin
|
2009-01-30 10:27:15 +01:00
|
|
|
(cd $out/bin && rm vdir dir sha*sum pinky factor pathchk runcon shuf who whoami shred users)
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
cp ${bash}/bin/bash $out/bin
|
|
|
|
cp ${findutils}/bin/find $out/bin
|
|
|
|
cp ${findutils}/bin/xargs $out/bin
|
|
|
|
cp -d ${diffutils}/bin/* $out/bin
|
|
|
|
cp -d ${gnused}/bin/* $out/bin
|
2014-10-29 13:36:03 +01:00
|
|
|
cp -d ${gnugrep}/bin/grep $out/bin
|
2009-01-30 10:27:15 +01:00
|
|
|
cp ${gawk}/bin/gawk $out/bin
|
|
|
|
cp -d ${gawk}/bin/awk $out/bin
|
|
|
|
cp ${gnutar}/bin/tar $out/bin
|
|
|
|
cp ${gzip}/bin/gzip $out/bin
|
|
|
|
cp ${bzip2}/bin/bzip2 $out/bin
|
|
|
|
cp -d ${gnumake}/bin/* $out/bin
|
|
|
|
cp -d ${patch}/bin/* $out/bin
|
2010-08-01 22:57:13 +02:00
|
|
|
cp ${patchelf}/bin/* $out/bin
|
2014-10-29 13:36:03 +01:00
|
|
|
cp ${curlMinimal}/bin/curl $out/bin
|
|
|
|
cp -d ${curlMinimal}/lib/libcurl* $out/lib
|
2009-01-30 10:27:15 +01:00
|
|
|
|
|
|
|
cp -d ${gnugrep.pcre}/lib/libpcre*.so* $out/lib # needed by grep
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
# Copy what we need of GCC.
|
|
|
|
cp -d ${gcc.gcc}/bin/gcc $out/bin
|
|
|
|
cp -d ${gcc.gcc}/bin/cpp $out/bin
|
|
|
|
cp -d ${gcc.gcc}/bin/g++ $out/bin
|
|
|
|
cp -d ${gcc.gcc}/lib*/libgcc_s.so* $out/lib
|
|
|
|
cp -d ${gcc.gcc}/lib*/libstdc++.so* $out/lib
|
|
|
|
cp -rd ${gcc.gcc}/lib/gcc $out/lib
|
|
|
|
chmod -R u+w $out/lib
|
|
|
|
rm -f $out/lib/gcc/*/*/include*/linux
|
|
|
|
rm -f $out/lib/gcc/*/*/include*/sound
|
|
|
|
rm -rf $out/lib/gcc/*/*/include*/root
|
2009-06-22 16:28:07 +02:00
|
|
|
rm -f $out/lib/gcc/*/*/include-fixed/asm
|
2010-08-21 14:50:49 +02:00
|
|
|
rm -rf $out/lib/gcc/*/*/plugin
|
2009-01-30 10:27:15 +01:00
|
|
|
#rm -f $out/lib/gcc/*/*/*.a
|
|
|
|
cp -rd ${gcc.gcc}/libexec/* $out/libexec
|
2014-10-29 13:36:03 +01:00
|
|
|
chmod -R u+w $out/libexec
|
|
|
|
rm -rf $out/libexec/gcc/*/*/plugin
|
2009-01-30 10:27:15 +01:00
|
|
|
mkdir $out/include
|
|
|
|
cp -rd ${gcc.gcc}/include/c++ $out/include
|
|
|
|
chmod -R u+w $out/include
|
|
|
|
rm -rf $out/include/c++/*/ext/pb_ds
|
|
|
|
rm -rf $out/include/c++/*/ext/parallel
|
|
|
|
|
2010-08-21 14:50:49 +02:00
|
|
|
cp -d ${gmpxx}/lib/libgmp*.so* $out/lib
|
2009-01-30 10:27:15 +01:00
|
|
|
cp -d ${mpfr}/lib/libmpfr*.so* $out/lib
|
2010-08-21 14:50:49 +02:00
|
|
|
cp -d ${mpc}/lib/libmpc*.so* $out/lib
|
|
|
|
cp -d ${zlib}/lib/libz.so* $out/lib
|
|
|
|
cp -d ${libelf}/lib/libelf.so* $out/lib
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
# Copy binutils.
|
|
|
|
for i in as ld ar ranlib nm strip readelf objdump; do
|
|
|
|
cp ${binutils}/bin/$i $out/bin
|
|
|
|
done
|
2014-10-29 13:36:03 +01:00
|
|
|
cp -d ${binutils}/lib/lib*.so* $out/lib
|
2009-01-30 10:27:15 +01:00
|
|
|
|
|
|
|
chmod -R u+w $out
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
# Strip executables even further.
|
|
|
|
for i in $out/bin/* $out/libexec/gcc/*/*/*; do
|
|
|
|
if test -x $i -a ! -L $i; then
|
|
|
|
chmod +w $i
|
|
|
|
strip -s $i || true
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
nuke-refs $out/bin/*
|
|
|
|
nuke-refs $out/lib/*
|
|
|
|
nuke-refs $out/libexec/gcc/*/*/*
|
|
|
|
|
|
|
|
mkdir $out/.pack
|
|
|
|
mv $out/* $out/.pack
|
|
|
|
mv $out/.pack $out/pack
|
|
|
|
|
|
|
|
mkdir $out/on-server
|
2014-10-29 13:36:03 +01:00
|
|
|
tar cvfJ $out/on-server/bootstrap-tools.tar.xz -C $out/pack .
|
|
|
|
cp ${busyboxMinimal}/bin/busybox $out/on-server
|
|
|
|
chmod u+w $out/on-server/busybox
|
|
|
|
nuke-refs $out/on-server/busybox
|
2009-01-30 10:27:15 +01:00
|
|
|
''; # */
|
|
|
|
|
|
|
|
# The result should not contain any references (store paths) so
|
|
|
|
# that we can safely copy them out of the store and to other
|
|
|
|
# locations in the store.
|
|
|
|
allowedReferences = [];
|
2006-10-20 13:16:15 +02:00
|
|
|
};
|
2009-01-30 10:27:15 +01:00
|
|
|
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
unpack =
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2014-10-29 13:36:03 +01:00
|
|
|
derivation {
|
2009-01-30 10:27:15 +01:00
|
|
|
name = "unpack";
|
2014-10-29 13:36:03 +01:00
|
|
|
inherit system;
|
|
|
|
builder = "${build}/on-server/busybox";
|
|
|
|
args = [ "ash" "-e" "-c" "eval \"$buildCommand\"" ];
|
2006-10-20 14:50:45 +02:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
buildCommand = ''
|
2014-10-29 13:36:03 +01:00
|
|
|
export PATH=${build}/on-server:$out/bin
|
|
|
|
|
|
|
|
busybox mkdir $out
|
|
|
|
< ${build}/on-server/bootstrap-tools.tar.xz busybox unxz | busybox tar x -C $out
|
2009-01-30 10:27:15 +01:00
|
|
|
|
|
|
|
for i in $out/bin/* $out/libexec/gcc/*/*/*; do
|
2014-10-29 13:36:03 +01:00
|
|
|
if [ -L "$i" ]; then continue; fi
|
|
|
|
if [ -z "''${i##*/liblto*}" ]; then continue; fi
|
|
|
|
echo patching "$i"
|
|
|
|
LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.2 \
|
|
|
|
$out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.2 --set-rpath $out/lib --force-rpath "$i"
|
|
|
|
done
|
|
|
|
|
|
|
|
for i in $out/lib/libpcre*; do
|
|
|
|
if [ -L "$i" ]; then continue; fi
|
|
|
|
echo patching "$i"
|
|
|
|
$out/bin/patchelf --set-rpath $out/lib --force-rpath "$i"
|
2009-01-30 10:27:15 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# Fix the libc linker script.
|
|
|
|
for i in $out/lib/libc.so; do
|
|
|
|
cat $i | sed "s|/nix/store/e*-[^/]*/|$out/|g" > $i.tmp
|
|
|
|
mv $i.tmp $i
|
|
|
|
done
|
|
|
|
''; # " */
|
|
|
|
|
|
|
|
allowedReferences = ["out"];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
test =
|
2006-10-19 20:03:13 +02:00
|
|
|
|
2014-10-29 13:36:03 +01:00
|
|
|
derivation {
|
2009-01-30 10:27:15 +01:00
|
|
|
name = "test";
|
2014-10-29 13:36:03 +01:00
|
|
|
inherit system;
|
|
|
|
builder = "${build}/on-server/busybox";
|
|
|
|
args = [ "ash" "-e" "-c" "eval \"$buildCommand\"" ];
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
buildCommand = ''
|
|
|
|
export PATH=${unpack}/bin
|
|
|
|
ls -l
|
|
|
|
mkdir $out
|
|
|
|
mkdir $out/bin
|
|
|
|
sed --version
|
|
|
|
find --version
|
|
|
|
diff --version
|
|
|
|
patch --version
|
|
|
|
make --version
|
|
|
|
awk --version
|
|
|
|
grep --version
|
|
|
|
gcc --version
|
2014-10-29 13:36:03 +01:00
|
|
|
curl --version
|
2009-01-30 10:27:15 +01:00
|
|
|
|
|
|
|
ldlinux=$(echo ${unpack}/lib/ld-linux*.so.2)
|
|
|
|
|
|
|
|
export CPP="cpp -idirafter ${unpack}/include-glibc -B${unpack}"
|
|
|
|
export CC="gcc -idirafter ${unpack}/include-glibc -B${unpack} -Wl,-dynamic-linker,$ldlinux -Wl,-rpath,${unpack}/lib"
|
|
|
|
export CXX="g++ -idirafter ${unpack}/include-glibc -B${unpack} -Wl,-dynamic-linker,$ldlinux -Wl,-rpath,${unpack}/lib"
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
echo '#include <stdio.h>' >> foo.c
|
|
|
|
echo '#include <limits.h>' >> foo.c
|
2014-10-29 13:36:03 +01:00
|
|
|
echo 'int main() { printf("Hello World\\n"); return 0; }' >> foo.c
|
2009-01-30 10:27:15 +01:00
|
|
|
$CC -o $out/bin/foo foo.c
|
|
|
|
$out/bin/foo
|
|
|
|
|
|
|
|
echo '#include <iostream>' >> bar.cc
|
2014-10-29 13:36:03 +01:00
|
|
|
echo 'int main() { std::cout << "Hello World\\n"; }' >> bar.cc
|
2009-01-30 10:27:15 +01:00
|
|
|
$CXX -v -o $out/bin/bar bar.cc
|
|
|
|
$out/bin/bar
|
|
|
|
|
|
|
|
tar xvf ${hello.src}
|
|
|
|
cd hello-*
|
|
|
|
./configure --prefix=$out
|
|
|
|
make
|
|
|
|
make install
|
|
|
|
''; # */
|
|
|
|
};
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
}
|