2019-04-05 17:22:49 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2019-04-09 15:14:32 +00:00
|
|
|
#
|
|
|
|
# This script is used by the Makefile to have an implicit nix-shell.
|
2019-06-04 16:50:29 +00:00
|
|
|
# The following environment variables modify the script behavior:
|
2019-11-29 10:20:08 +00:00
|
|
|
# - TARGET: This attribute is passed as `targets` arg to Nix, limiting the scope
|
2019-06-04 16:50:29 +00:00
|
|
|
# of the Nix expressions.
|
2019-07-15 16:34:33 +00:00
|
|
|
# - _NIX_ATTR: Used to specify an attribute set from inside the expression in `default.nix`.
|
|
|
|
# This allows for drilling down into a specific attribute in Nix expressions.
|
|
|
|
# - _NIX_PURE: This variable allows for making the shell pure with the use of --pure.
|
|
|
|
# Take note that this makes Nix tools like `nix-build` unavailable in the shell.
|
2019-11-15 15:04:36 +00:00
|
|
|
# - _NIX_KEEP: This variable allows specifying which env vars to keep for Nix pure shell.
|
2019-04-09 15:14:32 +00:00
|
|
|
|
2019-04-05 17:22:49 +00:00
|
|
|
GREEN='\033[0;32m'
|
2019-07-16 20:34:04 +00:00
|
|
|
YELLOW='\033[1;33m'
|
2019-04-05 17:22:49 +00:00
|
|
|
NC='\033[0m'
|
|
|
|
|
|
|
|
export TERM=xterm # fix for colors
|
|
|
|
shift # we remove the first -c from arguments
|
2019-04-09 15:14:32 +00:00
|
|
|
|
2019-04-05 17:22:49 +00:00
|
|
|
if ! command -v "nix" >/dev/null 2>&1; then
|
2019-04-09 15:14:32 +00:00
|
|
|
if [ -f ~/.nix-profile/etc/profile.d/nix.sh ]; then
|
|
|
|
. ~/.nix-profile/etc/profile.d/nix.sh
|
2019-05-07 15:57:30 +00:00
|
|
|
elif [ "$IN_NIX_SHELL" != 'pure' ]; then
|
2019-09-10 09:50:09 +00:00
|
|
|
echo -e "${GREEN}Setting up environment...${NC}" > /dev/stderr
|
2019-04-09 15:14:32 +00:00
|
|
|
./scripts/setup
|
2019-04-11 12:48:53 +00:00
|
|
|
|
|
|
|
. ~/.nix-profile/etc/profile.d/nix.sh
|
2019-04-09 15:14:32 +00:00
|
|
|
fi
|
2019-04-05 17:22:49 +00:00
|
|
|
fi
|
2019-04-09 15:14:32 +00:00
|
|
|
|
2019-07-16 20:34:04 +00:00
|
|
|
if !command -v "nix" >/dev/null 2>&1; then
|
2019-09-10 09:50:09 +00:00
|
|
|
echo "Nix not available, sourcing profile failed!" > /dev/stderr
|
2019-07-16 20:34:04 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2019-06-04 16:50:29 +00:00
|
|
|
|
2019-07-16 20:34:04 +00:00
|
|
|
shellArgs=(
|
|
|
|
"--show-trace"
|
|
|
|
)
|
|
|
|
|
2019-11-29 10:20:08 +00:00
|
|
|
if [[ -n "${TARGET}" ]]; then
|
|
|
|
shellArgs+=("--argstr target ${TARGET}")
|
2019-07-16 20:34:04 +00:00
|
|
|
else
|
2019-11-29 10:20:08 +00:00
|
|
|
echo -e "${YELLOW}Env is missing TARGET, assuming default target.${NC} See nix/README.md for more details." 1>&2
|
2019-07-16 20:34:04 +00:00
|
|
|
fi
|
2019-06-04 16:50:29 +00:00
|
|
|
|
2019-11-29 10:20:08 +00:00
|
|
|
if [[ "$TARGET" =~ (linux|windows|darwin|macos) ]]; then
|
2019-07-16 20:34:04 +00:00
|
|
|
# This is a dirty workaround because 'yarn install' is an impure operation,
|
|
|
|
# so we need to call it from an impure shell.
|
2019-08-14 07:05:32 +00:00
|
|
|
# Hopefully we'll be able to fix this later on with something like yarn2nix
|
2019-07-16 20:34:04 +00:00
|
|
|
nix-shell ${shellArgs[@]} --run "scripts/prepare-for-desktop-platform.sh" || exit
|
|
|
|
fi
|
|
|
|
|
2020-01-08 14:41:07 +00:00
|
|
|
statusGoConfig=''
|
2019-11-15 15:04:36 +00:00
|
|
|
if [ -n "${STATUS_GO_SRC_OVERRIDE}" ]; then
|
2020-01-08 14:41:07 +00:00
|
|
|
statusGoConfig+="status_go.src_override=\"${STATUS_GO_SRC_OVERRIDE}\";"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$statusGoConfig" ]; then
|
|
|
|
shellArgs+=("--arg config {$statusGoConfig}")
|
2019-11-15 15:04:36 +00:00
|
|
|
fi
|
|
|
|
|
2019-07-16 20:34:04 +00:00
|
|
|
# if _NIX_ATTR is specified we shouldn't use shell.nix, the path will be different
|
|
|
|
entryPoint="shell.nix"
|
|
|
|
if [ -n "${_NIX_ATTR}" ]; then
|
|
|
|
shellArgs+=("--attr ${_NIX_ATTR}")
|
|
|
|
entryPoint="default.nix"
|
|
|
|
fi
|
|
|
|
|
2019-07-15 16:34:33 +00:00
|
|
|
# ENTER_NIX_SHELL is the fake command used when `make shell` is run.
|
|
|
|
# It is just a special string, not a variable, and a marker to not use `--run`.
|
2019-07-16 20:34:04 +00:00
|
|
|
if [[ $@ == "ENTER_NIX_SHELL" ]]; then
|
2019-11-29 10:20:08 +00:00
|
|
|
echo -e "${GREEN}Configuring ${_NIX_ATTR:-default} Nix shell for target '${TARGET:-default}'...${NC}" 1>&2
|
2019-07-16 20:34:04 +00:00
|
|
|
exec nix-shell ${shellArgs[@]} ${entryPoint}
|
|
|
|
else
|
|
|
|
# Not all builds are ready to be run in a pure environment
|
2019-07-15 16:34:33 +00:00
|
|
|
if [[ -n "${_NIX_PURE}" ]]; then
|
2019-07-16 20:34:04 +00:00
|
|
|
shellArgs+=("--pure")
|
|
|
|
pureDesc='pure '
|
|
|
|
fi
|
|
|
|
# This variable allows specifying which env vars to keep for Nix pure shell
|
|
|
|
# The separator is a semicolon
|
|
|
|
if [[ -n "${_NIX_KEEP}" ]]; then
|
2019-07-15 16:34:33 +00:00
|
|
|
shellArgs+=("--keep ${_NIX_KEEP//;/ --keep }")
|
2019-04-05 17:22:49 +00:00
|
|
|
fi
|
2019-11-29 10:20:08 +00:00
|
|
|
echo -e "${GREEN}Configuring ${pureDesc}${_NIX_ATTR:-default} Nix shell for target '${TARGET}'...${NC}" 1>&2
|
2019-07-16 20:34:04 +00:00
|
|
|
exec nix-shell ${shellArgs[@]} --run "$@" ${entryPoint}
|
2019-04-05 17:22:49 +00:00
|
|
|
fi
|