Skip to content

Commit 444e6a5

Browse files
committed
Add "Open questions" section, overlay for fixing pkg-config
1 parent 526e161 commit 444e6a5

File tree

2 files changed

+117
-1
lines changed

2 files changed

+117
-1
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,56 @@ You can contribute to these to help static Haskell executables:
157157
* No. For that you need need to use an old `static-haskell-nix` version: The one before [this PR](https://github.com/nh2/static-haskell-nix/pull/98) was merged.
158158
* I get some other error. Can I just file an issue and have you help me with it?
159159
* Yes. If possible (especially if your project is open source), please push some code so that your issue can be easily reproduced.
160+
161+
162+
## Open questions
163+
164+
* Nixpkgs issue [Provide middle-ground overlay between pkgsMusl and pkgsStatic](https://github.com/NixOS/nixpkgs/issues/61575):
165+
166+
Should nixpkgs provide a `makeStaticAndSharedLibraries` adapter to provide a package set?
167+
That might be better (but more difficult) than what we do now, with `dontDisableStaticOverlay`, because:
168+
* `dontDisableStatic` is to prevent `--disable-static` to autoconf, which is really specific to C + autoconf.
169+
A package set should do more than that, also for Meson, CMake, etc.
170+
`nh2` started implementing this idea in nixpkgs branch `static-haskell-nix-nixos-24.05-makeStaticAndSharedLibraries`.
171+
172+
* Can we avoid building bootstrap tools?
173+
* Our current overlays also build `xgcc`, `gcc`, `binutils`, and so on.
174+
* This is because we override all packages to have e.g. `.a` files, and some of those are also dependencies of e.g. `gcc`.
175+
* `pkgsStatic` avoids that by being a `cross` toolchain.
176+
* But might this cause additional issues?
177+
Because `cross` may have additional complexities when building the actual packages we're interested in, vs just switching the libc ("native" compilation)?
178+
Unclear.
179+
* For now, we accept those additional builds.
180+
181+
* How should we handle `pkg-config` regarding static dependencies?
182+
183+
E.g. `libtiff` depends on `lerc` and `libtiff-4.pc` correctly declares
184+
185+
```
186+
Libs.private: -llzma -lLerc -ljpeg -ldeflate -lz -lm
187+
Requires.private: liblzma libjpeg libdeflate zlib
188+
```
189+
190+
But the `.pc` file does not include the path on which `libLerc.a` can be found, nor does anything in nixpkgs set `PKG_CONFIG_PATH` such that `Lerc.pc` is on it.
191+
Thus, linking a static binary that uses `libtiff-4.pc` fails with
192+
193+
```
194+
cannot find -lLerc: No such file or directory
195+
```
196+
197+
* Should we use `propagatedBuildInputs` for this?
198+
* Yes! We can use `stdenvAdapters.propagateBuildInputs`.
199+
* Current problem: Using that in a native compilation (instead of cross as `pkgsMusl` does) causes:
200+
```
201+
error: build of '/nix/store/...-stdenv-linux.drv' failed: output '/nix/store/...-stdenv-linux' is not allowed to refer to the following paths:
202+
/nix/store/...-binutils-patchelfed-ld-wrapper-2.41
203+
/nix/store/...-pcre2-10.43-dev
204+
/nix/store/...-gmp-with-cxx-6.3.0-dev
205+
/nix/store/...-musl-iconv-1.2.3
206+
/nix/store/...-binutils-2.41
207+
/nix/store/...-bootstrap-tools
208+
```
209+
* John Ericson explained that the bootstrap rebuild avoidance (mentioned in a point above) also solves this issue for `pkgsStatic`.
210+
So we probably need to do something similar.
211+
* After fixing that, we still need to fix `libtiff` to include `lerc` in `Requires.private`.
212+
* Done in https://github.com/NixOS/nixpkgs/pull/320105

survey/default.nix

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,68 @@ let
589589
)
590590
];
591591

