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