[New] `nvm_supports_xz`: Add Mac/FreeBSD xz platform support checks

macOS only supports extracting xz tarballs with `tar` in 10.9 and up.

GNU tar needs an `xz` executable on the `PATH` to extract xz tarballs.

(These are the most common variants of tar, so until further testing
is done, conservatively assume all variants of tar (other than the one
shipped with macOS) need an xz executable on the PATH in order to
decompress xz tarballs.)

Fixes #2155.
diff --git a/nvm.sh b/nvm.sh
index 32aacff..c40c607 100644
--- a/nvm.sh
+++ b/nvm.sh
@@ -3687,10 +3687,32 @@
 }
 
 nvm_supports_xz() {
-  if [ -z "${1-}" ] || ! command which xz >/dev/null 2>&1; then
+  if [ -z "${1-}" ]; then
     return 1
   fi
 
+  local NVM_OS
+  NVM_OS="$(nvm_get_os)"
+  if [ "_${NVM_OS}" = '_darwin' ]; then
+    local MACOS_VERSION
+    MACOS_VERSION="$(sw_vers -productVersion)"
+    if nvm_version_greater "10.9.0" "${MACOS_VERSION}"; then
+      # macOS 10.8 and earlier doesn't support extracting xz-compressed tarballs with tar
+      return 1
+    fi
+  elif [ "_${NVM_OS}" = '_freebsd' ]; then
+    if ! [ -e '/usr/lib/liblzma.so' ]; then
+      # FreeBSD without /usr/lib/liblzma.so doesn't support extracting xz-compressed tarballs with tar
+      return 1
+    fi
+  else
+    if ! command which xz >/dev/null 2>&1; then
+      # Most OSes without xz on the PATH don't support extracting xz-compressed tarballs with tar
+      # (Should correctly handle Linux, SmartOS, maybe more)
+      return 1
+    fi
+  fi
+
   # all node versions v4.0.0 and later have xz
   if nvm_is_merged_node_version "${1}"; then
     return 0
@@ -3706,8 +3728,6 @@
     return 0
   fi
 
-  local NVM_OS
-  NVM_OS="$(nvm_get_os)"
   case "${NVM_OS}" in
     darwin)
       # darwin only has xz for io.js v2.3.2 and later