github.com/status-im/status-go@v1.1.0/nix/scripts/source.sh (about)

     1  #!/usr/bin/env bash
     2  # This script makes sure we have Nix tools available
     3  set -e
     4  
     5  GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
     6  source "${GIT_ROOT}/nix/scripts/lib.sh"
     7  source "${GIT_ROOT}/scripts/colors.sh"
     8  
     9  source_nix_profile() {
    10      NIX_INSTALL_TYPE=$(nix_install_type)
    11      if [[ "${NIX_INSTALL_TYPE}" == "multi" ]]; then
    12          source "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
    13      elif [[ "${NIX_INSTALL_TYPE}" == "single" ]]; then
    14          export USER="${USER:-$(id -nu)}" # Missing in Docker.
    15          source "${HOME}/.nix-profile/etc/profile.d/nix.sh"
    16      elif [[ "${NIX_INSTALL_TYPE}" == "nixos" ]]; then
    17          echo "Sourcing profile not necessary on NixOS!" >&2
    18      fi
    19  }
    20  
    21  main() {
    22      # Just stop if Nix is already available
    23      if [[ -x $(command -v nix) ]]; then
    24          return
    25      fi
    26  
    27      # Setup Nix if not available
    28      if [[ ! -d /nix ]]; then
    29          "${GIT_ROOT}/nix/scripts/setup.sh"
    30      fi
    31  
    32      # Load Nix profile
    33      source_nix_profile
    34  
    35      # Verify Nix is available
    36      if [[ ! -x $(command -v nix) ]]; then
    37          echo -e "${RED}Nix not available, sourcing profile failed!${RST}" >&2
    38          exit 1
    39      fi
    40  }
    41  
    42  main