2024-05-05 09:28:48 +01:00
|
|
|
#!/usr/bin/env bash
|
2024-01-25 19:37:35 +00:00
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2024-05-01 21:54:32 +01:00
|
|
|
# Build the installable and forward any other arguments too. Also, use
|
|
|
|
# nix-output-monitor instead if it's available.
|
|
|
|
if command -v nom &> /dev/null; then
|
|
|
|
nom build "$@"
|
|
|
|
else
|
|
|
|
nix build "$@"
|
|
|
|
fi
|
2024-01-25 19:37:35 +00:00
|
|
|
|
|
|
|
if [ ! -z ${ATTIC_TOKEN+x} ]; then
|
2024-03-05 07:47:46 +00:00
|
|
|
nix run --inputs-from . attic -- \
|
|
|
|
login \
|
|
|
|
conduit \
|
2024-04-28 17:10:25 +01:00
|
|
|
"${ATTIC_ENDPOINT:-https://attic.conduit.rs/conduit}" \
|
2024-01-25 19:37:35 +00:00
|
|
|
"$ATTIC_TOKEN"
|
|
|
|
|
2024-05-01 21:54:32 +01:00
|
|
|
readarray -t derivations < <(nix path-info "$@" --derivation)
|
2024-05-05 09:25:39 +01:00
|
|
|
for derivation in "${derivations[@]}"; do
|
|
|
|
cache+=(
|
|
|
|
"$(nix-store --query --requisites --include-outputs "$derivation")"
|
|
|
|
)
|
|
|
|
done
|
|
|
|
|
|
|
|
# Upload them to Attic
|
|
|
|
#
|
|
|
|
# Use `xargs` and a here-string because something would probably explode if
|
|
|
|
# several thousand arguments got passed to a command at once. Hopefully no
|
|
|
|
# store paths include a newline in them.
|
|
|
|
(
|
|
|
|
IFS=$'\n'
|
|
|
|
nix shell --inputs-from . attic -c xargs \
|
|
|
|
attic push conduit <<< "${cache[*]}"
|
|
|
|
)
|
2024-05-01 21:54:32 +01:00
|
|
|
|
2024-01-25 19:37:35 +00:00
|
|
|
else
|
|
|
|
echo "\$ATTIC_TOKEN is unset, skipping uploading to the binary cache"
|
|
|
|
fi
|