2018-12-05 03:17:22 +00:00
|
|
|
|
# Overlay that builds static packages.
|
|
|
|
|
|
|
|
|
|
# Not all packages will build but support is done on a
|
|
|
|
|
# best effort basic.
|
|
|
|
|
#
|
|
|
|
|
# Note on Darwin/macOS: Apple does not provide a static libc
|
|
|
|
|
# so any attempts at static binaries are going to be very
|
|
|
|
|
# unsupported.
|
|
|
|
|
#
|
|
|
|
|
# Basic things like pkgsStatic.hello should work out of the box. More
|
|
|
|
|
# complicated things will need to be fixed with overrides.
|
|
|
|
|
|
|
|
|
|
self: super: let
|
|
|
|
|
inherit (super.stdenvAdapters) makeStaticBinaries
|
2019-07-24 15:04:51 +01:00
|
|
|
|
makeStaticLibraries
|
|
|
|
|
propagateBuildInputs;
|
2020-04-28 15:51:39 +01:00
|
|
|
|
inherit (super.lib) foldl optional flip id composeExtensions optionalAttrs optionalString;
|
2018-12-05 03:17:22 +00:00
|
|
|
|
inherit (super) makeSetupHook;
|
|
|
|
|
|
|
|
|
|
# Best effort static binaries. Will still be linked to libSystem,
|
|
|
|
|
# but more portable than Nix store binaries.
|
2020-04-28 15:51:39 +01:00
|
|
|
|
makeStaticDarwin = stdenv_: let stdenv = stdenv_.override {
|
|
|
|
|
# extraBuildInputs are dropped in cross.nix, but darwin still needs them
|
|
|
|
|
extraBuildInputs = [ self.buildPackages.darwin.CF ];
|
|
|
|
|
}; in stdenv // {
|
2018-12-05 03:17:22 +00:00
|
|
|
|
mkDerivation = args: stdenv.mkDerivation (args // {
|
|
|
|
|
NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "")
|
2021-05-04 05:08:20 +01:00
|
|
|
|
+ optionalString (stdenv_.cc.isGNU or false) " -static-libgcc";
|
2018-12-05 03:17:22 +00:00
|
|
|
|
nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ (makeSetupHook {
|
|
|
|
|
substitutions = {
|
|
|
|
|
libsystem = "${stdenv.cc.libc}/lib/libSystem.B.dylib";
|
|
|
|
|
};
|
|
|
|
|
} ../stdenv/darwin/portable-libsystem.sh) ];
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-06 23:09:07 +00:00
|
|
|
|
staticAdapters =
|
|
|
|
|
optional super.stdenv.hostPlatform.isDarwin makeStaticDarwin
|
|
|
|
|
|
|
|
|
|
++ [ makeStaticLibraries propagateBuildInputs ]
|
2018-12-05 03:17:22 +00:00
|
|
|
|
|
|
|
|
|
# Apple does not provide a static version of libSystem or crt0.o
|
|
|
|
|
# So we can’t build static binaries without extensive hacks.
|
|
|
|
|
++ optional (!super.stdenv.hostPlatform.isDarwin) makeStaticBinaries
|
|
|
|
|
|
|
|
|
|
# Glibc doesn’t come with static runtimes by default.
|
|
|
|
|
# ++ optional (super.stdenv.hostPlatform.libc == "glibc") ((flip overrideInStdenv) [ self.stdenv.glibc.static ])
|
|
|
|
|
;
|
|
|
|
|
|
2019-11-20 15:46:18 +00:00
|
|
|
|
ocamlFixPackage = b:
|
|
|
|
|
b.overrideAttrs (o: {
|
|
|
|
|
configurePlatforms = [ ];
|
2021-06-11 19:42:26 +01:00
|
|
|
|
dontAddStaticConfigureFlags = true;
|
2019-11-20 15:46:18 +00:00
|
|
|
|
buildInputs = o.buildInputs ++ o.nativeBuildInputs or [ ];
|
|
|
|
|
propagatedNativeBuildInputs = o.propagatedBuildInputs or [ ];
|
|
|
|
|
});
|
2019-12-16 12:39:21 +00:00
|
|
|
|
|
2019-11-20 15:46:18 +00:00
|
|
|
|
ocamlStaticAdapter = _: super:
|
|
|
|
|
self.lib.mapAttrs
|
|
|
|
|
(_: p: if p ? overrideAttrs then ocamlFixPackage p else p)
|
|
|
|
|
super
|
|
|
|
|
// {
|
|
|
|
|
lablgtk = null; # Currently xlibs cause infinite recursion
|
|
|
|
|
ocaml = ((super.ocaml.override { useX11 = false; }).overrideAttrs (o: {
|
|
|
|
|
configurePlatforms = [ ];
|
|
|
|
|
dontUpdateAutotoolsGnuConfigScripts = true;
|
|
|
|
|
})).overrideDerivation (o: {
|
|
|
|
|
preConfigure = ''
|
|
|
|
|
configureFlagsArray+=("-cc" "$CC" "-as" "$AS" "-partialld" "$LD -r")
|
|
|
|
|
'';
|
2021-06-11 19:42:26 +01:00
|
|
|
|
dontAddStaticConfigureFlags = true;
|
|
|
|
|
configureFlags = [
|
2019-11-20 15:46:18 +00:00
|
|
|
|
"--no-shared-libs"
|
|
|
|
|
"-host ${o.stdenv.hostPlatform.config}"
|
|
|
|
|
"-target ${o.stdenv.targetPlatform.config}"
|
|
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-05 03:17:22 +00:00
|
|
|
|
in {
|
|
|
|
|
stdenv = foldl (flip id) super.stdenv staticAdapters;
|
2021-04-02 12:55:11 +01:00
|
|
|
|
|
2018-12-05 03:17:22 +00:00
|
|
|
|
boost = super.boost.override {
|
2019-09-29 11:01:21 +01:00
|
|
|
|
# Don’t use new stdenv for boost because it doesn’t like the
|
|
|
|
|
# --disable-shared flag
|
|
|
|
|
stdenv = super.stdenv;
|
2018-12-05 03:17:22 +00:00
|
|
|
|
};
|
2021-03-23 05:19:50 +00:00
|
|
|
|
|
2021-03-23 05:18:09 +00:00
|
|
|
|
curl = super.curl.override {
|
2021-03-29 13:40:05 +01:00
|
|
|
|
# brotli doesn't build static (Mar. 2021)
|
2021-03-23 05:18:09 +00:00
|
|
|
|
brotliSupport = false;
|
|
|
|
|
# disable gss becuase of: undefined reference to `k5_bcmp'
|
|
|
|
|
gssSupport = false;
|
|
|
|
|
};
|
2021-03-23 05:19:50 +00:00
|
|
|
|
|
|
|
|
|
ocaml-ng = self.lib.mapAttrs (_: set:
|
|
|
|
|
if set ? overrideScope' then set.overrideScope' ocamlStaticAdapter else set
|
|
|
|
|
) super.ocaml-ng;
|
|
|
|
|
|
2018-12-05 03:17:22 +00:00
|
|
|
|
perl = super.perl.override {
|
|
|
|
|
# Don’t use new stdenv zlib because
|
|
|
|
|
# it doesn’t like the --disable-shared flag
|
|
|
|
|
stdenv = super.stdenv;
|
|
|
|
|
};
|
2019-10-11 21:58:47 +01:00
|
|
|
|
|
2021-03-23 05:19:50 +00:00
|
|
|
|
zlib = super.zlib.override {
|
|
|
|
|
# Don’t use new stdenv zlib because
|
|
|
|
|
# it doesn’t like the --disable-shared flag
|
|
|
|
|
stdenv = super.stdenv;
|
|
|
|
|
};
|
2018-12-05 03:17:22 +00:00
|
|
|
|
}
|