2017-06-26 22:56:03 +02:00
|
|
|
{ localSystem ? { system = builtins.currentSystem; }
|
|
|
|
, crossSystem ? null
|
|
|
|
}:
|
2007-12-03 16:40:29 +01:00
|
|
|
|
2017-06-26 22:56:03 +02:00
|
|
|
let
|
|
|
|
pkgs = import ../../.. { inherit localSystem crossSystem; };
|
2018-02-06 01:12:47 +01:00
|
|
|
libc = pkgs.stdenv.cc.libc;
|
2017-06-26 22:56:03 +02:00
|
|
|
in with pkgs; rec {
|
2006-10-19 20:03:13 +02:00
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
|
2014-10-29 13:36:03 +01:00
|
|
|
coreutilsMinimal = coreutils.override (args: {
|
2017-01-04 23:46:34 +01:00
|
|
|
# We want coreutils without ACL/attr support.
|
2009-01-30 10:27:15 +01:00
|
|
|
aclSupport = false;
|
2017-01-04 23:46:34 +01:00
|
|
|
attrSupport = false;
|
2016-06-28 09:48:56 +02:00
|
|
|
# Our tooling currently can't handle scripts in bin/, only ELFs and symlinks.
|
|
|
|
singleBinary = "symlinks";
|
2009-01-30 10:27:15 +01:00
|
|
|
});
|
|
|
|
|
2016-04-17 23:55:17 +02:00
|
|
|
tarMinimal = gnutar.override { acl = null; };
|
|
|
|
|
2014-10-29 13:36:03 +01:00
|
|
|
busyboxMinimal = busybox.override {
|
2018-11-01 21:18:51 +01:00
|
|
|
useMusl = !stdenv.targetPlatform.isRiscV;
|
2014-10-29 13:36:03 +01:00
|
|
|
enableStatic = true;
|
|
|
|
enableMinimal = true;
|
2010-08-21 14:50:49 +02:00
|
|
|
extraConfig = ''
|
|
|
|
CONFIG_ASH y
|
2017-08-14 16:41:48 +02:00
|
|
|
CONFIG_ASH_ECHO y
|
|
|
|
CONFIG_ASH_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 {
|
2015-10-23 13:04:10 +02:00
|
|
|
name = "stdenv-bootstrap-tools";
|
2009-01-30 10:27:15 +01:00
|
|
|
|
2017-06-26 22:56:03 +02:00
|
|
|
nativeBuildInputs = [ buildPackages.nukeReferences buildPackages.cpio ];
|
2009-01-30 10:27:15 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2018-11-01 21:18:51 +01:00
|
|
|
'' + (if (stdenv.hostPlatform.libc == "glibc") then ''
|
2009-01-30 10:27:15 +01:00
|
|
|
# Copy what we need of Glibc.
|
2018-01-05 22:36:24 +01:00
|
|
|
cp -d ${libc.out}/lib/ld*.so* $out/lib
|
|
|
|
cp -d ${libc.out}/lib/libc*.so* $out/lib
|
|
|
|
cp -d ${libc.out}/lib/libc_nonshared.a $out/lib
|
|
|
|
cp -d ${libc.out}/lib/libm*.so* $out/lib
|
|
|
|
cp -d ${libc.out}/lib/libdl*.so* $out/lib
|
|
|
|
cp -d ${libc.out}/lib/librt*.so* $out/lib
|
|
|
|
cp -d ${libc.out}/lib/libpthread*.so* $out/lib
|
|
|
|
cp -d ${libc.out}/lib/libnsl*.so* $out/lib
|
|
|
|
cp -d ${libc.out}/lib/libutil*.so* $out/lib
|
|
|
|
cp -d ${libc.out}/lib/libnss*.so* $out/lib
|
|
|
|
cp -d ${libc.out}/lib/libresolv*.so* $out/lib
|
|
|
|
cp -d ${libc.out}/lib/crt?.o $out/lib
|
|
|
|
|
|
|
|
cp -rL ${libc.dev}/include $out
|
2016-03-03 12:09:50 +01:00
|
|
|
chmod -R u+w "$out"
|
|
|
|
|
2018-01-05 22:36:24 +01:00
|
|
|
# libc can contain linker scripts: find them, copy their deps,
|
2016-03-03 12:09:50 +01:00
|
|
|
# and get rid of absolute paths (nuke-refs would make them useless)
|
|
|
|
local lScripts=$(grep --files-with-matches --max-count=1 'GNU ld script' -R "$out/lib")
|
2018-01-05 22:36:24 +01:00
|
|
|
cp -d -t "$out/lib/" $(cat $lScripts | tr " " "\n" | grep -F '${libc.out}' | sort -u)
|
2016-03-03 12:09:50 +01:00
|
|
|
for f in $lScripts; do
|
2018-01-05 22:36:24 +01:00
|
|
|
substituteInPlace "$f" --replace '${libc.out}/lib/' ""
|
2016-03-03 12:09:50 +01:00
|
|
|
done
|
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
|
2018-11-01 21:18:51 +01:00
|
|
|
'' else if (stdenv.hostPlatform.libc == "musl") then ''
|
2018-01-05 22:36:24 +01:00
|
|
|
# Copy what we need from musl
|
|
|
|
cp ${libc.out}/lib/* $out/lib
|
|
|
|
cp -rL ${libc.dev}/include $out
|
|
|
|
chmod -R u+w "$out"
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2018-01-05 22:36:24 +01:00
|
|
|
rm -rf $out/include/mtd $out/include/rdma $out/include/sound $out/include/video
|
|
|
|
find $out/include -name .install -exec rm {} \;
|
|
|
|
find $out/include -name ..install.cmd -exec rm {} \;
|
2018-01-05 23:26:46 +01:00
|
|
|
mv $out/include $out/include-libc
|
2018-01-05 22:36:24 +01:00
|
|
|
'' else throw "unsupported libc for bootstrap tools")
|
|
|
|
+ ''
|
2009-01-30 10:27:15 +01:00
|
|
|
# Copy coreutils, bash, etc.
|
2018-03-06 00:03:40 +01:00
|
|
|
cp -d ${coreutilsMinimal.out}/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
|
|
|
|
2016-04-17 23:59:55 +02:00
|
|
|
cp ${bash.out}/bin/bash $out/bin
|
|
|
|
cp ${findutils.out}/bin/find $out/bin
|
|
|
|
cp ${findutils.out}/bin/xargs $out/bin
|
|
|
|
cp -d ${diffutils.out}/bin/* $out/bin
|
|
|
|
cp -d ${gnused.out}/bin/* $out/bin
|
|
|
|
cp -d ${gnugrep.out}/bin/grep $out/bin
|
|
|
|
cp ${gawk.out}/bin/gawk $out/bin
|
|
|
|
cp -d ${gawk.out}/bin/awk $out/bin
|
2016-04-17 23:55:17 +02:00
|
|
|
cp ${tarMinimal.out}/bin/tar $out/bin
|
2016-04-17 23:59:55 +02:00
|
|
|
cp ${gzip.out}/bin/gzip $out/bin
|
2016-02-01 19:45:57 +01:00
|
|
|
cp ${bzip2.bin}/bin/bzip2 $out/bin
|
2016-04-17 23:59:55 +02:00
|
|
|
cp -d ${gnumake.out}/bin/* $out/bin
|
2009-01-30 10:27:15 +01:00
|
|
|
cp -d ${patch}/bin/* $out/bin
|
2010-08-01 22:57:13 +02:00
|
|
|
cp ${patchelf}/bin/* $out/bin
|
2009-01-30 10:27:15 +01:00
|
|
|
|
2016-01-24 08:30:07 +01:00
|
|
|
cp -d ${gnugrep.pcre.out}/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.
|
2016-04-17 23:59:55 +02:00
|
|
|
cp -d ${gcc.cc.out}/bin/gcc $out/bin
|
|
|
|
cp -d ${gcc.cc.out}/bin/cpp $out/bin
|
|
|
|
cp -d ${gcc.cc.out}/bin/g++ $out/bin
|
2018-09-23 21:54:09 +02:00
|
|
|
cp -d ${gcc.cc.lib}/lib/libgcc_s.so* $out/lib
|
|
|
|
cp -d ${gcc.cc.lib}/lib/libstdc++.so* $out/lib
|
2016-04-17 23:59:55 +02:00
|
|
|
cp -rd ${gcc.cc.out}/lib/gcc $out/lib
|
2009-01-30 10:27:15 +01:00
|
|
|
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
|
2016-04-17 23:59:55 +02:00
|
|
|
cp -rd ${gcc.cc.out}/libexec/* $out/libexec
|
2014-10-29 13:36:03 +01:00
|
|
|
chmod -R u+w $out/libexec
|
|
|
|
rm -rf $out/libexec/gcc/*/*/plugin
|
2018-01-05 22:36:24 +01:00
|
|
|
mkdir -p $out/include
|
2016-04-17 23:59:55 +02:00
|
|
|
cp -rd ${gcc.cc.out}/include/c++ $out/include
|
2009-01-30 10:27:15 +01:00
|
|
|
chmod -R u+w $out/include
|
|
|
|
rm -rf $out/include/c++/*/ext/pb_ds
|
|
|
|
rm -rf $out/include/c++/*/ext/parallel
|
|
|
|
|
2016-04-17 23:59:55 +02:00
|
|
|
cp -d ${gmpxx.out}/lib/libgmp*.so* $out/lib
|
2016-01-24 08:30:00 +01:00
|
|
|
cp -d ${mpfr.out}/lib/libmpfr*.so* $out/lib
|
2017-06-26 22:56:03 +02:00
|
|
|
cp -d ${libmpc.out}/lib/libmpc*.so* $out/lib
|
2016-01-24 08:30:24 +01:00
|
|
|
cp -d ${zlib.out}/lib/libz.so* $out/lib
|
2010-08-21 14:50:49 +02:00
|
|
|
cp -d ${libelf}/lib/libelf.so* $out/lib
|
2014-10-27 12:31:53 +01:00
|
|
|
|
2018-11-01 21:18:51 +01:00
|
|
|
'' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
|
2017-06-26 22:56:03 +02:00
|
|
|
# These needed for cross but not native tools because the stdenv
|
|
|
|
# GCC has certain things built in statically. See
|
|
|
|
# pkgs/stdenv/linux/default.nix for the details.
|
2018-02-18 22:25:27 +01:00
|
|
|
cp -d ${isl_0_17.out}/lib/libisl*.so* $out/lib
|
2017-06-26 22:56:03 +02:00
|
|
|
|
|
|
|
'' + ''
|
2017-04-13 15:28:09 +02:00
|
|
|
cp -d ${bzip2.out}/lib/libbz2.so* $out/lib
|
|
|
|
|
2009-01-30 10:27:15 +01:00
|
|
|
# Copy binutils.
|
|
|
|
for i in as ld ar ranlib nm strip readelf objdump; do
|
2017-08-26 17:43:30 +02:00
|
|
|
cp ${binutils.bintools.out}/bin/$i $out/bin
|
2009-01-30 10:27:15 +01:00
|
|
|
done
|
2018-09-01 22:30:41 +02:00
|
|
|
cp '${lib.getLib binutils.bintools}'/lib/* "$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
|
2017-06-26 22:56:03 +02:00
|
|
|
$STRIP -s $i || true
|
2009-01-30 10:27:15 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
nuke-refs $out/bin/*
|
|
|
|
nuke-refs $out/lib/*
|
|
|
|
nuke-refs $out/libexec/gcc/*/*/*
|
2017-06-26 22:56:03 +02:00
|
|
|
nuke-refs $out/lib/gcc/*/*/*
|
2009-01-30 10:27:15 +01:00
|
|
|
|
|
|
|
mkdir $out/.pack
|
|
|
|
mv $out/* $out/.pack
|
|
|
|
mv $out/.pack $out/pack
|
|
|
|
|
|
|
|
mkdir $out/on-server
|
2018-02-12 23:53:18 +01:00
|
|
|
XZ_OPT=-9 tar cvJf $out/on-server/bootstrap-tools.tar.xz --hard-dereference --sort=name --numeric-owner --owner=0 --group=0 --mtime=@1 -C $out/pack .
|
2014-10-29 13:36:03 +01:00
|
|
|
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
|
|
|
|
2015-10-23 13:04:10 +02:00
|
|
|
dist = stdenv.mkDerivation {
|
|
|
|
name = "stdenv-bootstrap-tools";
|
|
|
|
|
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out/nix-support
|
|
|
|
echo "file tarball ${build}/on-server/bootstrap-tools.tar.xz" >> $out/nix-support/hydra-build-products
|
|
|
|
echo "file busybox ${build}/on-server/busybox" >> $out/nix-support/hydra-build-products
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-03-03 13:46:21 +01:00
|
|
|
bootstrapFiles = {
|
2016-12-25 23:54:45 +01:00
|
|
|
# Make them their own store paths to test that busybox still works when the binary is named /nix/store/HASH-busybox
|
|
|
|
busybox = runCommand "busybox" {} "cp ${build}/on-server/busybox $out";
|
|
|
|
bootstrapTools = runCommand "bootstrap-tools.tar.xz" {} "cp ${build}/on-server/bootstrap-tools.tar.xz $out";
|
2016-03-03 13:46:21 +01:00
|
|
|
};
|
|
|
|
|
2018-11-01 21:18:51 +01:00
|
|
|
bootstrapTools = if (stdenv.hostPlatform.libc == "glibc") then
|
2018-01-05 23:26:46 +01:00
|
|
|
import ./bootstrap-tools {
|
2018-11-01 21:19:17 +01:00
|
|
|
inherit (stdenv.buildPlatform) system; # Used to determine where to build
|
2018-01-05 23:26:46 +01:00
|
|
|
inherit bootstrapFiles;
|
|
|
|
}
|
2018-11-01 21:18:51 +01:00
|
|
|
else if (stdenv.hostPlatform.libc == "musl") then
|
2018-01-05 23:26:46 +01:00
|
|
|
import ./bootstrap-tools-musl {
|
2018-11-01 21:19:17 +01:00
|
|
|
inherit (stdenv.buildPlatform) system; # Used to determine where to build
|
2018-01-05 23:26:46 +01:00
|
|
|
inherit bootstrapFiles;
|
|
|
|
}
|
|
|
|
else throw "unsupported libc";
|
2016-03-03 13:46:21 +01:00
|
|
|
|
|
|
|
test = derivation {
|
|
|
|
name = "test-bootstrap-tools";
|
2018-11-01 21:19:17 +01:00
|
|
|
inherit (stdenv.hostPlatform) system; # We cannot "cross test"
|
2016-03-03 13:46:21 +01:00
|
|
|
builder = bootstrapFiles.busybox;
|
|
|
|
args = [ "ash" "-e" "-c" "eval \"$buildCommand\"" ];
|
2015-10-23 13:04:10 +02:00
|
|
|
|
2016-03-03 13:46:21 +01:00
|
|
|
buildCommand = ''
|
|
|
|
export PATH=${bootstrapTools}/bin
|
|
|
|
|
|
|
|
ls -l
|
|
|
|
mkdir $out
|
|
|
|
mkdir $out/bin
|
|
|
|
sed --version
|
|
|
|
find --version
|
|
|
|
diff --version
|
|
|
|
patch --version
|
|
|
|
make --version
|
|
|
|
awk --version
|
|
|
|
grep --version
|
|
|
|
gcc --version
|
|
|
|
|
2018-11-01 21:18:51 +01:00
|
|
|
'' + lib.optionalString (stdenv.hostPlatform.libc == "glibc") ''
|
2016-03-03 13:46:21 +01:00
|
|
|
ldlinux=$(echo ${bootstrapTools}/lib/ld-linux*.so.?)
|
|
|
|
export CPP="cpp -idirafter ${bootstrapTools}/include-glibc -B${bootstrapTools}"
|
|
|
|
export CC="gcc -idirafter ${bootstrapTools}/include-glibc -B${bootstrapTools} -Wl,-dynamic-linker,$ldlinux -Wl,-rpath,${bootstrapTools}/lib"
|
|
|
|
export CXX="g++ -idirafter ${bootstrapTools}/include-glibc -B${bootstrapTools} -Wl,-dynamic-linker,$ldlinux -Wl,-rpath,${bootstrapTools}/lib"
|
2018-11-01 21:18:51 +01:00
|
|
|
'' + lib.optionalString (stdenv.hostPlatform.libc == "musl") ''
|
2018-01-05 23:26:46 +01:00
|
|
|
ldmusl=$(echo ${bootstrapTools}/lib/ld-musl*.so.?)
|
|
|
|
export CPP="cpp -idirafter ${bootstrapTools}/include-libc -B${bootstrapTools}"
|
|
|
|
export CC="gcc -idirafter ${bootstrapTools}/include-libc -B${bootstrapTools} -Wl,-dynamic-linker,$ldmusl -Wl,-rpath,${bootstrapTools}/lib"
|
|
|
|
export CXX="g++ -idirafter ${bootstrapTools}/include-libc -B${bootstrapTools} -Wl,-dynamic-linker,$ldmusl -Wl,-rpath,${bootstrapTools}/lib"
|
|
|
|
'' + ''
|
2016-03-03 13:46:21 +01:00
|
|
|
|
|
|
|
echo '#include <stdio.h>' >> foo.c
|
|
|
|
echo '#include <limits.h>' >> foo.c
|
|
|
|
echo 'int main() { printf("Hello World\\n"); return 0; }' >> foo.c
|
|
|
|
$CC -o $out/bin/foo foo.c
|
|
|
|
$out/bin/foo
|
|
|
|
|
|
|
|
echo '#include <iostream>' >> bar.cc
|
|
|
|
echo 'int main() { std::cout << "Hello World\\n"; }' >> bar.cc
|
|
|
|
$CXX -v -o $out/bin/bar bar.cc
|
|
|
|
$out/bin/bar
|
|
|
|
|
2017-11-13 17:45:09 +01:00
|
|
|
tar xvf ${hello.src}
|
2016-03-03 13:46:21 +01:00
|
|
|
cd hello-*
|
|
|
|
./configure --prefix=$out
|
|
|
|
make
|
|
|
|
make install
|
|
|
|
'';
|
|
|
|
};
|
2009-01-30 10:27:15 +01:00
|
|
|
}
|