#!/usr/bin/env bash # vim: set ft=bash # adapted from https://github.com/cachix/install-nix-action/blob/master/lib/install-nix.sh set -euo pipefail install_nix() { echo "Installing Nix" # Set jobs to number of cores sudo sh -c 'echo max-jobs = auto >> /tmp/nix.conf' # Allow binary caches for runner user sudo sh -c 'echo trusted-users = root runner >> /tmp/nix.conf' sh <(curl -L ${INPUT_INSTALL_URL:-https://nixos.org/nix/install}) \ --daemon --daemon-user-count 4 --nix-extra-conf-file /tmp/nix.conf --darwin-use-unencrypted-nix-store-volume --no-channel-add if [[ $OSTYPE =~ darwin ]]; then # Disable spotlight indexing of /nix to speed up performance sudo mdutil -i off /nix # macOS needs certificates hints cert_file=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt echo "::set-env name=NIX_SSL_CERT_FILE::$cert_file" export NIX_SSL_CERT_FILE=$cert_file sudo launchctl setenv NIX_SSL_CERT_FILE "$cert_file" fi # Set paths echo "::add-path::/nix/var/nix/profiles/per-user/runner/profile/bin" echo "::add-path::/nix/var/nix/profiles/default/bin" . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' } install_cachix() { echo "Installing cachix" nix-env -iA cachix -f https://cachix.org/api/v1/install echo "Setting up cachix" cachix_cache="${GITHUB_REPOSITORY##*/}" echo "Using cache '$cachix_cache' for '$GITHUB_REPOSITORY'" cachix use "$cachix_cache" script_path="$HOME/.local/bin/save-cache" mkdir -p "$(dirname $script_path)" } save_cache() { cachix_cache="${GITHUB_REPOSITORY##*/}" echo "Using cache '$cachix_cache' for '$GITHUB_REPOSITORY'" set +x if [ -z "${CACHIX_SIGNING_KEY:-}" ] && [ -n "${INPUT_CACHIX_SIGNING_KEY:-}" ]; then echo "CACHIX_SIGNING_KEY not set, but INPUT_CACHIX_SIGNING_KEY is present" echo "setting CACHIX_SIGNING_KEY" export CACHIX_SIGNING_KEY="$INPUT_CACHIX_SIGNING_KEY" fi if [ -n "${CACHIX_SIGNING_KEY:-}" ]; then echo "CACHIX_SIGNING_KEY is set, uploading cache" nix path-info --all | cachix push $cachix_cache else echo "CACHIX_SIGNING_KEY not set, not uploading cache" fi set -x } set -x if [ "${INSTALL_NIX_WAS_RUN:-}" == "1" ]; then save_cache else install_nix install_cachix echo "::set-env name=INSTALL_NIX_WAS_RUN::1" fi