This commit is contained in:
Kat Inskip 2024-07-13 16:58:48 -07:00
parent 025a7dd039
commit b4b8f5988f
Signed by: kat
GPG key ID: 465E64DECEA8CF0F
2 changed files with 81 additions and 79 deletions

View file

@ -36,7 +36,7 @@ in {
step.${name} = {
name = "build system closure for ${name}";
order = 500;
run = "nix run .#nf-build-system -- nixosConfigurations.${name}.config.system.build.topLevel ${name} NixOS";
run = "nix run .#nf-build-system -- nixosConfigurations.${name}.config.system.build.toplevel ${name} NixOS";
env = {
CACHIX_SIGNING_KEY = "\${{ secrets.CACHIX_SIGNING_KEY }}";
DISCORD_WEBHOOK_LINK = "\${{ secrets.DISCORD_WEBHOOK_LINK }}";

View file

@ -1,45 +1,25 @@
#!/usr/bin/env bash
set -eu
set -euo pipefail
DISCORD_WEBHOOK_LINK=${DISCORD_WEBHOOK_LINK:-""}
SYSTEM_LINK=$1
ALIAS=$2
SYSTEM_TYPE=$3
SYSTEM_LINK=${1:-""}
ALIAS=${2:-""}
SYSTEM_TYPE=${3:-""}
# Helper functions
send_discord_message() {
local message="$1"
if [[ -n "$DISCORD_WEBHOOK_LINK" ]]; then
local escaped_message=$(printf '%s' "$message" | jq -R -s '.')
curl -s -H "Accept: application/json" -H "Content-Type: application/json" \
-X POST --data "{\"content\": $escaped_message}" "$DISCORD_WEBHOOK_LINK"
else
echo "Discord message (not sent): $message"
fi
}
send_discord_message "Starting ${SYSTEM_TYPE} system build for ${ALIAS}"
if [[ -n ${CACHIX_SIGNING_KEY-} ]]; then
export NF_UPDATE_CACHIX_PUSH=1
fi
cd "$NF_CONFIG_ROOT"
if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then
export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result}
fi
if [[ ${GITHUB_ACTIONS-} = true && ${RUNNER_NAME-} = "Github Actions"* ]]; then
# low disk space available on public runners...
echo "enabled GC between builds due to restricted disk space..." >&2
export NF_ACTIONS_TEST_GC=1
fi
NIX_BUILD_ARGS=(
--show-trace
)
NIX_BUILD_ARGS_ASYNC=()
init_nfargs() {
nflinksuffix="-L"
shift
local nflinksuffix="-L"
nfargs=(
"${NIX_BUILD_ARGS[@]}"
@ -66,48 +46,70 @@ nfgc() {
nix-collect-garbage -d
fi
}
# Main script
if [[ -z "$SYSTEM_LINK" || -z "$ALIAS" || -z "$SYSTEM_TYPE" ]]; then
echo "Usage: $0 <SYSTEM_LINK> <ALIAS> <SYSTEM_TYPE>" >&2
exit 1
fi
send_discord_message "Starting ${SYSTEM_TYPE} system build for ${ALIAS}"
if [[ -n ${CACHIX_SIGNING_KEY-} ]]; then
export NF_UPDATE_CACHIX_PUSH=1
fi
cd "$NF_CONFIG_ROOT"
if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then
export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result}
fi
if [[ ${GITHUB_ACTIONS-} = true && ${RUNNER_NAME-} = "Github Actions"* ]]; then
echo "Enabled GC between builds due to restricted disk space..." >&2
export NF_ACTIONS_TEST_GC=1
fi
NIX_BUILD_ARGS=(
--show-trace
)
NIX_BUILD_ARGS_ASYNC=()
nfsystem=$ALIAS
nfinstallable="${NF_CONFIG_ROOT}#${SYSTEM_LINK}"
init_nfargs "-$nfsystem"
init_nfargs
nfwarn=
if [[ " ${NF_NIX_SYSTEMS_WARN[*]} " = *" $nfsystem "* ]]; then
if [[ -n "${NF_NIX_SYSTEMS_WARN-}" && " ${NF_NIX_SYSTEMS_WARN[*]} " = *" $nfsystem "* ]]; then
nfwarn=1
fi
if [[ -n ${NF_ACTIONS_TEST_ASYNC-} && -z $nfwarn ]]; then
NIX_BUILD_ARGS_ASYNC+=("$nfinstallable")
continue
fi
else
echo "Building ${nfsystem}..." >&2
echo >&2
echo "building ${nfsystem}..." >&2
echo >&2
nfbuildexit=0
nix build "$nfinstallable" \
"${nfargs[@]}" \
"$@" || nfbuildexit=$?
if [[ $nfbuildexit -ne 0 ]]; then
if ! nix build "$nfinstallable" "${nfargs[@]}"; then
if [[ -n $nfwarn ]]; then
send_discord_message "build failure allowed for ${nfsystem}, ignoring..."
echo "build failure allowed for ${nfsystem}, ignoring..." >&2
continue
send_discord_message "Build failure allowed for ${nfsystem}, ignoring..."
echo "Build failure allowed for ${nfsystem}, ignoring..." >&2
else
send_discord_message "Build failure for ${nfsystem}, problem!"
exit 1
fi
else
send_discord_message "${SYSTEM_TYPE} system build of ${ALIAS} succeeded!"
nfgc
fi
send_discord_message "build failure for ${nfsystem}, problem!"
exit $nfbuildexit
fi
send_discord_message "${SYSTEM_TYPE} system build of ${ALIAS} succeeded!"
nfgc
if [[ -n ${NF_ACTIONS_TEST_ASYNC-} ]]; then
init_nfargs ""
nix build \
"${nfargs[@]}" \
"${NIX_BUILD_ARGS_ASYNC[@]}" \
"$@"
init_nfargs
if nix build "${nfargs[@]}" "${NIX_BUILD_ARGS_ASYNC[@]}"; then
nfgc
else
send_discord_message "Async build failure for ${nfsystem}, problem!"
exit 1
fi
fi