From 7b309d48751b0de2e91132b0fe890759cf8c0406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Tue, 9 Apr 2019 17:14:32 +0200 Subject: [PATCH] prevent nix setup running multiple times MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- nix/shell.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/nix/shell.sh b/nix/shell.sh index 348ffe8848..497ea385fb 100755 --- a/nix/shell.sh +++ b/nix/shell.sh @@ -1,19 +1,29 @@ #!/usr/bin/env bash +# +# This script is used by the Makefile to have an implicit nix-shell. +# + GREEN='\033[0;32m' NC='\033[0m' export TERM=xterm # fix for colors shift # we remove the first -c from arguments + if ! command -v "nix" >/dev/null 2>&1; then - echo -e "${GREEN}Setting up environment...${NC}" - ./scripts/setup -fi -if command -v "nix" >/dev/null 2>&1 || [ -f ~/.nix-profile/etc/profile.d/nix.sh ]; then - echo -e "${GREEN}Configuring Nix shell...${NC}"; - if [[ $@ == "ENTER_NIX_SHELL" ]]; then - . ~/.nix-profile/etc/profile.d/nix.sh && exec nix-shell + if [ -f ~/.nix-profile/etc/profile.d/nix.sh ]; then + . ~/.nix-profile/etc/profile.d/nix.sh else - . ~/.nix-profile/etc/profile.d/nix.sh && exec nix-shell --run "$@" + echo -e "${GREEN}Setting up environment...${NC}" + ./scripts/setup + fi +fi + +if command -v "nix" >/dev/null 2>&1; then + echo -e "${GREEN}Configuring Nix shell...${NC}"; + if [[ $@ == "ENTER_NIX_SHELL" ]]; then + exec nix-shell + else + exec nix-shell --run "$@" fi fi