Skip to content

Commit

Permalink
pkgsStatic: Inline more of static overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Aug 19, 2021
1 parent a17fc03 commit 9046258
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 51 deletions.
2 changes: 2 additions & 0 deletions pkgs/development/libraries/boost/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ stdenv.mkDerivation {

configureScript = "./bootstrap.sh";
configurePlatforms = [];
dontDisableStatic = true;
dontAddStaticConfigureFlags = true;
configureFlags = [
"--includedir=$(dev)/include"
"--libdir=$(out)/lib"
Expand Down
10 changes: 6 additions & 4 deletions pkgs/development/libraries/zlib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions pkgs/stdenv/adapters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions pkgs/tools/networking/curl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

This comment has been minimized.

Copy link
@lukegb

lukegb Sep 7, 2021

Contributor

This breaks curl's usage of cacerts; in particular, this has the inverse behaviour to that desired: it enables ca-fallback with wolfsslSupport and disables it without.

This comment has been minimized.

Copy link
@vcunat

vcunat Sep 7, 2021

Member

Fixed in PR #136946

"--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}"
Expand Down
45 changes: 6 additions & 39 deletions pkgs/top-level/static.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

0 comments on commit 9046258

Please sign in to comment.