From 286186b380ff98684c2d34974331c253512c596f Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Sun, 15 Feb 2026 10:13:56 +0200 Subject: [PATCH 1/2] zlib: always apply all substitutions And use `--replace-fail` for Darwin substitutions. Make it easier to find wrong substitutions relevant for platforms other then your own. --- pkgs/development/libraries/zlib/default.nix | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix index 28a45600a66b..5f20237d49b5 100644 --- a/pkgs/development/libraries/zlib/default.nix +++ b/pkgs/development/libraries/zlib/default.nix @@ -40,17 +40,14 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-uzKaCizQJ00FUZ1hxmfAYuBpkNcuEl7i36jeZPARnRY="; }; - postPatch = - lib.optionalString stdenv.hostPlatform.isDarwin '' - substituteInPlace configure \ - --replace '/usr/bin/libtool' '${stdenv.cc.targetPrefix}ar' \ - --replace 'AR="libtool"' 'AR="${stdenv.cc.targetPrefix}ar"' \ - --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"' - '' - + lib.optionalString stdenv.hostPlatform.isCygwin '' - substituteInPlace win32/zlib.def \ - --replace-fail 'gzopen_w' "" - ''; + postPatch = '' + substituteInPlace configure \ + --replace-fail '/usr/bin/libtool' '${stdenv.cc.targetPrefix}ar' \ + --replace-fail 'AR="libtool"' 'AR="${stdenv.cc.targetPrefix}ar"' \ + --replace-fail 'ARFLAGS="-o"' 'ARFLAGS="-r"' + substituteInPlace win32/zlib.def \ + --replace-fail 'gzopen_w' "" + ''; strictDeps = true; outputs = [ From b56433bafc08895de2f9761b271cf108d8fb4e14 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Sun, 15 Feb 2026 18:42:47 +0200 Subject: [PATCH 2/2] zlib: simplify arguments & explain --shared & --static --- pkgs/development/libraries/zlib/default.nix | 47 +++++++++------------ 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix index 5f20237d49b5..f5da487e366d 100644 --- a/pkgs/development/libraries/zlib/default.nix +++ b/pkgs/development/libraries/zlib/default.nix @@ -3,25 +3,31 @@ stdenv, fetchurl, shared ? !stdenv.hostPlatform.isStatic, - static ? true, - # If true, a separate .static output is created and the .a is moved there. - # If false, and if `{ static = true; }`, the .a stays in the main output. - splitStaticOutput ? shared && static && !stdenv.hostPlatform.isWindows, + # zlib's hand-written `./configure` script is a bit buggy, and it always + # builds the static library. The `--enable-shared` argument (alias to + # `--shared`) makes it build the shared library too. The `--static` argument + # is particularly confusing - if used after `--shared` it disables the build + # of the shared library. See also: + # + # - https://github.com/madler/zlib/pull/394 + # + # Since --static is aliased to --disable-shared, we use this flag in the + # `configureFlags` below, along with a few more relevant arguments to + # `stdenv.mkDerivation`. + # + # We avoid the closure size penalty of this buggy upstream behavior by using + # a dedicated output for the static library, which is fortuenatly also + # supported by the `--libdir` argument to `./configure`. + splitStaticOutput ? shared && !stdenv.hostPlatform.isWindows, testers, minizip, }: -# Without either the build will actually still succeed because the build -# system makes an arbitrary choice, but we shouldn't be so indecisive. -assert shared || static; - # Note: this package is used for bootstrapping fetchurl, and thus # cannot use fetchpatch! All mutable patches (generated by GitHub or # cgit) that are needed here should be included directly in Nixpkgs as # files. -assert splitStaticOutput -> static; - stdenv.mkDerivation (finalAttrs: { pname = "zlib"; version = "1.3.2"; @@ -68,22 +74,9 @@ stdenv.mkDerivation (finalAttrs: { "--includedir=${placeholder "dev"}/include" "--sharedlibdir=${placeholder "out"}/lib" "--libdir=${placeholder (if splitStaticOutput then "static" else "out")}/lib" - ] - # For zlib's ./configure (as of version 1.2.11), the order - # of --static/--shared flags matters! - # `--shared --static` builds only static libs, while - # `--static --shared` builds both. - # So we use the latter order to be able to build both. - # Also, giving just `--shared` builds both, - # giving just `--static` builds only static, - # and giving nothing builds both. - # So we have 3 possible ways to build both: - # `--static --shared`, `--shared` and giving nothing. - # Of these, we choose `--static --shared`, for clarity and simpler - # conditions. - ++ lib.optional static "--static" - ++ lib.optional shared "--shared"; - # We do the right thing manually, above, so don't need these. + # See comment near splitStaticOutput argument + (lib.enableFeature shared "shared") + ]; dontDisableStatic = true; dontAddStaticConfigureFlags = true; @@ -127,7 +120,7 @@ stdenv.mkDerivation (finalAttrs: { # We don't strip on static cross-compilation because of reports that native # stripping corrupted the target library; see commit 12e960f5 for the report. - dontStrip = stdenv.hostPlatform != stdenv.buildPlatform && static; + dontStrip = stdenv.hostPlatform != stdenv.buildPlatform; configurePlatforms = [ ]; installFlags = lib.optionals (stdenv.hostPlatform.isMinGW || stdenv.hostPlatform.isCygwin) [