2024-01-26 04:39:59 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2024-04-11 03:36:34 +00:00
|
|
|
set -eo pipefail
|
2024-01-26 04:39:59 +00:00
|
|
|
|
2024-05-02 03:30:49 +00:00
|
|
|
toplevel="$(git rev-parse --show-toplevel)"
|
|
|
|
|
|
|
|
# Build just the single installable and forward any other arguments too
|
|
|
|
just() {
|
|
|
|
# uses nix-output-monitor (nom) if available
|
|
|
|
if command -v nom &> /dev/null; then
|
|
|
|
nom build "$@"
|
|
|
|
else
|
|
|
|
nix build -L "$@"
|
|
|
|
fi
|
|
|
|
|
2024-05-06 04:08:20 +00:00
|
|
|
if [ -z "$ATTIC_TOKEN" ]; then
|
2024-05-02 03:30:49 +00:00
|
|
|
echo "\$ATTIC_TOKEN is unset, skipping uploading to the binary cache"
|
2024-05-06 04:08:20 +00:00
|
|
|
return
|
2024-05-02 03:30:49 +00:00
|
|
|
fi
|
|
|
|
|
2024-05-06 04:08:20 +00:00
|
|
|
# historical "conduit" store for compatibility purposes, same as conduwuit
|
|
|
|
nix run --inputs-from "$toplevel" attic -- \
|
|
|
|
login \
|
|
|
|
conduit \
|
|
|
|
"${ATTIC_ENDPOINT:-https://attic.kennel.juneis.dog/conduit}" \
|
|
|
|
"$ATTIC_TOKEN"
|
|
|
|
|
|
|
|
# Find all output paths of the installables and their build dependencies
|
2024-10-25 01:29:17 +00:00
|
|
|
#readarray -t derivations < <(nix path-info --derivation "$@")
|
|
|
|
derivations=()
|
|
|
|
while IFS=$'\n' read derivation; do
|
|
|
|
derivations+=("$derivation")
|
|
|
|
done < <(nix path-info --derivation "$@")
|
|
|
|
|
2024-05-06 04:08:20 +00:00
|
|
|
cache=()
|
|
|
|
for derivation in "${derivations[@]}"; do
|
|
|
|
cache+=(
|
|
|
|
"$(nix-store --query --requisites --include-outputs "$derivation")"
|
|
|
|
)
|
|
|
|
done
|
|
|
|
|
2024-09-08 18:51:34 +00:00
|
|
|
withattic() {
|
|
|
|
nix shell --inputs-from "$toplevel" attic --command xargs attic push "$@" <<< "${cache[*]}"
|
|
|
|
}
|
2024-05-06 04:08:20 +00:00
|
|
|
# Upload them to Attic (conduit store)
|
|
|
|
#
|
|
|
|
# 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'
|
2024-09-08 18:51:34 +00:00
|
|
|
withattic conduit || withattic conduit || withattic conduit || true
|
2024-05-06 04:08:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# main "conduwuit" store
|
|
|
|
nix run --inputs-from "$toplevel" attic -- \
|
|
|
|
login \
|
|
|
|
conduwuit \
|
|
|
|
"${ATTIC_ENDPOINT:-https://attic.kennel.juneis.dog/conduwuit}" \
|
|
|
|
"$ATTIC_TOKEN"
|
|
|
|
|
2024-06-16 01:24:25 +00:00
|
|
|
# Upload them to Attic (conduwuit store) and Cachix
|
2024-05-06 04:08:20 +00:00
|
|
|
#
|
|
|
|
# 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'
|
2024-09-08 18:51:34 +00:00
|
|
|
withattic conduwuit || withattic conduwuit || withattic conduwuit || true
|
2024-06-16 01:24:25 +00:00
|
|
|
|
|
|
|
# push to cachix if available
|
|
|
|
if [ "$CACHIX_AUTH_TOKEN" ]; then
|
|
|
|
nix shell --inputs-from "$toplevel" cachix -c xargs \
|
|
|
|
cachix push conduwuit <<< "${cache[*]}"
|
|
|
|
fi
|
2024-05-06 04:08:20 +00:00
|
|
|
)
|
2024-05-02 03:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Build and cache things needed for CI
|
|
|
|
ci() {
|
|
|
|
cache=(
|
|
|
|
--inputs-from "$toplevel"
|
|
|
|
|
|
|
|
# Keep sorted
|
2024-10-25 01:29:17 +00:00
|
|
|
#"$toplevel#devShells.x86_64-linux.default"
|
|
|
|
#"$toplevel#devShells.x86_64-linux.all-features"
|
2024-05-02 03:30:49 +00:00
|
|
|
attic#default
|
2024-06-16 01:24:25 +00:00
|
|
|
cachix#default
|
2024-05-02 03:30:49 +00:00
|
|
|
nixpkgs#direnv
|
|
|
|
nixpkgs#jq
|
|
|
|
nixpkgs#nix-direnv
|
|
|
|
)
|
|
|
|
|
|
|
|
just "${cache[@]}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Build and cache *all* the package outputs from the flake.nix
|
|
|
|
packages() {
|
|
|
|
declare -a cache="($(
|
|
|
|
nix flake show --json 2> /dev/null |
|
|
|
|
nix run --inputs-from "$toplevel" nixpkgs#jq -- \
|
|
|
|
-r \
|
|
|
|
'.packages."x86_64-linux" | keys | map("'"$toplevel"'#" + .) | @sh'
|
|
|
|
))"
|
|
|
|
|
|
|
|
just "${cache[@]}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
eval "$@"
|