Files
status-react/nix/scripts/build.sh
T

75 lines
2.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2022-01-05 14:32:02 +01:00
# This script is a wrapper around nix-build with some niceties.
set -e
2019-11-29 11:20:08 +01:00
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
resultPath="${GIT_ROOT}/result/"
2020-02-19 14:15:28 +01:00
source "${GIT_ROOT}/scripts/colors.sh"
source "${GIT_ROOT}/nix/scripts/source.sh"
# cleanup for artifacts created during builds
2022-01-05 14:32:02 +01:00
cleanup() {
# clear trapped signals
trap - EXIT ERR INT QUIT
# do the actual cleanup, ignore failure
2019-11-29 11:20:08 +01:00
if ${GIT_ROOT}/nix/scripts/clean.sh "${nixResultPath}"; then
2020-02-19 14:15:28 +01:00
echo -e "${GRN}Successful cleanup!${RST}"
2019-11-29 11:20:08 +01:00
elif [[ -n "${JENKINS_URL}" ]]; then
2019-08-22 10:19:53 -04:00
# in CI removing some paths can fail due to parallel builds
2020-02-19 14:15:28 +01:00
echo -e "${YLW}Ignoring cleanup failure in CI.${RST}"
2019-08-22 10:19:53 -04:00
else
2020-02-19 14:15:28 +01:00
echo -e "${RED}Failed cleanup!${RST}"
2019-08-22 10:19:53 -04:00
exit 1
fi
}
2020-04-23 20:19:12 +02:00
# If you want to clean after every build set _NIX_CLEAN=true
if [[ -n "${_NIX_CLEAN}" ]]; then
trap cleanup EXIT ERR INT QUIT
2020-04-22 19:05:18 +02:00
fi
# build output will end up under /nix, we have to extract it
2022-01-05 14:32:02 +01:00
extractResults() {
local nixResultPath="$1"
mkdir -p "${resultPath}"
2020-04-23 20:19:12 +02:00
cp -vfr ${nixResultPath}/* "${resultPath}" | sed 's#'${PWD}'#.#'
2019-08-06 18:16:51 +02:00
chmod -R u+w "${resultPath}"
}
2020-06-19 15:43:58 +02:00
TARGET="${1}"
shift
2020-06-19 15:43:58 +02:00
if [[ -z "${TARGET}" ]]; then
2020-02-19 14:15:28 +01:00
echo -e "${RED}First argument is mandatory and has to specify the Nix attribute!${RST}"
exit 1
fi
# Hack fix for missing Android SDK for aarch64 on Darwin. See systemOverride in `nix/pkgs.nix`.
if [[ "${TARGET}" =~ ^(targets.status-go.mobile.android|targets.mobile.android.build)$ ]]; then
os=$(uname -s | tr '[:upper:]' '[:lower:]')
export NIXPKGS_SYSTEM_OVERRIDE="x86_64-${os}"
fi
# Some defaults flags, --pure could be optional in the future.
# NOTE: The --keep-failed flag can be used for debugging issues.
nixOpts=(
"--pure"
"--fallback"
"--no-out-link"
"--show-trace"
2020-06-19 15:43:58 +02:00
"--attr" "${TARGET}"
)
2020-06-19 15:43:58 +02:00
# Save derivation from being garbage collected
"${GIT_ROOT}/nix/scripts/gcroots.sh" "${TARGET}" "${@}"
2020-06-19 15:43:58 +02:00
# Run the actual build
echo -e "${GRN}Running:${RST} ${BLD}nix-build "${nixOpts[@]}" ${@}${RST}"
nixResultPath=$(nix-build "${nixOpts[@]}" "${@}" default.nix)
2020-04-23 20:19:12 +02:00
echo -e "\n${YLW}Extracting result${RST}: ${BLD}${nixResultPath}${RST}"
extractResults "${nixResultPath}"
2020-04-23 20:19:12 +02:00
echo -e "\n${GRN}SUCCESS${RST}"