#!/usr/bin/env bash

# Note: should be sourced, not executed.

set -euo pipefail

x_was_set=
if [ -o xtrace ]; then
    echo "disabling xtrace"
    x_was_set=1
    set +x
fi

CACHIX_PREFIX=
if [ -f "$HOME/.cachix-token" ]; then
    echo "setting cachix credentials"
    token="$(cat ~/.cachix-token)"
    export CACHIX_AUTH_TOKEN="$token"
    CACHIX_PREFIX="cachix watch-exec procfarm --"
fi
export CACHIX_PREFIX="$CACHIX_PREFIX"

if [ -n "$x_was_set" ]; then
    echo "enabling xtrace"
    set -x
fi
