From 904625852d535bbe53cadb006c9e1137ab481818 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 19 Aug 2021 17:56:53 +0000 Subject: [PATCH] pkgsStatic: Inline more of static overlay --- pkgs/development/libraries/boost/generic.nix | 2 + pkgs/development/libraries/zlib/default.nix | 10 +++-- pkgs/stdenv/adapters.nix | 18 ++++++++ pkgs/tools/networking/curl/default.nix | 17 ++++---- pkgs/top-level/static.nix | 45 +++----------------- 5 files changed, 41 insertions(+), 51 deletions(-) diff --git a/pkgs/development/libraries/boost/generic.nix b/pkgs/development/libraries/boost/generic.nix index 7ea7902e0873f..2d8d13482eac4 100644 --- a/pkgs/development/libraries/boost/generic.nix +++ b/pkgs/development/libraries/boost/generic.nix @@ -189,6 +189,8 @@ stdenv.mkDerivation { configureScript = "./bootstrap.sh"; configurePlatforms = []; + dontDisableStatic = true; + dontAddStaticConfigureFlags = true; configureFlags = [ "--includedir=$(dev)/include" "--libdir=$(out)/lib" diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix index a9fadf46c4b2e..8d7cb3a48c885 100644 --- a/pkgs/development/libraries/zlib/default.nix +++ b/pkgs/development/libraries/zlib/default.nix @@ -57,11 +57,13 @@ stdenv.mkDerivation (rec { # and giving nothing builds both. # So we have 3 possible ways to build both: # `--static --shared`, `--shared` and giving nothing. - # Of these, we choose `--shared`, only because that's - # what we did in the past and we can avoid mass rebuilds this way. - # As a result, we pass `--static` only when we want just static. - configureFlags = lib.optional (static && !shared) "--static" + # Of these, we choose `--static --shared`, for clarity and simpler + # conditions. + configureFlags = lib.optional static "--static" ++ lib.optional shared "--shared"; + # We do the right thing manually, above, so don't need these. + dontDisableStatic = true; + dontAddStaticConfigureFlags = true; # Note we don't need to set `dontDisableStatic`, because static-disabling # works by grepping for `enable-static` in the `./configure` script diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 719f679982664..9e1c73a57db14 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -90,6 +90,24 @@ rec { }); }); + # Best effort static binaries. Will still be linked to libSystem, + # but more portable than Nix store binaries. + makeStaticDarwin = stdenv: stdenv.override (old: { + # extraBuildInputs are dropped in cross.nix, but darwin still needs them + extraBuildInputs = [ pkgs.buildPackages.darwin.CF ]; + mkDerivationFromStdenv = extendMkDerivationArgs old (args: { + NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") + + lib.optionalString (stdenv.cc.isGNU or false) " -static-libgcc"; + nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ + (pkgs.buildPackages.makeSetupHook { + substitutions = { + libsystem = "${stdenv.cc.libc}/lib/libSystem.B.dylib"; + }; + } ./darwin/portable-libsystem.sh) + ]; + }); + }); + /* Modify a stdenv so that all buildInputs are implicitly propagated to consuming derivations diff --git a/pkgs/tools/networking/curl/default.nix b/pkgs/tools/networking/curl/default.nix index 4fd754a3a6c73..5dba94abe35bc 100644 --- a/pkgs/tools/networking/curl/default.nix +++ b/pkgs/tools/networking/curl/default.nix @@ -9,6 +9,7 @@ , scpSupport ? zlibSupport && !stdenv.isSunOS && !stdenv.isCygwin, libssh2 ? null , gssSupport ? with stdenv.hostPlatform; ( !isWindows && + # disable gss becuase of: undefined reference to `k5_bcmp' # a very sad story re static: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=439039 !isStatic && # the "mig" tool does not configure its compiler correctly. This could be @@ -95,15 +96,15 @@ stdenv.mkDerivation rec { "--without-ca-bundle" "--without-ca-path" # The build fails when using wolfssl with --with-ca-fallback - ( if wolfsslSupport then "--without-ca-fallback" else "--with-ca-fallback") + (lib.withFeature wolfsslSupport "ca-fallback") "--disable-manual" - ( if sslSupport then "--with-ssl=${openssl.dev}" else "--without-ssl" ) - ( if gnutlsSupport then "--with-gnutls=${gnutls.dev}" else "--without-gnutls" ) - ( if scpSupport then "--with-libssh2=${libssh2.dev}" else "--without-libssh2" ) - ( if ldapSupport then "--enable-ldap" else "--disable-ldap" ) - ( if ldapSupport then "--enable-ldaps" else "--disable-ldaps" ) - ( if idnSupport then "--with-libidn=${libidn.dev}" else "--without-libidn" ) - ( if brotliSupport then "--with-brotli" else "--without-brotli" ) + (lib.withFeatureAs sslSupport "ssl" openssl.dev) + (lib.withFeatureAs gnutlsSupport "gnutls" gnutls.dev) + (lib.withFeatureAs scpSupport "libssh2" libssh2.dev) + (lib.enableFeature ldapSupport "ldap") + (lib.enableFeature ldapSupport "ldaps") + (lib.withFeatureAs idnSupport "libidn" libidn.dev) + (lib.withFeature brotliSupport "brotli") ] ++ lib.optional wolfsslSupport "--with-wolfssl=${wolfssl.dev}" ++ lib.optional c-aresSupport "--enable-ares=${c-ares}" diff --git a/pkgs/top-level/static.nix b/pkgs/top-level/static.nix index 38f6a8fad424e..3cc3f6b79f4b1 100644 --- a/pkgs/top-level/static.nix +++ b/pkgs/top-level/static.nix @@ -13,26 +13,9 @@ self: super: let inherit (super.stdenvAdapters) makeStaticBinaries makeStaticLibraries - propagateBuildInputs; - inherit (super.lib) foldl optional flip id composeExtensions optionalAttrs optionalString; - inherit (super) makeSetupHook; - - # Best effort static binaries. Will still be linked to libSystem, - # but more portable than Nix store binaries. - makeStaticDarwin = stdenv_: let stdenv = stdenv_.override { - # extraBuildInputs are dropped in cross.nix, but darwin still needs them - extraBuildInputs = [ self.buildPackages.darwin.CF ]; - }; in stdenv // { - mkDerivation = args: stdenv.mkDerivation (args // { - NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") - + optionalString (stdenv_.cc.isGNU or false) " -static-libgcc"; - nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ (makeSetupHook { - substitutions = { - libsystem = "${stdenv.cc.libc}/lib/libSystem.B.dylib"; - }; - } ../stdenv/darwin/portable-libsystem.sh) ]; - }); - }; + propagateBuildInputs + makeStaticDarwin; + inherit (super.lib) foldl optional flip id composeExtensions; staticAdapters = optional super.stdenv.hostPlatform.isDarwin makeStaticDarwin @@ -48,24 +31,8 @@ self: super: let ; in { - stdenv = foldl (flip id) super.stdenv staticAdapters; - - boost = super.boost.override { - # Don’t use new stdenv for boost because it doesn’t like the - # --disable-shared flag - stdenv = super.stdenv; - }; + # Do not add new packages here! Instead use `stdenv.hostPlatform.isStatic` to + # write conditional code in the original package. - curl = super.curl.override { - # brotli doesn't build static (Mar. 2021) - brotliSupport = false; - # disable gss becuase of: undefined reference to `k5_bcmp' - gssSupport = false; - }; - - zlib = super.zlib.override { - # Don’t use new stdenv zlib because - # it doesn’t like the --disable-shared flag - stdenv = super.stdenv; - }; + stdenv = foldl (flip id) super.stdenv staticAdapters; }