-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild-using-nix.sh
executable file
·47 lines (40 loc) · 1.47 KB
/
build-using-nix.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/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 "$@"