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
|
|
|
|
2020-02-19 13:15:28 +00:00
|
|
|
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
|
|
|
|
source "${GIT_ROOT}/scripts/colors.sh"
|
|
|
|
source "${GIT_ROOT}/nix/scripts/source.sh"
|
2019-04-05 17:22:49 +00:00
|
|
|
|
|
|
|
export TERM=xterm # fix for colors
|
|
|
|
shift # we remove the first -c from arguments
|
2019-04-09 15:14:32 +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
|
2020-02-19 13:15:28 +00:00
|
|
|
echo -e "${YLW}Env is missing TARGET, assuming default target.${RST} 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-13 14:28:40 +00:00
|
|
|
config=''
|
2019-11-15 15:04:36 +00:00
|
|
|
if [ -n "${STATUS_GO_SRC_OVERRIDE}" ]; then
|
2020-01-13 14:28:40 +00:00
|
|
|
config+="status-im.status-go.src-override=\"${STATUS_GO_SRC_OVERRIDE}\";"
|
2020-01-08 14:41:07 +00:00
|
|
|
fi
|
2020-01-21 07:19:49 +00:00
|
|
|
if [ -n "${NIMBUS_SRC_OVERRIDE}" ]; then
|
|
|
|
config+="status-im.nimbus.src-override=\"${NIMBUS_SRC_OVERRIDE}\";"
|
|
|
|
fi
|
2020-01-13 14:28:40 +00:00
|
|
|
config+="status-im.build-type=\"${BUILD_TYPE}\";"
|
2020-01-08 14:41:07 +00:00
|
|
|
|
2020-01-13 14:28:40 +00:00
|
|
|
if [ -n "$config" ]; then
|
|
|
|
shellArgs+=("--arg config {$config}")
|
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
|
2020-02-19 13:15:28 +00:00
|
|
|
echo -e "${GRN}Configuring ${_NIX_ATTR:-default} Nix shell for target '${TARGET:-default}'...${RST}" 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
|
2020-02-19 13:15:28 +00:00
|
|
|
echo -e "${GRN}Configuring ${pureDesc}${_NIX_ATTR:-default} Nix shell for target '${TARGET}'...${RST}" 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
|