Skip to content

Commit

Permalink
stdenv: introduce dontAddStaticConfigureFlags
Browse files Browse the repository at this point in the history
With removeUnknownConfigureFlags, it's impossible to express a package
that needs --enable-static, but will not accept --disable-shared,
without overriding the result of removeUnknownConfigureFlags _again_
in pkgs/top-level/static.nix.

It would be much better (and more in line with the rest of Nixpkgs) if
we encoded changes needed for static builds in package definitions
themselves, rather than in an ever-expanding list in static.nix.  This
is especially true when doing it in static.nix is going to require
multiple overrides to express what could be expressed with stdenv
options.

So as a step in that direction, and to fix the problem described
above, here I replace removeUnknownConfigureFlags with a new stdenv
option, dontAddStaticConfigureFlags.  With this mechanism, a package
that needs one but not both of the flags just needs to set
dontAddStaticConfigureFlags and then set up configureFlags manually
based on stdenv.hostPlatform.isStatic.
  • Loading branch information
alyssais authored and Jonathan Ringer committed Jun 11, 2021
1 parent 8f3ead7 commit b0b5ef7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
8 changes: 7 additions & 1 deletion doc/stdenv/stdenv.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,12 @@ The prefix under which the package must be installed, passed via the `--prefix`

The key to use when specifying the prefix. By default, this is set to `--prefix=` as that is used by the majority of packages.

##### `dontAddStaticConfigureFlags`

By default, when building statically, stdenv will try to add build system appropriate configure flags to try to enable static builds.

If this is undesirable, set this variable to true.

##### `dontAddDisableDepTrack` {#var-stdenv-dontAddDisableDepTrack}

By default, the flag `--disable-dependency-tracking` is added to the configure flags to speed up Automake-based builds. If this is undesirable, set this variable to true.
Expand All @@ -475,7 +481,7 @@ By default, the configure phase applies some special hackery to all files called

By default, when the configure script has `--enable-static`, the option `--disable-static` is added to the configure flags.

If this is undesirable, set this variable to true.
If this is undesirable, set this variable to true. It is automatically set to true when building statically, for example through `pkgsStatic`.

##### `configurePlatforms` {#var-stdenv-configurePlatforms}

Expand Down
2 changes: 2 additions & 0 deletions pkgs/development/libraries/openssl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ let
throw "Not sure what configuration to use for ${stdenv.hostPlatform.config}"
);

# OpenSSL doesn't like the `--enable-static` / `--disable-shared` flags.
dontAddStaticConfigureFlags = true;
configureFlags = [
"shared" # "shared" builds both shared and static libraries
"--libdir=lib"
Expand Down
2 changes: 2 additions & 0 deletions pkgs/stdenv/adapters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ rec {
then throw "Cannot build fully static binaries on Darwin/macOS"
else stdenv'.mkDerivation (args // {
NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") + " -static";
} // pkgs.lib.optionalAttrs (!(args.dontAddStaticConfigureFlags or false)) {
configureFlags = (args.configureFlags or []) ++ [
"--disable-shared" # brrr...
];
Expand All @@ -56,6 +57,7 @@ rec {
makeStaticLibraries = stdenv: stdenv //
{ mkDerivation = args: stdenv.mkDerivation (args // {
dontDisableStatic = true;
} // pkgs.lib.optionalAttrs (!(args.dontAddStaticConfigureFlags or false)) {
configureFlags = (args.configureFlags or []) ++ [
"--enable-static"
"--disable-shared"
Expand Down
14 changes: 3 additions & 11 deletions pkgs/top-level/static.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@ self: super: let
# ++ optional (super.stdenv.hostPlatform.libc == "glibc") ((flip overrideInStdenv) [ self.stdenv.glibc.static ])
;

removeUnknownConfigureFlags = f: with self.lib;
remove "--disable-shared"
(remove "--enable-static" f);

ocamlFixPackage = b:
b.overrideAttrs (o: {
configurePlatforms = [ ];
configureFlags = removeUnknownConfigureFlags (o.configureFlags or [ ]);
dontAddStaticConfigureFlags = true;
buildInputs = o.buildInputs ++ o.nativeBuildInputs or [ ];
propagatedNativeBuildInputs = o.propagatedBuildInputs or [ ];
});
Expand All @@ -75,7 +71,8 @@ self: super: let
preConfigure = ''
configureFlagsArray+=("-cc" "$CC" "-as" "$AS" "-partialld" "$LD -r")
'';
configureFlags = (removeUnknownConfigureFlags o.configureFlags) ++ [
dontAddStaticConfigureFlags = true;
configureFlags = [
"--no-shared-libs"
"-host ${o.stdenv.hostPlatform.config}"
"-target ${o.stdenv.targetPlatform.config}"
Expand Down Expand Up @@ -124,11 +121,6 @@ in {
if set ? overrideScope' then set.overrideScope' ocamlStaticAdapter else set
) super.ocaml-ng;

openssl = super.openssl_1_1.overrideAttrs (o: {
# OpenSSL doesn't like the `--enable-static` / `--disable-shared` flags.
configureFlags = (removeUnknownConfigureFlags o.configureFlags);
});

perl = super.perl.override {
# Don’t use new stdenv zlib because
# it doesn’t like the --disable-shared flag
Expand Down

0 comments on commit b0b5ef7

Please sign in to comment.