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-04-05 17:22:49 +00:00
GREEN = '\033[0;32m'
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-04-09 15:14:32 +00:00
echo -e " ${ GREEN } Setting up environment... ${ NC } "
./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
if command -v "nix" >/dev/null 2>& 1; then
2019-05-07 15:57:30 +00:00
platform = ${ TARGET_OS : =all }
if [ " $platform " != 'all' ] ; then
# This is a dirty workaround to the fact that 'yarn install' is an impure operation, so we need to call it from an impure shell. Hopefull we'll be able to fix this later on with something like yarn2nix
2019-05-22 16:04:45 +00:00
nix-shell --show-trace --argstr target-os ${ TARGET_OS } --run " scripts/prepare-for-platform.sh $platform " || exit
2019-05-07 15:57:30 +00:00
fi
2019-04-05 17:22:49 +00:00
if [ [ $@ = = "ENTER_NIX_SHELL" ] ] ; then
2019-05-07 15:57:30 +00:00
echo -e " ${ GREEN } Configuring Nix shell for target ' ${ TARGET_OS } '... ${ NC } "
2019-04-12 08:36:30 +00:00
exec nix-shell --show-trace --argstr target-os ${ TARGET_OS }
2019-04-05 17:22:49 +00:00
else
2019-04-12 12:45:54 +00:00
is_pure = ''
2019-06-10 11:39:43 +00:00
if [ [ " ${ TARGET_OS } " != 'all' ] ] && [ [ " ${ TARGET_OS } " != 'ios' ] ] && [ [ " ${ TARGET_OS } " != 'windows' ] ] ; then
2019-04-29 16:33:40 +00:00
is_pure = '--pure'
pure_desc = 'pure '
fi
2019-06-10 11:39:43 +00:00
# This variable allows specifying which env vars to keep for Nix pure shell
# The separator is a semicolon
keep_opts = ''
if [ [ -n " ${ NIX_KEEP } " ] ] ; then
keep_opts = " --keep ${ NIX_KEEP //;/ --keep } "
fi
2019-05-07 15:57:30 +00:00
echo -e " ${ GREEN } Configuring ${ pure_desc } Nix shell for target ' ${ TARGET_OS } '... ${ NC } "
2019-06-10 11:39:43 +00:00
exec nix-shell ${ is_pure } ${ keep_opts } --show-trace --argstr target-os ${ TARGET_OS } --run " $@ "
2019-04-05 17:22:49 +00:00
fi
fi