2019-04-04 11:33:38 +03:00
|
|
|
|
#!/usr/bin/env bash
|
2021-01-01 21:49:51 +03:00
|
|
|
|
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
2019-04-04 11:33:38 +03:00
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
2019-04-09 19:59:37 +03:00
|
|
|
|
# shellcheck disable=SC2174
|
|
|
|
|
|
2019-04-04 11:33:38 +03:00
|
|
|
|
# Installs nix on a fresh machine
|
2019-04-09 19:59:37 +03:00
|
|
|
|
set -euo pipefail
|
2019-04-04 11:33:38 +03:00
|
|
|
|
|
2019-04-04 14:03:56 +03:00
|
|
|
|
## Functions ##
|
|
|
|
|
|
|
|
|
|
step() {
|
|
|
|
|
echo "step: $*" >&2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## Main ##
|
|
|
|
|
|
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
|
|
2019-04-09 19:59:37 +03:00
|
|
|
|
if [[ ! -e /nix ]]; then
|
|
|
|
|
step "Installing Nix"
|
|
|
|
|
|
|
|
|
|
sudo mkdir -m 0755 /nix
|
|
|
|
|
sudo chown "$(id -u):$(id -g)" /nix
|
2019-04-04 14:03:56 +03:00
|
|
|
|
|
2020-06-18 11:34:08 +03:00
|
|
|
|
curl -sSfL https://nixos.org/releases/nix/nix-2.3.3/install | bash
|
2019-04-09 19:59:37 +03:00
|
|
|
|
fi
|
2019-04-04 14:03:56 +03:00
|
|
|
|
|
|
|
|
|
# shellcheck source=../dev-env/lib/ensure-nix
|
|
|
|
|
source dev-env/lib/ensure-nix
|
|
|
|
|
|
2019-04-04 15:47:32 +03:00
|
|
|
|
export NIX_CONF_DIR=$PWD/dev-env/etc
|
|
|
|
|
|
2019-04-04 14:03:56 +03:00
|
|
|
|
step "Building dev-env dependencies"
|
2019-05-06 15:52:12 +03:00
|
|
|
|
|
|
|
|
|
# Nix cache downloads can sometimes be flaky and end with "unexpected end-of-file" so we
|
|
|
|
|
# repeat this a few times. There does not seem to be an option that we can pass to nix
|
|
|
|
|
# to make it retry itself. See https://github.com/NixOS/nix/issues/2794 for the issue requesting
|
|
|
|
|
# this feature.
|
2019-05-07 14:55:30 +03:00
|
|
|
|
NIX_FAILED=0
|
2019-05-06 15:52:12 +03:00
|
|
|
|
for i in `seq 10`; do
|
2019-05-07 14:55:30 +03:00
|
|
|
|
NIX_FAILED=0
|
2020-02-26 17:52:08 +03:00
|
|
|
|
nix-build nix -A tools -A ci-cached 2>&1 | tee nix_log || NIX_FAILED=1
|
2019-05-06 15:52:12 +03:00
|
|
|
|
# It should be in the last line but let’s use the last 3 and wildcards
|
|
|
|
|
# to be robust against slight changes.
|
2019-07-03 15:00:43 +03:00
|
|
|
|
if [[ $NIX_FAILED -ne 0 ]] &&
|
|
|
|
|
([[ $(tail -n 3 nix_log) == *"unexpected end-of-file"* ]] ||
|
|
|
|
|
[[ $(tail -n 3 nix_log) == *"decompressing xz file"* ]]); then
|
2019-05-06 15:52:12 +03:00
|
|
|
|
echo "Restarting nix-build due to failed cache download"
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
break
|
|
|
|
|
done
|
2019-05-07 14:55:30 +03:00
|
|
|
|
if [[ $NIX_FAILED -ne 0 ]]; then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|