diff --git a/System/Posix/Env.hsc b/System/Posix/Env.hsc
index 6412bae22fac289d323ca8a43db64bf3fcde0d81..7d5f04cb6f544a440ceb0743e5edbfd0859d5d70 100644
--- a/System/Posix/Env.hsc
+++ b/System/Posix/Env.hsc
@@ -78,9 +78,8 @@ getEnvironmentPrim = do
       mapM peekFilePath arr
 
 getCEnviron :: IO (Ptr CString)
-
-#if darwin_HOST_OS
--- You should not access _environ directly on Darwin in a bundle/shared library.
+#if HAVE__NSGETENVIRON
+-- You should not access @char **environ@ directly on Darwin in a bundle/shared library.
 -- See #2458 and http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man7/environ.7.html
 getCEnviron = nsGetEnviron >>= peek
 
@@ -88,7 +87,6 @@ foreign import ccall unsafe "_NSGetEnviron"
    nsGetEnviron :: IO (Ptr (Ptr CString))
 #else
 getCEnviron = peek c_environ_p
-
 foreign import ccall unsafe "&environ"
    c_environ_p :: Ptr (Ptr CString)
 #endif
diff --git a/System/Posix/Env/ByteString.hsc b/System/Posix/Env/ByteString.hsc
index 57b03aa8bb17adf950ae5ae2353d6896192b3c2f..c6c374c18d43db08a2c85f403dbb40cc87762e35 100644
--- a/System/Posix/Env/ByteString.hsc
+++ b/System/Posix/Env/ByteString.hsc
@@ -69,8 +69,8 @@ getEnvironmentPrim = do
   mapM B.packCString arr
 
 getCEnviron :: IO (Ptr CString)
-#if darwin_HOST_OS
--- You should not access _environ directly on Darwin in a bundle/shared library.
+#if HAVE__NSGETENVIRON
+-- You should not access @char **environ@ directly on Darwin in a bundle/shared library.
 -- See #2458 and http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man7/environ.7.html
 getCEnviron = nsGetEnviron >>= peek
 
diff --git a/configure.ac b/configure.ac
index 5b6eb7c602e274229930c05a3d7bb6e68d66b0a8..fdc27e4e045b41a6a3fb12e7016668b6532a8ef5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,6 +40,10 @@ AC_CHECK_FUNCS([readdir_r])
 dnl not available on android so check for it
 AC_CHECK_FUNCS([telldir seekdir])
 
+dnl When available, _NSGetEnviron() (defined in <crt_externs.h>) is
+dnl the preferred way to access environ(7)
+AC_CHECK_FUNCS([_NSGetEnviron])
+
 dnl This is e.g. available as a GNU extension in glibc 2.11+
 AC_CHECK_DECLS([execvpe])
 AC_CHECK_FUNCS([execvpe])