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

     1  #!/usr/bin/env bash
     2  # This script installs a specific version of Nix.
     3  set -eo pipefail
     4  
     5  GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
     6  source "${GIT_ROOT}/scripts/colors.sh"
     7  source "${GIT_ROOT}/nix/scripts/lib.sh"
     8  source "${GIT_ROOT}/nix/scripts/version.sh"
     9  
    10  nix_install() {
    11      # Download installer and verify SHA256>
    12      curl -sSf "${NIX_INSTALL_URL}" -o "${NIX_INSTALL_PATH}"
    13      echo "${NIX_INSTALL_SHA256}  ${NIX_INSTALL_PATH}" | sha256sum -c
    14      chmod +x "${NIX_INSTALL_PATH}"
    15  
    16      # Identify installation type.
    17      if [[ -z "${NIX_INSTALL_OPTS}" ]]; then
    18          if [[ "$(uname -r)" =~ microsoft ]]; then
    19              # Systemd is not started by default on WSL.
    20              NIX_INSTALL_OPTS="--no-daemon"
    21          elif [[ "$(uname -s)" == "Darwin" ]]; then
    22              # Single-user not supported on Darwin.
    23              NIX_INSTALL_OPTS="--daemon"
    24          elif [[ "$(uname -s)" == "Linux" ]]; then
    25              # Open file limit issues on Linux.
    26              # https://github.com/NixOS/nix/issues/6007
    27              # Alson known issues with nix-daemon.socket on Arch.
    28              NIX_INSTALL_OPTS="--no-daemon"
    29          fi
    30      fi
    31  
    32      # Run the installer
    33      "${NIX_INSTALL_PATH}" "${NIX_INSTALL_OPTS}"
    34      if [[ $? -eq 0 ]]; then
    35          echo -e "${GRN}The Nix package manager was successfully installed.${RST}"
    36      else
    37          echo -e "${RED}Failed to install Nix package manager!${RST}" >&2
    38          echo "Please see: https://nixos.org/nix/manual/#chap-installation" >&2
    39          exit 1
    40      fi
    41  
    42      # Additional fixes
    43      nix_add_extra_cache
    44      nix_daemon_restart
    45  }
    46  
    47  # Adding directly to global config to avoid warnings like this:
    48  # "ignoring untrusted substituter 'https://nix-cache.status.im/', you are not a trusted user."
    49  nix_add_extra_cache() {
    50      # Single-user installations do not have this issue.
    51      [[ ! -f /etc/nix/nix.conf ]] && return
    52      echo -e 'Adding our cache to Nix daemon config...' >&2
    53      local NIX_SETTINGS=('substituters' 'trusted-substituters' 'trusted-public-keys')
    54      for NIX_SETTING in "${NIX_SETTINGS[@]}"; do
    55          nix_set_global_setting "${NIX_SETTING}" "$(nix_get_local_setting "${NIX_SETTING}")"
    56      done
    57  }
    58  
    59  if [[ ! -x "$(command -v sha256sum)" ]]; then
    60      echo -e "${RED}The 'sha256sum' utility is required for Nix installation.${RST}" >&2
    61      echo -e "${YLW}Install 'coreutils' package on your system.${RST}" >&2
    62      exit 1
    63  fi
    64  
    65  if [[ ! -x "$(command -v curl)" ]]; then
    66      echo -e "${RED}The 'curl' utility is required for Nix installation.${RST}" >&2
    67      exit 1
    68  fi
    69  
    70  if [[ "$(source /etc/os-release 2>/dev/null && echo "${NAME}")" == *NixOS* ]]; then
    71      echo -e "${GRN}Already running NixOS.${RST}"
    72      exit
    73  fi
    74  
    75  if [[ -x "$(command -v nix)" ]]; then
    76      echo -e "${GRN}Nix package manager already installed.${RST}"
    77      exit
    78  fi
    79  
    80  if [[ "${IN_NIX_SHELL}" == 'pure' ]]; then
    81      echo -e "${GRN}Already in a pure Nix shell.${RST}"
    82      exit
    83  fi
    84  
    85  # If none of the checks before succeeded we need to install Nix
    86  echo -e "${GRN}Setting up Nix package manager...${RST}"
    87  nix_install
    88  echo -e "${YLW}See STARTING_GUIDE.md if you're new here.${RST}"