allow for TARGET_OS to be not set
If we don't we will rebuild status-go for every platform when we running `make shell`. Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
158f9b4938
commit
0d78e71ece
2
Makefile
2
Makefile
|
@ -58,7 +58,7 @@ shell: ##@prepare Enter into a pre-configured shell
|
||||||
ifndef IN_NIX_SHELL
|
ifndef IN_NIX_SHELL
|
||||||
@ENTER_NIX_SHELL
|
@ENTER_NIX_SHELL
|
||||||
else
|
else
|
||||||
@echo "Nix shell is already active"
|
@echo "${YELLOW}Nix shell is already active$(RESET)"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
add-gcroots: SHELL := /bin/sh
|
add-gcroots: SHELL := /bin/sh
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
nixpkgs-bootstrap ? import ./nix/nixpkgs-bootstrap.nix { inherit config; },
|
nixpkgs-bootstrap ? import ./nix/nixpkgs-bootstrap.nix { inherit config; },
|
||||||
pkgs ? nixpkgs-bootstrap.pkgs,
|
pkgs ? nixpkgs-bootstrap.pkgs,
|
||||||
stdenv ? pkgs.stdenv,
|
stdenv ? pkgs.stdenv,
|
||||||
target-os ? "all" }:
|
target-os ? "none" }:
|
||||||
|
|
||||||
let deriv = pkgs.callPackage ./nix/derivation.nix { inherit pkgs target-os; inherit (nixpkgs-bootstrap) config; };
|
let deriv = pkgs.callPackage ./nix/derivation.nix { inherit pkgs target-os; inherit (nixpkgs-bootstrap) config; };
|
||||||
|
|
||||||
|
|
|
@ -14,3 +14,11 @@ In order to access an interactive Nix shell a user should run `make shell`.
|
||||||
|
|
||||||
The Nix shell is started in this repo via the [`nix/shell.sh`](/nix/shell.sh) script, which is a wrapper around the `nix-shell` command and is intended for use with our main [`Makefile`](/Makefile). This allows for an implicit use of `nix-shell` as the default shell in the `Makefile`.
|
The Nix shell is started in this repo via the [`nix/shell.sh`](/nix/shell.sh) script, which is a wrapper around the `nix-shell` command and is intended for use with our main [`Makefile`](/Makefile). This allows for an implicit use of `nix-shell` as the default shell in the `Makefile`.
|
||||||
|
|
||||||
|
By default the shell starts without any specific target platform, if you want to change that you should export the `TARGET_OS` env variable with the right value:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
TARGET_OS=android make shell
|
||||||
|
```
|
||||||
|
This way your shell and all other nix commands should run in a setup that is tailored towards Android development.
|
||||||
|
|
||||||
|
For valid values you can check the [`nix/platform.nix`](/nix/platform.nix) file.
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
{ target-os, stdenv }:
|
{ target-os, stdenv }:
|
||||||
|
|
||||||
assert stdenv.lib.assertOneOf "target-os" target-os [ "linux" "android" "windows" "macos" "darwin" "ios" "all" ];
|
# We allow for "none" value because `make shell` can be called with `TARGET_OS` not set.
|
||||||
|
# We don't want to assume `all`, because that will rebuild status-go for all platforms.
|
||||||
|
assert stdenv.lib.assertOneOf "target-os" target-os [ "linux" "android" "windows" "macos" "darwin" "ios" "all" "none" ];
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (stdenv) isDarwin isLinux;
|
inherit (stdenv) isDarwin isLinux;
|
||||||
|
|
82
nix/shell.sh
82
nix/shell.sh
|
@ -11,6 +11,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
export TERM=xterm # fix for colors
|
export TERM=xterm # fix for colors
|
||||||
|
@ -27,38 +28,51 @@ if ! command -v "nix" >/dev/null 2>&1; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if command -v "nix" >/dev/null 2>&1; then
|
if !command -v "nix" >/dev/null 2>&1; then
|
||||||
platform=${TARGET_OS:=all}
|
echo "Nix not available, sourcing profile failed!"
|
||||||
if [ "$platform" != 'all' ] && [ "$platform" != 'android' ] && [ "$platform" != 'ios' ]; then
|
exit 1
|
||||||
# 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
|
fi
|
||||||
nix-shell --show-trace --argstr target-os ${TARGET_OS} --run "scripts/prepare-for-desktop-platform.sh" || exit
|
|
||||||
fi
|
shellArgs=(
|
||||||
|
"--show-trace"
|
||||||
entry_point='shell.nix'
|
)
|
||||||
attrset_option=''
|
|
||||||
if [ -n "${_NIX_ATTR}" ]; then
|
if [[ -n "${TARGET_OS}" ]]; then
|
||||||
entry_point='default.nix'
|
shellArgs+=("--argstr target-os ${TARGET_OS}")
|
||||||
attrset_option="-A ${_NIX_ATTR}"
|
else
|
||||||
fi
|
echo -e "${YELLOW}Env is missing TARGET_OS, assuming no target platform.${NC}"
|
||||||
|
echo -e "See nix/README.md for more details."
|
||||||
attrStr="${_NIX_ATTR}"
|
fi
|
||||||
[ -n "$attrStr" ] && attrStr="$attrStr "
|
|
||||||
if [[ $@ == "ENTER_NIX_SHELL" ]]; then
|
if [[ "$TARGET_OS" =~ (linux|windows) ]]; then
|
||||||
echo -e "${GREEN}Configuring ${attrStr}Nix shell for target '${TARGET_OS}'...${NC}"
|
# This is a dirty workaround because 'yarn install' is an impure operation,
|
||||||
exec nix-shell --show-trace --argstr target-os ${TARGET_OS} ${attrset_option} ${entry_point}
|
# so we need to call it from an impure shell.
|
||||||
else
|
# Hopefull we'll be able to fix this later on with something like yarn2nix
|
||||||
is_pure=''
|
nix-shell ${shellArgs[@]} --run "scripts/prepare-for-desktop-platform.sh" || exit
|
||||||
if [[ "${TARGET_OS}" != 'all' ]] && [[ "${TARGET_OS}" != 'ios' ]] && [[ "${TARGET_OS}" != 'windows' ]]; then
|
fi
|
||||||
is_pure='--pure'
|
|
||||||
pure_desc='pure '
|
# if _NIX_ATTR is specified we shouldn't use shell.nix, the path will be different
|
||||||
fi
|
entryPoint="shell.nix"
|
||||||
# This variable allows specifying which env vars to keep for Nix pure shell
|
if [ -n "${_NIX_ATTR}" ]; then
|
||||||
# The separator is a semicolon
|
shellArgs+=("--attr ${_NIX_ATTR}")
|
||||||
keep_opts=''
|
entryPoint="default.nix"
|
||||||
if [[ -n "${_NIX_KEEP}" ]]; then
|
fi
|
||||||
keep_opts="--keep ${_NIX_KEEP//;/ --keep }"
|
|
||||||
fi
|
# this happens if `make shell` is run already in a Nix shell
|
||||||
echo -e "${GREEN}Configuring ${pure_desc}${attrStr}Nix shell for target '${TARGET_OS}'...${NC}"
|
if [[ $@ == "ENTER_NIX_SHELL" ]]; then
|
||||||
exec nix-shell ${is_pure} ${keep_opts} --show-trace --argstr target-os ${TARGET_OS} ${attrset_option} --run "$@" ${entry_point}
|
echo -e "${GREEN}Configuring ${_NIX_ATTR:-default} Nix shell for target '${TARGET_OS}'...${NC}"
|
||||||
fi
|
exec nix-shell ${shellArgs[@]} ${entryPoint}
|
||||||
|
else
|
||||||
|
# Not all builds are ready to be run in a pure environment
|
||||||
|
if [[ "${TARGET_OS}" =~ (android|macos|linux) ]]; then
|
||||||
|
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
|
||||||
|
nixShelArgs+=("--keep ${_NIX_KEEP//;/ --keep }")
|
||||||
|
fi
|
||||||
|
echo -e "${GREEN}Configuring ${pureDesc}${_NIX_ATTR:-default} Nix shell for target '${TARGET_OS}'...${NC}"
|
||||||
|
exec nix-shell ${shellArgs[@]} --run "$@" ${entryPoint}
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{ nixpkgs-bootstrap ? import ./nix/nixpkgs-bootstrap.nix { },
|
{ nixpkgs-bootstrap ? import ./nix/nixpkgs-bootstrap.nix { },
|
||||||
pkgs ? nixpkgs-bootstrap.pkgs,
|
pkgs ? nixpkgs-bootstrap.pkgs,
|
||||||
target-os ? "all" }:
|
target-os ? "none" }:
|
||||||
|
|
||||||
let
|
let
|
||||||
project = import ./default.nix { inherit target-os pkgs nixpkgs-bootstrap; inherit (nixpkgs-bootstrap) config; };
|
project = import ./default.nix { inherit target-os pkgs nixpkgs-bootstrap; inherit (nixpkgs-bootstrap) config; };
|
||||||
|
|
Loading…
Reference in New Issue