Skip to content

Commit b0b5ef7

Browse files
alyssaisJonathan Ringer
authored andcommitted
stdenv: introduce dontAddStaticConfigureFlags
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.
1 parent 8f3ead7 commit b0b5ef7

4 files changed

Lines changed: 14 additions & 12 deletions

File tree

doc/stdenv/stdenv.chapter.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,12 @@ The prefix under which the package must be installed, passed via the `--prefix`
463463

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

466+
##### `dontAddStaticConfigureFlags`
467+
468+
By default, when building statically, stdenv will try to add build system appropriate configure flags to try to enable static builds.
469+
470+
If this is undesirable, set this variable to true.
471+
466472
##### `dontAddDisableDepTrack` {#var-stdenv-dontAddDisableDepTrack}
467473

468474
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.
@@ -475,7 +481,7 @@ By default, the configure phase applies some special hackery to all files called
475481

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

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

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

pkgs/development/libraries/openssl/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ let
9393
throw "Not sure what configuration to use for ${stdenv.hostPlatform.config}"
9494
);
9595

96+
# OpenSSL doesn't like the `--enable-static` / `--disable-shared` flags.
97+
dontAddStaticConfigureFlags = true;
9698
configureFlags = [
9799
"shared" # "shared" builds both shared and static libraries
98100
"--libdir=lib"

pkgs/stdenv/adapters.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ rec {
4444
then throw "Cannot build fully static binaries on Darwin/macOS"
4545
else stdenv'.mkDerivation (args // {
4646
NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") + " -static";
47+
} // pkgs.lib.optionalAttrs (!(args.dontAddStaticConfigureFlags or false)) {
4748
configureFlags = (args.configureFlags or []) ++ [
4849
"--disable-shared" # brrr...
4950
];
@@ -56,6 +57,7 @@ rec {
5657
makeStaticLibraries = stdenv: stdenv //
5758
{ mkDerivation = args: stdenv.mkDerivation (args // {
5859
dontDisableStatic = true;
60+
} // pkgs.lib.optionalAttrs (!(args.dontAddStaticConfigureFlags or false)) {
5961
configureFlags = (args.configureFlags or []) ++ [
6062
"--enable-static"
6163
"--disable-shared"

pkgs/top-level/static.nix

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,10 @@ self: super: let
5050
# ++ optional (super.stdenv.hostPlatform.libc == "glibc") ((flip overrideInStdenv) [ self.stdenv.glibc.static ])
5151
;
5252

53-
removeUnknownConfigureFlags = f: with self.lib;
54-
remove "--disable-shared"
55-
(remove "--enable-static" f);
56-
5753
ocamlFixPackage = b:
5854
b.overrideAttrs (o: {
5955
configurePlatforms = [ ];
60-
configureFlags = removeUnknownConfigureFlags (o.configureFlags or [ ]);
56+
dontAddStaticConfigureFlags = true;
6157
buildInputs = o.buildInputs ++ o.nativeBuildInputs or [ ];
6258
propagatedNativeBuildInputs = o.propagatedBuildInputs or [ ];
6359
});
@@ -75,7 +71,8 @@ self: super: let
7571
preConfigure = ''
7672
configureFlagsArray+=("-cc" "$CC" "-as" "$AS" "-partialld" "$LD -r")
7773
'';
78-
configureFlags = (removeUnknownConfigureFlags o.configureFlags) ++ [
74+
dontAddStaticConfigureFlags = true;
75+
configureFlags = [
7976
"--no-shared-libs"
8077
"-host ${o.stdenv.hostPlatform.config}"
8178
"-target ${o.stdenv.targetPlatform.config}"
@@ -124,11 +121,6 @@ in {
124121
if set ? overrideScope' then set.overrideScope' ocamlStaticAdapter else set
125122
) super.ocaml-ng;
126123

127-
openssl = super.openssl_1_1.overrideAttrs (o: {
128-
# OpenSSL doesn't like the `--enable-static` / `--disable-shared` flags.
129-
configureFlags = (removeUnknownConfigureFlags o.configureFlags);
130-
});
131-
132124
perl = super.perl.override {
133125
# Don’t use new stdenv zlib because
134126
# it doesn’t like the --disable-shared flag

0 commit comments

Comments
 (0)