From 3c368dcff7ee95bc70a95b1e12bd02f0bdc29c95 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Thu, 9 Apr 2026 20:27:02 -0400 Subject: [PATCH 1/5] libiconvReal: add UTF-8-MAC encoding patch --- pkgs/development/libraries/libiconv/default.nix | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkgs/development/libraries/libiconv/default.nix b/pkgs/development/libraries/libiconv/default.nix index 294e7a81d5e46..966b3840f0c9a 100644 --- a/pkgs/development/libraries/libiconv/default.nix +++ b/pkgs/development/libraries/libiconv/default.nix @@ -31,8 +31,18 @@ stdenv.mkDerivation rec { setupHooks = [ ../../../build-support/setup-hooks/role.bash ./setup-hook.sh + patches = [ + # Add support for the UTF-8-MAC encoding. This is needed for correct behavior of applications that interact with + # the filesystem on Darwin because it uses a variant of NFD to store filenames. + (fetchurl { + url = "https://raw.githubusercontent.com/macports/macports-ports/ce1083dbec406fcea0f2678308ae85639798aa6e/textproc/libiconv/files/patch-utf8mac.diff"; + hash = "sha256-aqoTDIunKnWLHPizdWbU6eCDZXaj2s+GJwtg6Spzfio="; + }) ]; + # The patch for UTF-8-MAC requires -p0. It can’t use `fetchpatch2` because that results in an infinite recursion. + patchFlags = [ "-p0" ]; + postPatch = lib.optionalString ( @@ -82,6 +92,12 @@ stdenv.mkDerivation rec { # remove after gnulib is updated ++ lib.optional stdenv.hostPlatform.isCygwin "gl_cv_clean_version_stddef=yes"; + preBuild = '' + # The UTF-8-MAC patch requires regenerating `flags.h` + make -C lib genflags + lib/genflags > lib/flags.h + ''; + passthru = { inherit setupHooks; }; meta = { From 116c4b57742865ab13a4d07d40196b21815523f3 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Thu, 9 Apr 2026 20:27:02 -0400 Subject: [PATCH 2/5] libiconvReal: disable the setup hook on Darwin This mirrors the Darwin libiconv package, which does not provide a setup hook. It is expected that libiconv will be linked explicitly on Darwin. --- pkgs/development/libraries/libiconv/default.nix | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkgs/development/libraries/libiconv/default.nix b/pkgs/development/libraries/libiconv/default.nix index 966b3840f0c9a..d4b4711a4ac60 100644 --- a/pkgs/development/libraries/libiconv/default.nix +++ b/pkgs/development/libraries/libiconv/default.nix @@ -28,9 +28,13 @@ stdenv.mkDerivation rec { # https://github.com/NixOS/nixpkgs/pull/192630#discussion_r978985593 hardeningDisable = lib.optional (stdenv.hostPlatform.libc == "bionic") "fortify"; - setupHooks = [ - ../../../build-support/setup-hooks/role.bash - ./setup-hook.sh + setupHooks = + # Match the default behavior on Darwin, which does not automatically link libiconv. + lib.optionals (!stdenv.hostPlatform.isDarwin) [ + ../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; + patches = [ # Add support for the UTF-8-MAC encoding. This is needed for correct behavior of applications that interact with # the filesystem on Darwin because it uses a variant of NFD to store filenames. From 3d7ce9597bce61336520bba600bf1e8680cbe614 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Thu, 9 Apr 2026 20:27:02 -0400 Subject: [PATCH 3/5] libiconvReal: enable the Darwin ABI by default on Darwin --- pkgs/development/libraries/libiconv/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/libraries/libiconv/default.nix b/pkgs/development/libraries/libiconv/default.nix index d4b4711a4ac60..fcf8cb7800f2a 100644 --- a/pkgs/development/libraries/libiconv/default.nix +++ b/pkgs/development/libraries/libiconv/default.nix @@ -5,7 +5,7 @@ updateAutotoolsGnuConfigScriptsHook, enableStatic ? stdenv.hostPlatform.isStatic, enableShared ? !stdenv.hostPlatform.isStatic, - enableDarwinABICompat ? false, + enableDarwinABICompat ? stdenv.hostPlatform.isDarwin, }: # assert !stdenv.hostPlatform.isLinux || stdenv.hostPlatform != stdenv.buildPlatform; # TODO: improve on cross From d899c6d5b585ff29b4afcd56b88b2f301046649b Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Thu, 9 Apr 2026 20:27:02 -0400 Subject: [PATCH 4/5] libiconvReal: build with bootstrap SDK to avoid infinite recursion on Darwin --- pkgs/development/libraries/libiconv/default.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgs/development/libraries/libiconv/default.nix b/pkgs/development/libraries/libiconv/default.nix index fcf8cb7800f2a..a7251b7f58a9d 100644 --- a/pkgs/development/libraries/libiconv/default.nix +++ b/pkgs/development/libraries/libiconv/default.nix @@ -2,6 +2,7 @@ fetchurl, stdenv, lib, + darwin, updateAutotoolsGnuConfigScriptsHook, enableStatic ? stdenv.hostPlatform.isStatic, enableShared ? !stdenv.hostPlatform.isStatic, @@ -10,7 +11,12 @@ # assert !stdenv.hostPlatform.isLinux || stdenv.hostPlatform != stdenv.buildPlatform; # TODO: improve on cross -stdenv.mkDerivation rec { +let + # libiconv is propagated by the SDK in the stdenv. Avoid an infinite recursion by using a stdenv + # with an SDK that does not try to propagate it. + stdenv' = if stdenv.hostPlatform.isDarwin then darwin.bootstrapStdenv else stdenv; +in +stdenv'.mkDerivation rec { pname = "libiconv"; version = "1.19"; @@ -124,6 +130,6 @@ stdenv.mkDerivation rec { mainProgram = "iconv"; # This library is not needed on GNU platforms. - hydraPlatforms = with lib.platforms; cygwin ++ darwin ++ freebsd; + hydraPlatforms = lib.platforms.cygwin ++ lib.platforms.darwin ++ lib.platforms.freebsd; }; } From d44e270d0177b8c337e0158b4b2bc355879d1d19 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Thu, 9 Apr 2026 20:27:02 -0400 Subject: [PATCH 5/5] libiconvReal: make default on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Darwin libiconv tries to be compatible with GNU libiconv, but it’s not. Recent versions of Autoconf and gnulib include checks for issues in Darwin’s libiconv implementation, which has effectively turned `autoreconfHook` into `autoBreakDarwinHook` due to failing to link libiconv. Instead of continuing to work around it, make GNU libiconv the default. With the UTF-8-MAC patch, it should be a drop-in replacement. --- pkgs/stdenv/darwin/default.nix | 11 ++++------- pkgs/top-level/all-packages.nix | 2 -- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 385a315f9c871..683a6a0218792 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -277,6 +277,7 @@ let sdkPackages = prevStage: { inherit (prevStage) bashNonInteractive + libiconvReal libpng libxml2 libxo @@ -291,7 +292,6 @@ let Csu adv_cmds copyfile - libiconv libresolv libsbuf libutil @@ -557,9 +557,6 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check # Use this stage’s CF to build CMake. It’s required but can’t be included in the stdenv. cmake = self.cmakeMinimal; - # Use libiconvReal with gettext to break an infinite recursion. - gettext = super.gettext.override { libiconv = super.libiconvReal; }; - # Disable grep’s tests for now due to impure locale updates in # macOS 15.4 breaking them in the bootstrap. gnugrep = super.gnugrep.overrideAttrs { doCheck = false; }; @@ -1050,6 +1047,7 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check ld64.lib ld64.out libffi.out + libiconv.out libxml2.out ncurses.dev ncurses.man @@ -1076,7 +1074,6 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check binutils binutils.bintools libcxx - libiconv.out libresolv.out libsbuf.out libSystem @@ -1192,8 +1189,8 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check assert isFromNixpkgs prevStage.binutils-unwrapped.src; assert isBuiltByNixpkgsCompiler prevStage.curl; - # libiconv should be an alias for darwin.libiconv - assert prevStage.libiconv == prevStage.darwin.libiconv; + # libiconv should be an alias for libiconvReal + assert prevStage.libiconv == prevStage.libiconvReal; { inherit (prevStage) config overlays stdenv; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f665b697f38b9..7e87acae874c4 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -6674,8 +6674,6 @@ with pkgs; ] then libcIconv pkgs.libc - else if stdenv.hostPlatform.isDarwin then - darwin.libiconv else libiconvReal;