From 8fa084dc0f0d3eac2714f15bc478f10b33ad433c Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Fri, 1 Jan 2021 00:22:23 -0600 Subject: [PATCH] stdenv/setup.sh: Add version check to setup script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only bash 4+ works in setup.sh. To make sure this is obvious, we can check BASH_VERSINFO to get the major version number of Bash. While Bash 3 is pretty rare, it still comes stock in macOS. We *could* provide a warning here for non-Bash shells, but it’s not always clear whether they will work or not. Zsh should have no trouble while busybox sh, fish, or any others. There’s no great way to detect what feature set the shell supports. Fixes #71625 --- pkgs/stdenv/generic/setup.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 4ff0a6caf760..e583054779b5 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -1,6 +1,12 @@ set -eu set -o pipefail +if [ -n "${BASH_VERSINFO-}" ] && [ "${BASH_VERSINFO-}" -lt 4 ]; then + echo "Detected Bash version that isn't supported by Nixpkgs (${BASH_VERSION})" + echo "Please install Bash 4 or greater to continue." + exit 1 +fi + if (( "${NIX_DEBUG:-0}" >= 6 )); then set -x fi