2019-07-15 16:34:33 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2019-08-26 16:56:55 +00:00
|
|
|
gitRoot=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
|
|
|
|
resultPath="${gitRoot}/result/"
|
|
|
|
|
2019-07-15 16:34:33 +00:00
|
|
|
# cleanup for artifacts created during builds
|
|
|
|
function cleanup() {
|
|
|
|
# clear trapped signals
|
|
|
|
trap - EXIT ERR INT QUIT
|
2019-08-22 14:19:53 +00:00
|
|
|
# do the actual cleanup, ignore failure
|
|
|
|
if ./nix/clean.sh "${nixResultPath}"; then
|
|
|
|
echo "Successful cleanup!"
|
|
|
|
elif [[ -n "${JENKINS_URL}" ]]; then
|
|
|
|
# in CI removing some paths can fail due to parallel builds
|
|
|
|
echo "Ignoring cleanup failure in CI."
|
|
|
|
else
|
|
|
|
echo "Failed cleanup!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-07-15 16:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup EXIT ERR INT QUIT
|
|
|
|
|
|
|
|
# build output will end up under /nix, we have to extract it
|
|
|
|
function extractResults() {
|
|
|
|
local nixResultPath="$1"
|
|
|
|
echo "Saving build result: ${nixResultPath}"
|
2019-08-26 16:56:55 +00:00
|
|
|
mkdir -p "${resultPath}"
|
|
|
|
cp -vfr ${nixResultPath}/* "${resultPath}"
|
|
|
|
chmod u+w -R "${resultPath}"
|
2019-07-15 16:34:33 +00:00
|
|
|
}
|
|
|
|
|
2019-08-20 19:45:41 +00:00
|
|
|
# Load Nix profile
|
|
|
|
. ~/.nix-profile/etc/profile.d/nix.sh
|
|
|
|
|
2019-07-15 16:34:33 +00:00
|
|
|
targetAttr="${1}"
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [[ -z "${targetAttr}" ]]; then
|
|
|
|
echo "First argument is madatory and has to specify the Nix attribute!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Some defaults flags, --pure could be optional in the future
|
|
|
|
nixOpts=(
|
|
|
|
"--pure"
|
|
|
|
"--fallback"
|
|
|
|
"--no-out-link"
|
|
|
|
"--show-trace"
|
|
|
|
"--argstr target-os ${TARGET_OS}"
|
|
|
|
"--attr ${targetAttr}"
|
|
|
|
"${@}"
|
|
|
|
"default.nix"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Run the actual build
|
|
|
|
echo "Running: nix-build ${nixOpts[@]}"
|
|
|
|
nixResultPath=$(nix-build ${nixOpts[@]})
|
|
|
|
|
|
|
|
extractResults "${nixResultPath}"
|
|
|
|
|
|
|
|
echo "SUCCESS"
|