592+
593+
# For static builds, all `buildInputs` should become `propagatedBuildInputs`.
594+
# This is because a final link will necessarily have access to all recursive
595+
# dependencies.
596+
#
597+
# (`pkgsStatic` does this too, as `makeStatic` in `adapters.nix` uses
598+
# the `propagateBuildInputs` adapter.)
599+
#
600+
# Examples where this matters:
601+
#
602+
# * `pkg-config`:
603+
# * `libwebp` depends on `libtiff` which depends on `lerc`.
604+
# `libtiff-4.pc` correctly declares (with my patch
605+
# https://gitlab.com/libtiff/libtiff/-/merge_requests/633):
606+
#
607+
# Libs.private: -llzma -lLerc -ljpeg -ldeflate -lz -lm
608+
# Requires.private: liblzma Lerc libjpeg libdeflate zlib
609+
#
610+
# But the `.pc` file does not include the path on which `libLerc.a`
611+
# can be found.
612+
# Thus we would normally get error:
613+
#
614+
# cannot find -lLerc: No such file or directory
615+
#
616+
# That is supposed to be resolved via `pkg-config --static --libs libtiff-4`,
617+
# which is supposed to chase down the `Requires.private: Lerc` dependency,
618+
# finding the correct path of `libLerc.a` from `Lerc.pc`.
619+
# But for that to work `Lerc.pc` must be on `PKG_CONFIG_PATH`.
620+
# nixpkgs includes the `PKG_CONFIG_PATH` of `lerc` in the build
621+
# of `libwebp` only if `lerc` is in `propagatedBuildInputs` of `libtiff`.
622+
propagatedBuildInputsOverlay = final: previous: {
623+
# Doing this like `pkgsStatic` does it via `makeStatic` in `adapters.nix`.
624+
# Problem build error:
625+
# error: build of '/nix/store/...-stdenv-linux.drv' failed: output '/nix/store/...-stdenv-linux' is not allowed to refer to the following paths:
626+
# /nix/store/...-binutils-patchelfed-ld-wrapper-2.41
627+
# /nix/store/...-pcre2-10.43-dev
628+
# /nix/store/...-gmp-with-cxx-6.3.0-dev
629+
# /nix/store/...-musl-iconv-1.2.3
630+
# /nix/store/...-binutils-2.41
631+
# /nix/store/...-bootstrap-tools
632+
stdenv = previous.stdenvAdapters.propagateBuildInputs previous.stdenv;
633+
};
634+
635+
# Workaround to the above, overriding packages manually that need it.
636+
propagatedBuildInputsManuallyOverlay = final: previous: {
637+
638+
# Needs
639+
# https://github.com/NixOS/nixpkgs/pull/320105
640+
# to work, but we still have to have `lerc` in `propagatedBuildInputs`
641+
# so that downstream packages such as `libwebp` can see `lerc`'s `.pc` file.
642+
libtiff = previous.libtiff.overrideAttrs (oldAttrs: {
643+
propagatedBuildInputs = (oldAttrs.propagatedBuildInputs or []) ++ [
644+
final.lerc
645+
];
646+
});
647+
648+
};
649+
650+
# pkgsPropagatedBuildInputs = pkgs.extend propagatedBuildInputsOverlay;
651+
pkgsPropagatedBuildInputs = pkgs.extend propagatedBuildInputsManuallyOverlay;
652+
653+
592654
applyDontDisableStatic = pkgsSet: lib.mapAttrs (pkgName: pkgValue:
593655
if pkgValue ? overrideAttrs then
594656
pkgValue.overrideAttrs (old: { dontDisableStatic = true; })
@@ -601,7 +663,7 @@ let
601663
xorg = applyDontDisableStatic previous.xorg;
602664
};
603665

604-
pkgsDontDisableStatic = pkgs.extend dontDisableStaticOverlay;
666+
pkgsDontDisableStatic = pkgsPropagatedBuildInputs.extend dontDisableStaticOverlay;
605667

606668

607669
# Overlay that enables `.a` files for as many system packages as possible.
@@ -1723,6 +1785,7 @@ in
17231785
inherit lib;
17241786

17251787
inherit pkgsWithGhc;
1788+
inherit pkgsPropagatedBuildInputs;
17261789
inherit pkgsDontDisableStatic;
17271790
inherit pkgsWithArchiveFiles;
17281791
inherit pkgsWithStaticHaskellBinaries;

0 commit comments

Comments
 (0)