diff --git a/doc/stdenv.xml b/doc/stdenv.xml
index 26190debc29..4ef89991d2f 100644
--- a/doc/stdenv.xml
+++ b/doc/stdenv.xml
@@ -2525,6 +2525,23 @@ addEnvHooks "$hostOffset" myBashFunction
+
+
+ libiconv, libintl
+
+
+
+ A few libraries automatically add to
+ NIX_LDFLAGS their library, making their
+ symbols automatically available to the linker. This includes
+ libiconv and libintl (gettext). This is done to provide
+ compatibility between GNU Linux, where libiconv and libintl
+ are bundled in, and other systems where that might not be the
+ case. Sometimes, this behavior is not desired. To disable
+ this behavior, set dontAddExtraLibs.
+
+
+
cmake
diff --git a/pkgs/development/compilers/ghc/8.2.2.nix b/pkgs/development/compilers/ghc/8.2.2.nix
index 3ecea2b54ed..3b9fecd55e1 100644
--- a/pkgs/development/compilers/ghc/8.2.2.nix
+++ b/pkgs/development/compilers/ghc/8.2.2.nix
@@ -206,6 +206,9 @@ stdenv.mkDerivation (rec {
"--disable-large-address-space"
];
+ # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself.
+ dontAddExtraLibs = true;
+
# Make sure we never relax`$PATH` and hooks support for compatability.
strictDeps = true;
diff --git a/pkgs/development/compilers/ghc/8.4.4.nix b/pkgs/development/compilers/ghc/8.4.4.nix
index 1ea18149d1e..4db5c07b460 100644
--- a/pkgs/development/compilers/ghc/8.4.4.nix
+++ b/pkgs/development/compilers/ghc/8.4.4.nix
@@ -186,6 +186,9 @@ stdenv.mkDerivation (rec {
# Make sure we never relax`$PATH` and hooks support for compatability.
strictDeps = true;
+ # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself.
+ dontAddExtraLibs = true;
+
nativeBuildInputs = [
perl autoconf automake m4 python3 sphinx
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
diff --git a/pkgs/development/compilers/ghc/8.6.1.nix b/pkgs/development/compilers/ghc/8.6.1.nix
index 434570fe988..5710c60338a 100644
--- a/pkgs/development/compilers/ghc/8.6.1.nix
+++ b/pkgs/development/compilers/ghc/8.6.1.nix
@@ -167,6 +167,9 @@ stdenv.mkDerivation (rec {
# Make sure we never relax`$PATH` and hooks support for compatability.
strictDeps = true;
+ # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself.
+ dontAddExtraLibs = true;
+
nativeBuildInputs = [
perl autoconf automake m4 python3 sphinx
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
diff --git a/pkgs/development/compilers/ghc/8.6.2.nix b/pkgs/development/compilers/ghc/8.6.2.nix
index 85853e15832..914d6ae08fa 100644
--- a/pkgs/development/compilers/ghc/8.6.2.nix
+++ b/pkgs/development/compilers/ghc/8.6.2.nix
@@ -167,6 +167,9 @@ stdenv.mkDerivation (rec {
# Make sure we never relax`$PATH` and hooks support for compatability.
strictDeps = true;
+ # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself.
+ dontAddExtraLibs = true;
+
nativeBuildInputs = [
perl autoconf automake m4 python3 sphinx
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
diff --git a/pkgs/development/compilers/ghc/head.nix b/pkgs/development/compilers/ghc/head.nix
index 29de668767b..42119682892 100644
--- a/pkgs/development/compilers/ghc/head.nix
+++ b/pkgs/development/compilers/ghc/head.nix
@@ -149,6 +149,9 @@ stdenv.mkDerivation (rec {
# Make sure we never relax`$PATH` and hooks support for compatability.
strictDeps = true;
+ # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself.
+ dontAddExtraLibs = true;
+
nativeBuildInputs = [
perl autoconf automake m4 python3
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
diff --git a/pkgs/development/libraries/gettext/gettext-setup-hook.sh b/pkgs/development/libraries/gettext/gettext-setup-hook.sh
index 0a6bc0dd253..ad3763c29b6 100644
--- a/pkgs/development/libraries/gettext/gettext-setup-hook.sh
+++ b/pkgs/development/libraries/gettext/gettext-setup-hook.sh
@@ -10,7 +10,7 @@ addEnvHooks "$hostOffset" gettextDataDirsHook
# libintl must be listed in load flags on non-Glibc
# it doesn't hurt to have it in Glibc either though
-if [ ! -z "@gettextNeedsLdflags@" ]; then
+if [ -n "@gettextNeedsLdflags@" -a -z "$dontAddExtraLibs" ]; then
# See pkgs/build-support/setup-hooks/role.bash
getHostRole
export NIX_${role_pre}LDFLAGS+=" -lintl"
diff --git a/pkgs/development/libraries/libiconv/setup-hook.sh b/pkgs/development/libraries/libiconv/setup-hook.sh
index d20e94513e2..f89361a6299 100644
--- a/pkgs/development/libraries/libiconv/setup-hook.sh
+++ b/pkgs/development/libraries/libiconv/setup-hook.sh
@@ -2,5 +2,7 @@
# it doesn't hurt to have it in Glibc either though
# See pkgs/build-support/setup-hooks/role.bash
-getHostRole
-export NIX_${role_pre}LDFLAGS+=" -liconv"
+if [ -z "$dontAddExtraLibs" ]; then
+ getHostRole
+ export NIX_${role_pre}LDFLAGS+=" -liconv"
+fi