infrastructure/scripts/nix-cache.sh
2024-12-23 14:02:22 +01:00

29 lines
790 B
Bash

# SPDX-FileCopyrightText: 2024 Ryan Lahfa <ryan.lahfa@dgnum.eu>
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
# SPDX-FileContributor: Maurice Debray <maurice@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
# Build the derivation and send it to the great beyond
drv=$(nix-instantiate "$@")
nix-store --query --requisites --force-realise --include-outputs "$drv" | grep -v '.*\.drv' > paths.txt
if [ "$STORE_PASSWORD" == "" ]; then
echo "No password given for the remote cache, uploading cannot take place."
exit 0
fi
cat <<EOF >.netrc
default
login $STORE_USER
password $STORE_PASSWORD
EOF
nix copy \
--extra-experimental-features nix-command \
--to "$STORE_ENDPOINT?compression=none" \
--netrc-file .netrc \
"$(nix-store --realise "$drv")"
rm .netrc