2020-12-11 12:26:07 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Build a single-output derivation and store it in 'cachixCache'.
|
|
|
|
# Skip the build if it is already cached.
|
|
|
|
# Accepts the same arguments as nix-instantiate.
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2022-08-16 19:00:00 +00:00
|
|
|
CACHIX_SIGNING_KEY="${CACHIX_SIGNING_KEY:-}"
|
2020-12-11 12:26:07 +00:00
|
|
|
cachixCache=nix-bitcoin
|
|
|
|
|
|
|
|
trap 'echo Error at line $LINENO' ERR
|
|
|
|
|
|
|
|
tmpDir=$(mktemp -d -p /tmp)
|
2022-08-16 19:00:00 +00:00
|
|
|
trap 'rm -rf $tmpDir' EXIT
|
2021-01-30 09:46:59 +00:00
|
|
|
|
2020-12-11 12:26:07 +00:00
|
|
|
## Instantiate
|
|
|
|
|
2022-08-16 19:00:00 +00:00
|
|
|
time nix-instantiate "$@" --add-root "$tmpDir/drv" --indirect > /dev/null
|
|
|
|
printf "instantiated "; realpath "$tmpDir/drv"
|
2020-12-11 12:26:07 +00:00
|
|
|
|
2022-08-16 19:00:00 +00:00
|
|
|
outPath=$(nix-store --query "$tmpDir/drv")
|
|
|
|
if nix path-info --store "https://${cachixCache}.cachix.org" "$outPath" &>/dev/null; then
|
2020-12-11 12:26:07 +00:00
|
|
|
echo "$outPath has already been built successfully."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Build
|
|
|
|
|
|
|
|
if [[ -v CIRRUS_CI ]]; then
|
2022-08-16 19:00:00 +00:00
|
|
|
cachix use "$cachixCache"
|
2020-12-11 12:26:07 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $CACHIX_SIGNING_KEY ]]; then
|
|
|
|
# Speed up task by uploading store paths as soon as they are created
|
2021-02-01 21:53:24 +00:00
|
|
|
buildCmd="cachix watch-exec $cachixCache nix-build --"
|
|
|
|
else
|
|
|
|
buildCmd=nix-build
|
2020-12-11 12:26:07 +00:00
|
|
|
fi
|
|
|
|
|
2022-08-16 19:00:00 +00:00
|
|
|
$buildCmd --out-link "$tmpDir/result" "$tmpDir/drv" >/dev/null
|
2020-12-11 12:26:07 +00:00
|
|
|
|
|
|
|
if [[ $CACHIX_SIGNING_KEY ]]; then
|
2022-08-16 19:00:00 +00:00
|
|
|
cachix push "$cachixCache" "$outPath"
|
2020-12-11 12:26:07 +00:00
|
|
|
fi
|
|
|
|
|
2022-08-16 19:00:00 +00:00
|
|
|
echo "$outPath"
|