#!/usr/bin/env bash # this is entirely optional and for development purposes only # just use `nix-build` and you should be fine # build with ccache and without /bin/sh present # your nix needs experimental-options = ca-derivations # and you need root access / to be a trusted user set -ue CCACHE_HOST=/var/cache/ccache mkdir -p $CCACHE_HOST/data sudo chgrp nixbld $CCACHE_HOST $CCACHE_HOST/data sudo chmod g+ws $CCACHE_HOST $CCACHE_HOST/data if [[ ! -e $CCACHE_HOST/bin/ccache ]]; then nix build 'nixpkgs#pkgsStatic.ccache' --out-link $CCACHE_HOST/result mkdir -p $CCACHE_HOST/bin cp --reflink=auto $CCACHE_HOST/result/bin/ccache $CCACHE_HOST/bin/ccache rm $CCACHE_HOST/result fi [[ -e $CCACHE_HOST/setup ]] || cat > $CCACHE_HOST/setup <<\EOF mkdir -p .ccache-wrappers for prefix in '' x86_64-linux- x86_64-linux-musl- x86_64-linux-unknown-; do for name in cc c++ gcc g++ clang clang++ tcc; do if command -v $prefix$name; then ln -s /ccache/bin/ccache .ccache-wrappers/$prefix$name fi done done export PATH="$(pwd)/.ccache-wrappers:/ccache/bin:$PATH" export CCACHE_DIR="/ccache/data/$1" export CCACHE_COMPILERCHECK=content export CCACHE_SLOPPINESS=include_file_ctime,include_file_mtime export CCACHE_MAXSIZE=0 export CCACHE_UMASK=005 export CCACHE_NOHASHDIR=1 export CCACHE_BASEDIR="$(pwd)" EOF chmod +x $CCACHE_HOST/setup nix-build -A stage1.protomusl nix-build -A stage1.protobusybox nix-build -A stage1.tinycc sudo env "NIX_CONFIG=sandbox-paths = /ccache=$CCACHE_HOST" nix-build "$@"