├── .drone.yml ├── .gitignore ├── flake.nix ├── meta └── wget-list ├── nix └── flattenTree.nix └── pkgs ├── stage0 ├── bootstrap-tarball.nix ├── bootstrap-tools.nix ├── busybox.nix ├── default.nix └── unpack-bootstrap-tools.sh ├── stage1 ├── bash.nix ├── binutils.nix ├── bison.nix ├── busybox-config.sh ├── busybox.nix ├── default.nix ├── fetchurl.nix ├── gcc.nix ├── genWrapper.nix ├── gmp.nix ├── linux-headers.nix ├── m4.nix ├── mkDerivation │ ├── default.nix │ └── mkDerivation-builder.sh ├── mpc.nix ├── mpfr.nix ├── musl.nix ├── stage0.nix ├── wrappers.nix └── writeFile.nix └── utils └── attrdir.nix /.drone.yml: -------------------------------------------------------------------------------- 1 | --- 2 | kind: pipeline 3 | type: docker 4 | name: build 5 | 6 | steps: 7 | - name: build 8 | image: docker.io/nixos/nix 9 | environment: 10 | CACHIX_AUTH_TOKEN: 11 | from_secret: CACHIX_AUTH_TOKEN 12 | commands: 13 | - "nix-env -iA nixpkgs.nixFlakes" 14 | - "echo 'experimental-features = nix-command flakes ca-references' >> /etc/nix/nix.conf" 15 | - "nix profile install github:NixOS/nixpkgs/nixos-unstable-small#cachix github:NixOS/nixpkgs/nixos-unstable-small#git" 16 | - "cachix use scratchix" 17 | - "cachix watch-exec scratchix -- nix flake check -vL" 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | result 2 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | outputs = { self }: { 3 | packages.x86_64-linux = import ./nix/flattenTree.nix (import ./pkgs/stage1); 4 | checks = self.packages; 5 | }; 6 | } 7 | -------------------------------------------------------------------------------- /meta/wget-list: -------------------------------------------------------------------------------- 1 | http://download.savannah.gnu.org/releases/acl/acl-2.2.53.tar.gz 2 | http://download.savannah.gnu.org/releases/attr/attr-2.4.48.tar.gz 3 | http://ftp.gnu.org/gnu/autoconf/autoconf-2.71.tar.xz 4 | http://ftp.gnu.org/gnu/automake/automake-1.16.3.tar.xz 5 | http://ftp.gnu.org/gnu/bash/bash-5.1.tar.gz 6 | https://github.com/gavinhoward/bc/releases/download/3.3.0/bc-3.3.0.tar.xz 7 | http://ftp.gnu.org/gnu/binutils/binutils-2.36.1.tar.xz 8 | http://ftp.gnu.org/gnu/bison/bison-3.7.5.tar.xz 9 | https://www.sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz 10 | https://github.com/libcheck/check/releases/download/0.15.2/check-0.15.2.tar.gz 11 | http://ftp.gnu.org/gnu/coreutils/coreutils-8.32.tar.xz 12 | https://dbus.freedesktop.org/releases/dbus/dbus-1.12.20.tar.gz 13 | http://ftp.gnu.org/gnu/dejagnu/dejagnu-1.6.2.tar.gz 14 | http://ftp.gnu.org/gnu/diffutils/diffutils-3.7.tar.xz 15 | https://downloads.sourceforge.net/project/e2fsprogs/e2fsprogs/v1.46.1/e2fsprogs-1.46.1.tar.gz 16 | https://sourceware.org/ftp/elfutils/0.183/elfutils-0.183.tar.bz2 17 | https://dev.gentoo.org/~blueness/eudev/eudev-3.2.10.tar.gz 18 | https://prdownloads.sourceforge.net/expat/expat-2.2.10.tar.xz 19 | https://prdownloads.sourceforge.net/expect/expect5.45.4.tar.gz 20 | http://ftp.astron.com/pub/file/file-5.39.tar.gz 21 | http://ftp.gnu.org/gnu/findutils/findutils-4.8.0.tar.xz 22 | https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz 23 | http://ftp.gnu.org/gnu/gawk/gawk-5.1.0.tar.xz 24 | http://ftp.gnu.org/gnu/gcc/gcc-10.2.0/gcc-10.2.0.tar.xz 25 | http://ftp.gnu.org/gnu/gdbm/gdbm-1.19.tar.gz 26 | http://ftp.gnu.org/gnu/gettext/gettext-0.21.tar.xz 27 | http://ftp.gnu.org/gnu/glibc/glibc-2.33.tar.xz 28 | http://ftp.gnu.org/gnu/gmp/gmp-6.2.1.tar.xz 29 | http://ftp.gnu.org/gnu/gperf/gperf-3.1.tar.gz 30 | http://ftp.gnu.org/gnu/grep/grep-3.6.tar.xz 31 | http://ftp.gnu.org/gnu/groff/groff-1.22.4.tar.gz 32 | https://ftp.gnu.org/gnu/grub/grub-2.04.tar.xz 33 | http://ftp.gnu.org/gnu/gzip/gzip-1.10.tar.xz 34 | https://github.com/Mic92/iana-etc/releases/download/20210202/iana-etc-20210202.tar.gz 35 | http://ftp.gnu.org/gnu/inetutils/inetutils-2.0.tar.xz 36 | https://launchpad.net/intltool/trunk/0.51.0/+download/intltool-0.51.0.tar.gz 37 | https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-5.10.0.tar.xz 38 | https://www.kernel.org/pub/linux/utils/kbd/kbd-2.4.0.tar.xz 39 | https://www.kernel.org/pub/linux/utils/kernel/kmod/kmod-28.tar.xz 40 | http://www.greenwoodsoftware.com/less/less-563.tar.gz 41 | http://www.linuxfromscratch.org/lfs/downloads/development/lfs-bootscripts-20210201.tar.xz 42 | https://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/libcap-2.48.tar.xz 43 | https://sourceware.org/pub/libffi/libffi-3.3.tar.gz 44 | http://download.savannah.gnu.org/releases/libpipeline/libpipeline-1.5.3.tar.gz 45 | http://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.xz 46 | https://www.kernel.org/pub/linux/kernel/v5.x/linux-5.10.17.tar.xz 47 | http://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.xz 48 | http://ftp.gnu.org/gnu/make/make-4.3.tar.gz 49 | http://download.savannah.gnu.org/releases/man-db/man-db-2.9.4.tar.xz 50 | https://www.kernel.org/pub/linux/docs/man-pages/man-pages-5.10.tar.xz 51 | https://github.com/mesonbuild/meson/releases/download/0.57.0/meson-0.57.0.tar.gz 52 | https://ftp.gnu.org/gnu/mpc/mpc-1.2.1.tar.gz 53 | http://www.mpfr.org/mpfr-4.1.0/mpfr-4.1.0.tar.xz 54 | http://ftp.gnu.org/gnu/ncurses/ncurses-6.2.tar.gz 55 | https://github.com/ninja-build/ninja/archive/v1.10.2/ninja-1.10.2.tar.gz 56 | https://www.openssl.org/source/openssl-1.1.1j.tar.gz 57 | http://ftp.gnu.org/gnu/patch/patch-2.7.6.tar.xz 58 | https://www.cpan.org/src/5.0/perl-5.32.1.tar.xz 59 | https://pkg-config.freedesktop.org/releases/pkg-config-0.29.2.tar.gz 60 | https://sourceforge.net/projects/procps-ng/files/Production/procps-ng-3.3.17.tar.xz 61 | https://sourceforge.net/projects/psmisc/files/psmisc/psmisc-23.4.tar.xz 62 | https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tar.xz 63 | https://www.python.org/ftp/python/doc/3.9.1/python-3.9.1-docs-html.tar.bz2 64 | http://ftp.gnu.org/gnu/readline/readline-8.1.tar.gz 65 | http://ftp.gnu.org/gnu/sed/sed-4.8.tar.xz 66 | https://github.com/shadow-maint/shadow/releases/download/4.8.1/shadow-4.8.1.tar.xz 67 | http://www.infodrom.org/projects/sysklogd/download/sysklogd-1.5.1.tar.gz 68 | https://github.com/systemd/systemd/archive/v247/systemd-247.tar.gz 69 | http://anduin.linuxfromscratch.org/LFS/systemd-man-pages-247.tar.xz 70 | http://download.savannah.gnu.org/releases/sysvinit/sysvinit-2.98.tar.xz 71 | http://ftp.gnu.org/gnu/tar/tar-1.34.tar.xz 72 | https://downloads.sourceforge.net/tcl/tcl8.6.11-src.tar.gz 73 | https://downloads.sourceforge.net/tcl/tcl8.6.11-html.tar.gz 74 | http://ftp.gnu.org/gnu/texinfo/texinfo-6.7.tar.xz 75 | https://www.iana.org/time-zones/repository/releases/tzdata2021a.tar.gz 76 | http://anduin.linuxfromscratch.org/LFS/udev-lfs-20171102.tar.xz 77 | https://www.kernel.org/pub/linux/utils/util-linux/v2.36/util-linux-2.36.2.tar.xz 78 | http://anduin.linuxfromscratch.org/LFS/vim-8.2.2433.tar.gz 79 | https://cpan.metacpan.org/authors/id/T/TO/TODDR/XML-Parser-2.46.tar.gz 80 | https://tukaani.org/xz/xz-5.2.5.tar.xz 81 | https://zlib.net/zlib-1.2.11.tar.xz 82 | https://github.com/facebook/zstd/releases/download/v1.4.8/zstd-1.4.8.tar.gz 83 | http://www.linuxfromscratch.org/patches/lfs/development/bzip2-1.0.8-install_docs-1.patch 84 | http://www.linuxfromscratch.org/patches/lfs/development/coreutils-8.32-i18n-1.patch 85 | http://www.linuxfromscratch.org/patches/lfs/development/glibc-2.33-fhs-1.patch 86 | http://www.linuxfromscratch.org/patches/lfs/development/kbd-2.4.0-backspace-1.patch 87 | http://www.linuxfromscratch.org/patches/lfs/development/sysvinit-2.98-consolidated-1.patch 88 | http://www.linuxfromscratch.org/patches/lfs/development/systemd-247-upstream_fixes-1.patch 89 | -------------------------------------------------------------------------------- /nix/flattenTree.nix: -------------------------------------------------------------------------------- 1 | # https://github.com/numtide/flake-utils/blob/master/flattenTree.nix 2 | 3 | tree: 4 | let 5 | op = sum: path: val: 6 | let 7 | pathStr = builtins.concatStringsSep "/" path; 8 | in 9 | if (builtins.typeOf val) != "set" then 10 | # ignore that value 11 | # builtins.trace "${pathStr} is not of type set" 12 | sum 13 | else if val ? type && val.type == "derivation" then 14 | # builtins.trace "${pathStr} is a derivation" 15 | # we used to use the derivation outPath as the key, but that crashes Nix 16 | # so fallback on constructing a static key 17 | (sum // { 18 | "${pathStr}" = val; 19 | }) 20 | else if val ? recurseForDerivations && val.recurseForDerivations == true then 21 | # builtins.trace "${pathStr} is a recursive" 22 | # recurse into that attribute set 23 | (recurse sum path val) 24 | else 25 | # ignore that value 26 | # builtins.trace "${pathStr} is something else" 27 | sum 28 | ; 29 | 30 | recurse = sum: path: val: 31 | builtins.foldl' 32 | (sum: key: op sum (path ++ [ key ]) val.${key}) 33 | sum 34 | (builtins.attrNames val) 35 | ; 36 | in 37 | recurse { } [ ] tree 38 | -------------------------------------------------------------------------------- /pkgs/stage0/bootstrap-tarball.nix: -------------------------------------------------------------------------------- 1 | {}: 2 | 3 | import { 4 | name = "bootstrap-tarball"; 5 | url = "http://tarballs.nixos.org/stdenv-linux/x86_64/c5aabb0d603e2c1ea05f5a93b3be82437f5ebf31/bootstrap-tools.tar.xz"; 6 | hash = "sha256-pc6cFV7Qk5dhRkbJcX/HzZSxAj17drYY1Ank/v1unTk="; 7 | } 8 | -------------------------------------------------------------------------------- /pkgs/stage0/bootstrap-tools.nix: -------------------------------------------------------------------------------- 1 | { busybox, bootstrap-tarball }: 2 | 3 | derivation { 4 | system = "x86_64-linux"; # FIXME 5 | name = "bootstrap"; 6 | builder = busybox; 7 | args = [ "ash" "-e" ./unpack-bootstrap-tools.sh ]; 8 | tarball = bootstrap-tarball; 9 | } 10 | -------------------------------------------------------------------------------- /pkgs/stage0/busybox.nix: -------------------------------------------------------------------------------- 1 | {}: 2 | 3 | import { 4 | name = "busybox"; 5 | url = "http://tarballs.nixos.org/stdenv-linux/i686/4907fc9e8d0d82b28b3c56e3a478a2882f1d700f/busybox"; 6 | hash = "sha256-70wb5seuV+T2VO/ZCuLS4gTWdpNkxGRp+p/zdhGVy6E="; 7 | executable = true; 8 | } 9 | -------------------------------------------------------------------------------- /pkgs/stage0/default.nix: -------------------------------------------------------------------------------- 1 | import ../utils/attrdir.nix ./. 2 | -------------------------------------------------------------------------------- /pkgs/stage0/unpack-bootstrap-tools.sh: -------------------------------------------------------------------------------- 1 | # https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/linux/bootstrap-tools/scripts/unpack-bootstrap-tools.sh 2 | # Unpack the bootstrap tools tarball. 3 | echo Unpacking the bootstrap tools... 4 | $builder mkdir $out 5 | < $tarball $builder unxz | $builder tar x -C $out 6 | 7 | # Set the ELF interpreter / RPATH in the bootstrap binaries. 8 | echo Patching the bootstrap tools... 9 | 10 | if test -f $out/lib/ld.so.?; then 11 | # MIPS case 12 | LD_BINARY=$out/lib/ld.so.? 13 | elif test -f $out/lib/ld64.so.?; then 14 | # ppc64(le) 15 | LD_BINARY=$out/lib/ld64.so.? 16 | else 17 | # i686, x86_64 and armv5tel 18 | LD_BINARY=$out/lib/ld-*so.? 19 | fi 20 | 21 | # On x86_64, ld-linux-x86-64.so.2 barfs on patchelf'ed programs. So 22 | # use a copy of patchelf. 23 | LD_LIBRARY_PATH=$out/lib $LD_BINARY $out/bin/cp $out/bin/patchelf . 24 | 25 | for i in $out/bin/* $out/libexec/gcc/*/*/*; do 26 | if [ -L "$i" ]; then continue; fi 27 | if [ -z "${i##*/liblto*}" ]; then continue; fi 28 | echo patching "$i" 29 | LD_LIBRARY_PATH=$out/lib $LD_BINARY \ 30 | ./patchelf --set-interpreter $LD_BINARY --set-rpath $out/lib --force-rpath "$i" 31 | done 32 | 33 | for i in $out/lib/librt-*.so $out/lib/libpcre*; do 34 | if [ -L "$i" ]; then continue; fi 35 | echo patching "$i" 36 | $out/bin/patchelf --set-rpath $out/lib --force-rpath "$i" 37 | done 38 | 39 | export PATH=$out/bin 40 | 41 | # Provide some additional symlinks. 42 | ln -s bash $out/bin/sh 43 | ln -s bzip2 $out/bin/bunzip2 44 | 45 | # Provide a gunzip script. 46 | cat > $out/bin/gunzip < $out/bin/egrep 54 | echo "exec $out/bin/grep -E \"\$@\"" >> $out/bin/egrep 55 | echo "#! $out/bin/sh" > $out/bin/fgrep 56 | echo "exec $out/bin/grep -F \"\$@\"" >> $out/bin/fgrep 57 | 58 | # Provide xz (actually only xz -d will work). 59 | echo "#! $out/bin/sh" > $out/bin/xz 60 | echo "exec $builder unxz \"\$@\"" >> $out/bin/xz 61 | 62 | chmod +x $out/bin/egrep $out/bin/fgrep $out/bin/xz 63 | -------------------------------------------------------------------------------- /pkgs/stage1/bash.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, fetchurl, bison }: 2 | 3 | mkDerivation { 4 | name = "bash-5.1"; 5 | 6 | src = fetchurl { 7 | url = "https://ftp.gnu.org/gnu/bash/bash-5.1.tar.gz"; 8 | hash = "sha256-zAEryGBAbc9C9kQxvNPS+nVgwCkVpgGrqc1Zejkym6o="; 9 | }; 10 | 11 | NIX_BUILD_CORES = 1; 12 | 13 | buildInputs = [ bison ]; 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /pkgs/stage1/binutils.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, fetchurl }: 2 | 3 | mkDerivation { 4 | name = "binutils-2.36.1"; 5 | 6 | src = fetchurl { 7 | url = "http://ftp.gnu.org/gnu/binutils/binutils-2.36.1.tar.xz"; 8 | hash = "sha256-6B2e3zc/GTr0KKDyVmdK6mKp103+k/ZRktTq4DCw87A="; 9 | }; 10 | 11 | configureFlags = [ "--disable-nls" "--disable-werror" ]; 12 | } 13 | -------------------------------------------------------------------------------- /pkgs/stage1/bison.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation 2 | , fetchurl 3 | , m4 4 | }: 5 | 6 | mkDerivation { 7 | name = "bison-3.7.6"; 8 | 9 | src = fetchurl { 10 | url = "https://ftp.gnu.org/gnu/bison/bison-3.7.6.tar.xz"; 11 | hash = "sha256-Z9aM4eIhkgUFJWQ/wKeiIpdXZoK+9qXFFEaQP1ru888="; 12 | }; 13 | 14 | buildInputs = [ m4 ]; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /pkgs/stage1/busybox-config.sh: -------------------------------------------------------------------------------- 1 | export KCONFIG_NOTIMESTAMP=1 2 | make defconfig 3 | 4 | function parseconfig { 5 | while read LINE; do 6 | NAME= 7 | OPTION= 8 | 9 | if ! [[ "" =~ ^CONFIG_ ]]; then continue; fi 10 | 11 | echo "parseconfig: removing " 12 | sed -i /'\(=\| \)'/d .config 13 | 14 | echo "parseconfig: setting =" 15 | echo "=" >> .config 16 | done 17 | } 18 | 19 | 20 | cat << EOF | parseconfig 21 | 22 | CONFIG_PREFIX "" 23 | CONFIG_INSTALL_NO_USR y 24 | 25 | CONFIG_LFS y 26 | 27 | 28 | 29 | # Use the external mount.cifs program. 30 | CONFIG_FEATURE_MOUNT_CIFS n 31 | CONFIG_FEATURE_MOUNT_HELPERS y 32 | 33 | # Set paths for console fonts. 34 | CONFIG_DEFAULT_SETFONT_DIR "/etc/kbd" 35 | 36 | # Bump from 4KB, much faster I/O 37 | CONFIG_FEATURE_COPYBUF_KB 64 38 | 39 | # Set the path for the udhcpc script 40 | CONFIG_UDHCPC_DEFAULT_SCRIPT "/default.script" 41 | 42 | 43 | CONFIG_CROSS_COMPILER_PREFIX "" 44 | CONFIG_FEATURE_UTMP n 45 | CONFIG_FEATURE_WTMP n 46 | 47 | EOF 48 | 49 | make oldconfig 50 | 51 | -------------------------------------------------------------------------------- /pkgs/stage1/busybox.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation 2 | , fetchurl 3 | , musl 4 | , gcc 5 | , linux-headers 6 | }: 7 | 8 | mkDerivation { 9 | name = "busybox-1.33.1"; 10 | 11 | src = fetchurl { 12 | url = "https://busybox.net/downloads/busybox-1.33.1.tar.bz2"; 13 | hash = "sha256-Es7GvSsW2KlEbdFhMPK5KYLxgZ9uHF9Yh7bbA/VmDSg="; 14 | }; 15 | 16 | CC = "${gcc}/bin/gcc"; 17 | NIX_BUILD_CORES=1; 18 | 19 | makeFlags = [ 20 | "-isystem ${musl}/include -B${musl}/lib -L${musl}/lib" 21 | ]; 22 | 23 | configurePhase = '' 24 | bash ${./busybox-config.sh} 25 | ''; 26 | 27 | buildPhase = '' 28 | make ${musl}/include -B ${musl}/lib -L ${musl}/lib busybox; 29 | ''; 30 | 31 | installPhase = '' 32 | mkdir -p $out/bin; 33 | cp busybox $out/bin/; 34 | $out/bin/busybox --install -s $out/bin; 35 | ''; 36 | 37 | 38 | buildInputs = [ linux-headers ]; 39 | } 40 | -------------------------------------------------------------------------------- /pkgs/stage1/default.nix: -------------------------------------------------------------------------------- 1 | import ../utils/attrdir.nix ./. 2 | -------------------------------------------------------------------------------- /pkgs/stage1/fetchurl.nix: -------------------------------------------------------------------------------- 1 | {}: 2 | 3 | import 4 | -------------------------------------------------------------------------------- /pkgs/stage1/gcc.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation 2 | , fetchurl 3 | , gmp 4 | , mpfr 5 | , mpc 6 | }: 7 | 8 | mkDerivation { 9 | name = "gcc-10.2.0"; 10 | 11 | src = fetchurl { 12 | url = "http://ftp.gnu.org/gnu/gcc/gcc-10.2.0/gcc-10.2.0.tar.xz"; 13 | hash = "sha256-uN1DaLucfwuYGIMX7gJU3YzJnR46GND/FGyFX+FsHYw="; 14 | }; 15 | 16 | buildInputs = [ gmp mpfr mpc ]; 17 | 18 | configureFlags = [ 19 | "--disable-libcc1" 20 | "--disable-bootstrap" 21 | "--with-newlib" 22 | "--without-headers" 23 | "--enable-initfini-array" 24 | "--disable-nls" 25 | "--disable-shared" 26 | "--disable-multilib" 27 | "--disable-decimal-float" 28 | "--disable-threads" 29 | "--disable-libatomic" 30 | "--disable-libgomp" 31 | "--disable-libquadmath" 32 | "--disable-libssp" 33 | "--disable-libvtv" 34 | "--disable-libstdcxx" 35 | "--enable-languages=c,c++" 36 | ]; 37 | } 38 | -------------------------------------------------------------------------------- /pkgs/stage1/genWrapper.nix: -------------------------------------------------------------------------------- 1 | { writeFile, stage0 }: 2 | 3 | { name, label, wrapped }: 4 | 5 | writeFile { 6 | inherit name; 7 | executable = true; 8 | 9 | contents = '' 10 | #!${stage0.bootstrap-tools}/bin/bash 11 | exec ${wrapped} $NIX_WRAPPER_${label}_ARGS "$@" 12 | ''; 13 | } 14 | -------------------------------------------------------------------------------- /pkgs/stage1/gmp.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation 2 | , fetchurl 3 | , m4 4 | }: 5 | 6 | mkDerivation { 7 | name = "gmp-6.2.1"; 8 | 9 | src = fetchurl { 10 | url = "http://ftp.gnu.org/gnu/gmp/gmp-6.2.1.tar.xz"; 11 | hash = "sha256-/UgpkSzd0S+EGBw0Ucx1K+IkZD6H+sSXtp7d2txJtPI="; 12 | }; 13 | 14 | buildInputs = [ m4 ]; 15 | } 16 | -------------------------------------------------------------------------------- /pkgs/stage1/linux-headers.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation , fetchurl }: 2 | 3 | mkDerivation { 4 | name = "linux-headers.2.1"; 5 | 6 | src = fetchurl { 7 | url = "mirror://kernel/linux/kernel/v5.x/linux-5.12.tar.xz"; 8 | sha256 = "sha256-fQ328r8jhNaNC9jh/j4HHWQ2Tc3GAC57XIfJLUj6w2Y="; 9 | }; 10 | 11 | buildPhase = '' 12 | make headers 13 | ''; 14 | 15 | installPhase = '' 16 | mkdir -p $out; 17 | cp -r usr/include $out; 18 | find $out -type f ! -name '*.h' -delete; 19 | ''; 20 | configurePhase = ""; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /pkgs/stage1/m4.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, fetchurl }: 2 | 3 | mkDerivation { 4 | name = "m4-1.4.18"; 5 | 6 | src = fetchurl { 7 | url = "http://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.xz"; 8 | hash = "sha256-8sHobKCkBP8oFjG9yDd2OJknRLF1r7gG4lhxokqTTgc="; 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /pkgs/stage1/mkDerivation/default.nix: -------------------------------------------------------------------------------- 1 | { stage0, wrappers }: 2 | 3 | { name 4 | , src 5 | , builder ? ./mkDerivation-builder.sh 6 | , configureFlags ? [ ] 7 | , makeFlags ? [ ] 8 | , makeInstallFlags ? [ ] 9 | , buildInputs ? [ ] 10 | , configurePhase ? ''./configure --prefix="$out" --host=x86_64-linux $configureFlags'' 11 | , buildPhase ? ''make -j$NIX_BUILD_CORES -l$NIX_BUILD_CORES $makeFlags'' 12 | , installPhase ? ''make install $makeInstallFlags'' 13 | , ... 14 | }@args: 15 | 16 | derivation (args // { 17 | inherit name src; 18 | inherit wrappers; 19 | inherit configureFlags makeFlags makeInstallFlags; 20 | inherit buildInputs; 21 | inherit configurePhase buildPhase installPhase; 22 | 23 | system = "x86_64-linux"; # FIXME 24 | 25 | builder = "${stage0.bootstrap-tools}/bin/bash"; 26 | args = [ "-e" builder ]; 27 | 28 | bootstrapTools = stage0.bootstrap-tools; 29 | }) 30 | -------------------------------------------------------------------------------- /pkgs/stage1/mkDerivation/mkDerivation-builder.sh: -------------------------------------------------------------------------------- 1 | if [ -z "$NIX_BUILD_CORES" ]; then 2 | NIX_BUILD_CORES="1" 3 | elif [ "$NIX_BUILD_CORES" -le 0 ]; then 4 | NIX_BUILD_CORES=$($bootstrapTools/bin/nproc 2>/dev/null || true) 5 | if $bootstrapTools/bin/expr >/dev/null 2>&1 "$NIX_BUILD_CORES" : "^[0-9][0-9]*$"; then 6 | : 7 | else 8 | NIX_BUILD_CORES="1" 9 | fi 10 | fi 11 | 12 | NIX_WRAPPER_gcc_ARGS="-Wl,--dynamic-linker=$bootstrapTools/lib/ld-linux-x86-64.so.2" 13 | 14 | for path in $bootstrapTools/include-glibc \ 15 | $bootstrapTools/lib/gcc/x86_64-unknown-linux-gnu/8.3.0/include \ 16 | $bootstrapTools/lib/gcc/x86_64-unknown-linux-gnu/8.3.0/include-fixed; do 17 | 18 | NIX_WRAPPER_gcc_ARGS="$NIX_WRAPPER_gcc_ARGS -idirafter $path" 19 | done 20 | 21 | for dep in $wrappers $bootstrapTools $buildInputs; do 22 | NIX_WRAPPER_gcc_ARGS="$NIX_WRAPPER_gcc_ARGS -Wl,--rpath=$dep/lib -I $dep/include" 23 | PATH="$PATH:$dep/bin" 24 | done 25 | 26 | NIX_WRAPPER_gxx_ARGS="NIX_WRAPPER_gcc_ARGS" 27 | 28 | for path in $bootstrapTools/include/c++/8.3.0 \ 29 | $bootstrapTools/include/c++/8.3.0/x86_64-unknown-linux-gnu \ 30 | $bootstrapTools/include/c++/8.3.0/backward; do 31 | NIX_WRAPPER_gxx_ARGS="$NIX_WRAPPER_gcc_ARGS -idirafter $path" 32 | done 33 | 34 | export PATH 35 | export NIX_WRAPPER_gxx_ARGS 36 | export NIX_WRAPPER_gcc_ARGS 37 | 38 | tar -xf $src -C . 39 | 40 | sourceRoot="$(ls | head -1)" 41 | echo sourceRoot is "$sourceRoot" 42 | 43 | cd "$sourceRoot" 44 | type -p cpp 45 | 46 | echo !!!!! CONFIG PHASE 47 | eval $configurePhase 48 | 49 | echo !!!!! BUILD PHASE 50 | eval $buildPhase 51 | 52 | echo !!!!! INSTALL PHASE 53 | eval $installPhase 54 | 55 | for path in $(find "$out/bin" "$out/lib" -type f -executable); do 56 | echo Shrinking RPATH of "$path" 57 | patchelf --shrink-rpath "$path" || true 58 | done 59 | -------------------------------------------------------------------------------- /pkgs/stage1/mpc.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation 2 | , fetchurl 3 | , gmp 4 | , mpfr 5 | }: 6 | 7 | mkDerivation { 8 | name = "mpc-1.2.1"; 9 | 10 | src = fetchurl { 11 | url = "https://ftp.gnu.org/gnu/mpc/mpc-1.2.1.tar.gz"; 12 | hash = "sha256-F1A9LDld/PEGtiLcFCaDwRmUMdCVNnxqrLpu7DA0BFk="; 13 | }; 14 | 15 | buildInputs = [ gmp mpfr ]; 16 | } 17 | -------------------------------------------------------------------------------- /pkgs/stage1/mpfr.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation 2 | , fetchurl 3 | , gmp 4 | }: 5 | 6 | mkDerivation { 7 | name = "mpfr-4.1.0"; 8 | 9 | src = fetchurl { 10 | url = "http://www.mpfr.org/mpfr-4.1.0/mpfr-4.1.0.tar.xz"; 11 | hash = "sha256-DJij8XMv9spOppBVIHnanFl4ctMOluwoQU7iPJVVin8="; 12 | }; 13 | 14 | buildInputs = [ gmp ]; 15 | } 16 | -------------------------------------------------------------------------------- /pkgs/stage1/musl.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation 2 | , fetchurl 3 | , gcc 4 | , binutils 5 | }: 6 | 7 | mkDerivation { 8 | name = "musl-1.2.2"; 9 | 10 | CC = "${gcc}/bin/gcc"; 11 | AR = "${binutils}/bin/ar"; 12 | RANLIB = "${binutils}/bin/ranlib"; 13 | 14 | src = fetchurl { 15 | url = "https://musl.libc.org/releases/musl-1.2.2.tar.gz"; 16 | hash = "sha256-m5aTIgEteW3CPdono1hmA0+mfY+2fg4sRckTw9QyGd0="; 17 | }; 18 | 19 | configureFlags = [ 20 | "--enable-shared" 21 | "--enable-static" 22 | "--enable-debug" 23 | "--enable-wrapper=all" 24 | "--syslibdir=${placeholder "out"}/lib" 25 | ]; 26 | } 27 | -------------------------------------------------------------------------------- /pkgs/stage1/stage0.nix: -------------------------------------------------------------------------------- 1 | {}: 2 | 3 | import ../stage0 4 | -------------------------------------------------------------------------------- /pkgs/stage1/wrappers.nix: -------------------------------------------------------------------------------- 1 | { genWrapper, stage0 }: 2 | 3 | derivation { 4 | system = "x86_64-linux"; 5 | name = "wrappers"; 6 | 7 | builder = "${stage0.bootstrap-tools}/bin/bash"; 8 | args = [ "-e" "-c" ". $commandPath" ]; 9 | passAsFile = [ "command" ]; 10 | 11 | gccWrapper = genWrapper { 12 | name = "gcc-wrapper"; 13 | label = "gcc"; 14 | wrapped = "${stage0.bootstrap-tools}/bin/gcc"; 15 | }; 16 | 17 | gxxWrapper = genWrapper { 18 | name = "g++-wrapper"; 19 | label = "gxx"; 20 | wrapped = "${stage0.bootstrap-tools}/bin/g++"; 21 | }; 22 | 23 | command = '' 24 | export PATH="${stage0.bootstrap-tools}/bin" 25 | mkdir -p $out/bin 26 | cp $gccWrapper $out/bin/gcc 27 | cp $gxxWrapper $out/bin/g++ 28 | ''; 29 | } 30 | -------------------------------------------------------------------------------- /pkgs/stage1/writeFile.nix: -------------------------------------------------------------------------------- 1 | { stage0 }: 2 | 3 | { name, contents, executable ? false }: 4 | 5 | derivation { 6 | system = "x86_64-linux"; 7 | 8 | inherit name contents executable; 9 | 10 | builder = "${stage0.bootstrap-tools}/bin/bash"; 11 | args = [ "-e" "-c" ". $commandPath" ]; 12 | passAsFile = [ "contents" "command" ]; 13 | 14 | command = '' 15 | ${stage0.bootstrap-tools}/bin/cp $contentsPath $out 16 | [ $executable -eq 1 ] && ${stage0.bootstrap-tools}/bin/chmod +x $out 17 | ''; 18 | } 19 | -------------------------------------------------------------------------------- /pkgs/utils/attrdir.nix: -------------------------------------------------------------------------------- 1 | base: 2 | 3 | with builtins; 4 | 5 | let 6 | dirContents = readDir base; 7 | attrset = listToAttrs (concatMap genAttr (attrNames dirContents)) 8 | // { recurseForDerivations = true; }; 9 | 10 | genAttr = file: 11 | let 12 | matchResult = match ''(.+)\.(.+)'' file; 13 | name = elemAt matchResult 0; 14 | ext = elemAt matchResult 1; 15 | okay = 16 | (dirContents.${file} == "regular" && length matchResult == 2 && ext == "nix" && name != "default") 17 | || dirContents.${file} == "directory"; 18 | contents = import (base + "/${file}"); 19 | args = intersectAttrs (functionArgs contents) attrset; 20 | in 21 | if okay 22 | then [ 23 | { 24 | name = 25 | if dirContents.${file} == "directory" 26 | then file else name; 27 | value = contents args; 28 | } 29 | ] 30 | else [ ]; 31 | 32 | in 33 | attrset 34 | --------------------------------------------------------------------------------