forked from NixOS/aarch64-build-box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·81 lines (63 loc) · 2.63 KB
/
build.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env nix-shell
#!nix-shell -p gawk gnused -i bash -I nixpkgs=channel:nixos-unstable-small
set -eu
set -o pipefail
if [ "${1:-x}" = "x" ]; then
./nix/update-nixpkgs.sh
./nix/update-ofborg-path.sh
fi
cfgOpt() {
ret=$(awk '$1 == "'"$1"'" { print $2; }' build.cfg)
if [ -z "$ret" ]; then
echo "Config option '$1' isn't specified in build.cfg" >&2
echo "Example format:"
echo "$1 value"
echo ""
exit 1
fi
echo "$ret"
}
#buildHost=$(cfgOpt "buildHost")
#target=$(cfgOpt "imageName")
git clone https://github.com/grahamc/packet-nix-builder
nix-build -I nixpkgs=channel:nixos-unstable-small ./packet-nix-builder/build-support/aarch64-setup.nix --out-link ./importer
./importer
buildHost=$(cat machines | grep aarch64 | grep big-parallel | cut -d' ' -f1 | head -n1)
printf "%s %s\n" \
"$(echo "$buildHost" | cut -d@ -f2)" \
"$(grep "$buildHost" machines | head -n1 | cut -d' ' -f8 | base64 -d)" > KnownHosts
#pxeHost=$(cfgOpt "pxeHost")
#pxeDir=$(cfgOpt "pxeDir")
#opensslServer=$(cfgOpt "opensslServer")
#opensslPort=$(cfgOpt "opensslPort")
target=nix-community-aarch64
pxeDir=/var/lib/nginx/netboot/webroot/
opensslServer=netboot.gsc.io
opensslPort=61616
tmpDir=$(mktemp -t -d nixos-rebuild-aarch-community.XXXXXX)
SSHOPTS="${NIX_SSHOPTS:-} -o UserKnownHostsFile=$(pwd)/KnownHosts -o ControlMaster=auto -o ControlPath=$tmpDir/ssh-%n -o ControlPersist=60"
recvpid=0
cleanup() {
for ctrl in "$tmpDir"/ssh-*; do
ssh -o ControlPath="$ctrl" -O exit dummyhost 2>/dev/null || true
done
rm -rf "$tmpDir"
if [ "$recvpid" -gt 0 ]; then
kill -9 "$recvpid"
fi
}
trap cleanup EXIT
set -eu
drv=$(nix-instantiate -I nixpkgs=channel:nixos-unstable-small ./configuration.nix --show-trace)
NIX_SSHOPTS=$SSHOPTS nix-copy-closure --use-substitutes --gzip --to "$buildHost" "$drv"
out=$(ssh $SSHOPTS "$buildHost" NIX_REMOTE=daemon nix-store --keep-going -r "$drv" -j 5 --cores 45 --add-root ./community-build-box --indirect)
ssh $SSHOPTS "$pxeHost" rm -rf "${pxeDir}/${target}.next"
ssh $SSHOPTS "$pxeHost" mkdir -p "${pxeDir}/${target}.next"
ssh $SSHOPTS "$pxeHost" -- nix-shell -p socat mbuffer openssl --run ":"
ssh $SSHOPTS "$buildHost" -- tar -C "$out" -hvvvczf - '{Image,initrd,netboot.ipxe}' \
| ssh $SSHOPTS "$pxeHost" -- tar -C "${pxeDir}/${target}.next" -vvvzxf -
ssh $SSHOPTS "$pxeHost" mkdir -p "${pxeDir}/${target}"
ssh $SSHOPTS "$pxeHost" rm -rf "${pxeDir}/${target}.old"
ssh $SSHOPTS "$pxeHost" mv "${pxeDir}/${target}" "${pxeDir}/${target}.old"
ssh $SSHOPTS "$pxeHost" mv "${pxeDir}/${target}.next" "${pxeDir}/${target}"