576576 makeFlags = [ "curl_LDFLAGS=-all-static" ] ;
577577 } ) ;
578578
579+
580+ fixGhc = ghcPackage0 : lib . pipe ghcPackage0 [
581+ # musl does not support libdw's alleged need for `dlopen()`, see:
582+ # https://github.com/nh2/static-haskell-nix/pull/116#issuecomment-1585786484
583+ #
584+ # Nixpkgs has the `enableDwarf` argument only for GHCs versions that are built
585+ # with Hadrian (`common-hadrian.nix`), which in nixpkgs is the case for GHC >= 9.6.
586+ # So set `enableDwarf = true`, but not for older versions known to not use Hadrian.
587+ ( ghcPackage :
588+ if lib . any ( prefix : lib . strings . hasPrefix prefix compiler ) [ "ghc8" "ghc90" "ghc92" "ghc94" ]
589+ then ghcPackage # GHC < 9.6, no Hadrian
590+ else ghcPackage . override { enableDwarf = false ; }
591+ )
592+ ( ghcPackage :
593+ ghcPackage . override {
594+ enableRelocatedStaticLibs = useArchiveFilesForTemplateHaskell ;
595+ enableShared = ! useArchiveFilesForTemplateHaskell ;
596+ }
597+ )
598+ ] ;
599+
600+
601+ applyDontDisableStatic = pkgValue :
602+ if pkgValue ? overrideAttrs then
603+ pkgValue . overrideAttrs ( old : { dontDisableStatic = true ; } )
604+ else
605+ pkgValue ;
606+
607+ dontDisableStaticOverlay = final : previous : lib . mapAttrs (
608+ pkgName : pkgValue : applyDontDisableStatic pkgValue
609+ ) previous ;
610+
611+ pkgsDontDisableStatic = pkgs . extend dontDisableStaticOverlay ;
612+
613+
579614 # Overlay that enables `.a` files for as many system packages as possible.
580615 # This is in *addition* to `.so` files.
581616 # See also https://github.com/NixOS/nixpkgs/issues/61575
584619 # in `adapters.nix` does it (but without disabling shared).
585620 archiveFilesOverlay = final : previous : {
586621
587- libffi = previous . libffi . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
588-
589- sqlite = previous . sqlite . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
590-
591- lzma = previous . lzma . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
592-
593622 # Note [Packages that cause bootstrap compiler recompilation]
594623 # The following packages are compiler bootstrap dependencies.
595624 # While we could override them to have static libraries
639668 # Disable failing tests for postgresql on musl that should have no impact
640669 # on the libpq that we need (collate.icu.utf8 and foreign regression tests)
641670 # This approach is copied from PostgREST, see https://github.com/PostgREST/postgrest/pull/2002/files#diff-72929db01d3c689277a1e7777b5df1dbbb20c5de41d1502ff8ac6b443a4e74c6R45
642- postgresql = ( previous . postgresql_14 . overrideAttrs ( old : { dontDisableStatic = true ; doCheck = false ; } ) ) . override {
671+ postgresql = ( previous . postgresql_14 . overrideAttrs ( old : { doCheck = false ; } ) ) . override {
643672 # We need libpq, which does not need systemd,
644673 # and systemd doesn't currently build with musl.
645674 enableSystemd = false ;
653682 withSystemd = false ;
654683 } ;
655684
656- libpsl = previous . libpsl . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
657- libunistring = previous . libunistring . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
658- libidn2 = previous . libidn2 . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
659-
660- pixman = previous . pixman . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
661- freetype = previous . freetype . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
662685 fontconfig = previous . fontconfig . overrideAttrs ( old : {
663- dontDisableStatic = true ;
664686 configureFlags = ( old . configureFlags or [ ] ) ++ [
665687 "--enable-static"
666688 ] ;
@@ -674,64 +696,18 @@ let
674696 # ld: ../../lib/libfontforge.so.4: undefined reference to `BrotliDefaultAllocFunc'
675697 woff2 = null ;
676698 } ) ;
677- cairo = previous . cairo . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
678- libpng = previous . libpng . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
679- libpng_apng = previous . libpng_apng . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
680- libpng12 = previous . libpng12 . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
681- libtiff = previous . libtiff . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
682- libwebp = previous . libwebp . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
683-
684- expat = previous . expat . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
685-
686- mpfr = previous . mpfr . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
687-
688- gmp = previous . gmp . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
689-
690- gsl = previous . gsl . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
691-
692- libxml2 = previous . libxml2 . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
693-
694- nettle = previous . nettle . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
695-
696- nghttp2 = previous . nghttp2 . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
697-
698- libssh2 = ( previous . libssh2 . overrideAttrs ( old : { dontDisableStatic = true ; } ) ) ;
699-
700- keyutils = previous . keyutils . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
701-
702- libxcb = previous . xorg . libxcb . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
703- libX11 = previous . xorg . libX11 . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
704- libXau = previous . xorg . libXau . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
705- libXcursor = previous . xorg . libXcursor . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
706- libXdmcp = previous . xorg . libXdmcp . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
707- libXext = previous . xorg . libXext . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
708- libXfixes = previous . xorg . libXfixes . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
709- libXi = previous . xorg . libXi . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
710- libXinerama = previous . xorg . libXinerama . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
711- libXrandr = previous . xorg . libXrandr . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
712- libXrender = previous . xorg . libXrender . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
713- libXScrnSaver = previous . xorg . libXScrnSaver . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
714- libXxf86vm = previous . xorg . libXxf86vm . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
715-
716- SDL2 = previous . SDL2 . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
717- SDL2_gfx = previous . SDL2_gfx . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
718- SDL2_image = previous . SDL2_image . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
719- SDL2_mixer = previous . SDL2_mixer . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
720699
721700 libjpeg = previous . libjpeg . override ( old : { enableStatic = true ; } ) ;
722701 libjpeg_turbo = previous . libjpeg_turbo . override ( old : { enableStatic = true ; } ) ;
723702
724703 openblas = ( previous . openblas . override { enableStatic = true ; } ) ;
725704
726705 libusb1 = previous . libusb1 . override { withStatic = true ; enableUdev = false ; } ;
727- libusb-compat-0_1 = previous . libusb-compat-0_1 . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
728706
729707 openssl = previous . openssl . override { static = true ; } ;
730708
731709 zstd = previous . zstd . override { enableStatic = true ; } ;
732710
733- libsass = previous . libsass . overrideAttrs ( old : { dontDisableStatic = true ; } ) ;
734-
735711 # Disabling kerberos support for now, as openssh's `./configure` fails to
736712 # detect its functions due to linker error, so the build breaks, see #68.
737713 openssh = previous . openssh . override { withKerberos = false ; } ;
868844
869845 } ;
870846
871- pkgsWithArchiveFiles = pkgs . extend archiveFilesOverlay ;
847+ pkgsWithArchiveFiles = pkgsDontDisableStatic . extend archiveFilesOverlay ;
872848
873- fixGhc = ghcPackage0 : lib . pipe ghcPackage0 [
874- # musl does not support libdw's alleged need for `dlopen()`, see:
875- # https://github.com/nh2/static-haskell-nix/pull/116#issuecomment-1585786484
876- #
877- # Nixpkgs has the `enableDwarf` argument only for GHCs versions that are built
878- # with Hadrian (`common-hadrian.nix`), which in nixpkgs is the case for GHC >= 9.6.
879- # So set `enableDwarf = true`, but not for older versions known to not use Hadrian.
880- ( ghcPackage :
881- if lib . any ( prefix : lib . strings . hasPrefix prefix compiler ) [ "ghc8" "ghc90" "ghc92" "ghc94" ]
882- then ghcPackage # GHC < 9.6, no Hadrian
883- else ghcPackage . override { enableDwarf = false ; }
884- )
885- ( ghcPackage :
886- ghcPackage . override {
887- enableRelocatedStaticLibs = useArchiveFilesForTemplateHaskell ;
888- enableShared = ! useArchiveFilesForTemplateHaskell ;
889- }
890- )
891- ] ;
892849
893850 setupGhcOverlay = final : previous :
894851 let
914871
915872 pkgsWithGhc = pkgsWithArchiveFiles . extend setupGhcOverlay ;
916873
874+
917875 # This overlay "fixes up" Haskell libraries so that static linking works.
918876 # See note "Don't add new packages here" below!
919877 haskellLibsReadyForStaticLinkingOverlay = final : previous : {
17431701 inherit lib ;
17441702
17451703 inherit pkgsWithGhc ;
1704+ inherit pkgsDontDisableStatic ;
17461705 inherit pkgsWithArchiveFiles ;
17471706 inherit pkgsWithStaticHaskellBinaries ;
17481707
0 commit comments