From 27ae28da3bac0ccaa7a01992ebe39818c3b232a3 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Wed, 15 Dec 2021 13:35:56 +0900 Subject: [PATCH 01/29] Bump nixpkgs.nix to pin to nixos-21.11 commit 573095944e7. --- nixpkgs.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nixpkgs.nix b/nixpkgs.nix index 18eb9c9..75886cd 100644 --- a/nixpkgs.nix +++ b/nixpkgs.nix @@ -25,4 +25,5 @@ if builtins.getEnv "STATIC_HASKELL_NIX_CI_NIXPKGS_UNSTABLE_BUILD" == "1" if builtins.pathExists ./nixpkgs/pkgs then import ./nixpkgs {} # Pinned nixpkgs version; should be kept up-to-date with our submodule. - else import (fetchTarball https://github.com/NixOS/nixpkgs/archive/d00b5a5fa6fe8bdf7005abb06c46ae0245aec8b5.tar.gz) {} + # This is nixos-21.11 as of 2021-12-15. + else import (fetchTarball https://github.com/NixOS/nixpkgs/archive/573095944e7c1d58d30fc679c81af63668b54056.tar.gz) {} From 49fce8dadea5011e9403ecf847c6ffb40e008e77 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Wed, 15 Dec 2021 13:36:36 +0900 Subject: [PATCH 02/29] Bump nixpkgs submodule to be on 21.11. --- nixpkgs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixpkgs b/nixpkgs index d00b5a5..5730959 160000 --- a/nixpkgs +++ b/nixpkgs @@ -1 +1 @@ -Subproject commit d00b5a5fa6fe8bdf7005abb06c46ae0245aec8b5 +Subproject commit 573095944e7c1d58d30fc679c81af63668b54056 From b92d8240cd4fde31160d5fec4674d9a61ab8f241 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Wed, 15 Dec 2021 13:45:24 +0900 Subject: [PATCH 03/29] Make sure the nixpkgs submodule is looking at NixOS/nixpkgs. --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 7b12849..597165b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "nixpkgs"] path = nixpkgs - url = https://github.com/nh2/nixpkgs.git + url = https://github.com/NixOS/nixpkgs.git From dbe55ac3c1fd2e628af8c5b2484966eb5a566f96 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Wed, 15 Dec 2021 13:52:55 +0900 Subject: [PATCH 04/29] Get the basic example working with 21.11. --- default.nix | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/default.nix b/default.nix index ef58216..3fc7fe7 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,6 @@ # Note: This is just a minimal example. For proper usage, see the README. -{ nixpkgs ? (import ./nixpkgs.nix).pkgsMusl, compiler ? "ghc864", strip ? true }: +{ nixpkgs ? (import ./nixpkgs.nix).pkgsMusl, compiler ? "ghc8107", strip ? true }: let @@ -12,7 +12,7 @@ let pname = "example-scotty-app"; version = "0.1.0.0"; src = pkgs.lib.sourceByRegex ./. [ - ".*\.cabal$" + ".*\\.cabal$" "^Setup.hs$" "^Main.hs$" ]; @@ -21,7 +21,7 @@ let enableSharedExecutables = false; enableSharedLibraries = false; executableHaskellDepends = [ base scotty ]; - license = stdenv.lib.licenses.bsd3; + license = pkgs.lib.licenses.bsd3; configureFlags = [ "--ghc-option=-optl=-static" "--extra-lib-dirs=${pkgs.gmp6.override { withStatic = true; }}/lib" @@ -37,7 +37,6 @@ let haskellPackages = with pkgs.haskell.lib; normalHaskellPackages.override { overrides = self: super: { # Dependencies we need to patch - hpc-coveralls = appendPatch super.hpc-coveralls (builtins.fetchurl https://github.com/guillaume-nargeot/hpc-coveralls/pull/73/commits/344217f513b7adfb9037f73026f5d928be98d07f.patch); }; }; From 9c4227e8efbfac179c784299acc9949f008622d4 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Wed, 15 Dec 2021 13:56:42 +0900 Subject: [PATCH 05/29] Add more ghc to cabal version mappings. --- survey/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/survey/default.nix b/survey/default.nix index 46d8066..45ba372 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -28,6 +28,7 @@ in # * https://www.snoyman.com/base/ # * https://www.haskell.org/cabal/download.html # section "Older Releases" + # * https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/libraries/version-history defaultCabalPackageVersionComingWithGhc ? ({ ghc822 = "Cabal_2_2_0_1"; # TODO this is technically incorrect for ghc 8.2.2, should be 2.0.1.0, but nixpkgs doesn't have that @@ -38,6 +39,7 @@ in ghc881 = "Cabal_3_0_0_0"; ghc8104 = "Cabal_3_2_1_0"; ghc8105 = "Cabal_3_2_1_0"; + ghc8107 = "Cabal_3_2_1_0"; ghc901 = "Cabal_3_4_0_0"; }."${compiler}"), From 2b08698a4766b7df6ab51daa3339a35536834020 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Wed, 15 Dec 2021 14:14:50 +0900 Subject: [PATCH 06/29] Bump to ghc-8.10.7. Nixpkgs is on LTS-18.16. --- survey/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/survey/default.nix b/survey/default.nix index 45ba372..1f1d718 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -22,7 +22,7 @@ in ])."${approach}", # When changing this, also change the default version of Cabal declared below - compiler ? "ghc8104", + compiler ? "ghc8107", # See: # * https://www.snoyman.com/base/ From b3f4744b7e1bc275459bb6da8ccb314005c59be7 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Wed, 15 Dec 2021 23:16:14 +0900 Subject: [PATCH 07/29] postgresl's tests fail when building with musl, so disable postgrest from the set of working Haskell packages --- survey/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/survey/default.nix b/survey/default.nix index 1f1d718..c1b78af 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -1567,7 +1567,7 @@ in bench dhall dhall-json - postgrest + # postgrest # postgresql's test fail proto3-suite hsyslog # Small example of handling https://github.com/NixOS/nixpkgs/issues/43849 correctly # aura # `aur` maked as broken in nixpkgs, but works here with `allowBroken = true;` actually From f30e2f5eb2f5072ae3fed86c9934d960d48b8575 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Wed, 15 Dec 2021 23:17:04 +0900 Subject: [PATCH 08/29] Apparently there is a curlMinimal top-level derivation now, which also needs to be statified. --- survey/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/survey/default.nix b/survey/default.nix index c1b78af..0ee1714 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -765,6 +765,9 @@ let # so that `curl` can use it. curl = statify_curl_including_exe previous.curl final.zlib_both; + # curlMinimal also needs to be statified. + curlMinimal = statify_curl_including_exe previous.curlMinimal final.zlib_both; + # `fetchurl` uses our overridden `curl` above, but `fetchurl` overrides # `zlib` in `curl`, see # https://github.com/NixOS/nixpkgs/blob/4a5c0e029ddbe89aa4eb4da7949219fe4e3f8472/pkgs/top-level/all-packages.nix#L296-L299 From 6e3e1df85703c1b6fcd071aa2d9e8f24fecafc26 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Wed, 15 Dec 2021 23:18:17 +0900 Subject: [PATCH 09/29] brotli support was added to curl and it needs to be explicitly disabled because it pulls in krb5 --- survey/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/survey/default.nix b/survey/default.nix index 0ee1714..767cf00 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -507,6 +507,7 @@ let # `archiveFilesOverlay` below where `statify_curl_including_exe` is used. gssSupport = false; zlib = zlib_both; + brotliSupport = false; })).overrideAttrs (old: { dontDisableStatic = true; From 4b1f174a7fc01cc86886887425f3d39a890dc156 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Fri, 17 Dec 2021 13:41:30 +0900 Subject: [PATCH 10/29] Make sure static archives symlinks are created for openblas. --- survey/default.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/survey/default.nix b/survey/default.nix index 767cf00..84e3c54 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -734,7 +734,17 @@ let libjpeg = previous.libjpeg.override (old: { enableStatic = true; }); libjpeg_turbo = previous.libjpeg_turbo.override (old: { enableStatic = true; }); - openblas = previous.openblas.override { enableStatic = true; }; + openblas = (previous.openblas.override { enableStatic = true; }).overrideAttrs (old: { + # openblas doesn't create symlinks for static archives like libblas.a and + # liblapack.a. The following lines fixes this. + # https://github.com/NixOS/nixpkgs/pull/151049 + postInstall = old.postInstall + '' + ln -s $out/lib/libopenblas.a $out/lib/libblas.a + ln -s $out/lib/libopenblas.a $out/lib/libcblas.a + ln -s $out/lib/libopenblas.a $out/lib/liblapack.a + ln -s $out/lib/libopenblas.a $out/lib/liblapacke.a + ''; + }); openssl = previous.openssl.override { static = true; }; From 4fa209cf610bb666b3adfe58c6b40c214826b62a Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Fri, 17 Dec 2021 14:01:07 +0900 Subject: [PATCH 11/29] Make sure blas-ffi uses openblasCompat. --- survey/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/survey/default.nix b/survey/default.nix index 84e3c54..585afd5 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -1202,6 +1202,13 @@ let # Tests fail with: doctests: : Dynamic loading not supported headroom = dontCheck super.headroom; + # We need to explicitly get blas from openblasCompat, since + # otherwise openblas is used and Haskell programs like `resistor-cube` + # won't be able to find libblas. + blas-ffi = super.blas-ffi.override { + blas = final.openblasCompat; + }; + hmatrix = # musl does not have `random_r()`. (enableCabalFlag super.hmatrix "no-random_r") From 83b18226a6bdf2ebca0f334235312b9ab2bc45f9 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Fri, 17 Dec 2021 14:01:40 +0900 Subject: [PATCH 12/29] Disable stackage executable magico because of gfortran linking error. --- survey/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/survey/default.nix b/survey/default.nix index 585afd5..1eea2a5 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -1647,6 +1647,7 @@ in "LambdaHack" # fails `systemd` dependency erroring on `#include ` "language-puppet" # `base >=4.6 && <4.14, ghc-prim >=0.3 && <0.6` for dependency `protolude` "learn-physics" # needs opengl: `cannot find -lGLU` `-lGL` + "magico" # undefined reference to `_gfortran_concat_string' "odbc" # `odbcss.h: No such file or directory` "qchas" # `_gfortran_concat_string` linker error via openblas "rhine-gloss" # needs opengl: `cannot find -lGLU` `-lGL` From d41b96acc100331a1c9e69fffcfc6ff4bc979dc4 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Fri, 17 Dec 2021 14:18:17 +0900 Subject: [PATCH 13/29] Disable stackage packages that depend on postgres. --- survey/default.nix | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/survey/default.nix b/survey/default.nix index 1eea2a5..7c913aa 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -265,6 +265,17 @@ let # https://github.com/nh2/static-haskell-nix/issues/6#issuecomment-420494800 "sparkle" + # PostgreSQL's test suite doesn't pass: + # https://github.com/NixOS/nixpkgs/issues/150930 + # + # Even if the test suite is disabled, these Haskell binaries fail in + # linking with errors like: + # + # ld: libpq.a(fe-auth-scram.o): in function `pg_fe_scram_build_secret': + # /build/postgresql-13.4/src/interfaces/libpq/fe-auth-scram.c:839:0: error: + # undefined reference to `pg_saslprep' + "hasql-notifications" "hasql-queue" "postgresql-orm" "postgrest" "tmp-postgres" + # These ones currently don't compile for not-yet-investigated reasons: "amqp-utils" "elynx" From 1b57af797cbbe9c5bc1b87a7d348a40eee7f284f Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Fri, 17 Dec 2021 15:50:35 +0900 Subject: [PATCH 14/29] Make sure libdevil has libdeflate as buildInput. --- survey/default.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/survey/default.nix b/survey/default.nix index 7c913aa..462c366 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -859,6 +859,21 @@ let }; }; + # I'm not sure why this is needed. As far as I can tell, libdevil doesn't + # directly link to libdeflate. But libdevil does link to libtiff, which + # uses libdeflate. + # + # However, if libdevil doesn't have libdeflate as a buildInput, building + # libdevil fails with linking errors. + # + # I wasn't able to report this upstream, because in nixpkgs libdevil and + # pkgsMusl.libdevil build correctly. Some transitive dependencies for + # pkgsStatic.libdevil fail to build, so it is hard to say whether this is a + # static-haskell-nix problem, or just a static-linking problem. + libdevil = previous.libdevil.overrideAttrs (oldAttrs: { + buildInputs = oldAttrs.buildInputs ++ [ final.libdeflate ]; + }); + }; From 3d0be9a16f85a3a530fdffcde77b1c6e93b79229 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Sat, 18 Dec 2021 14:43:27 +0900 Subject: [PATCH 15/29] Drop to postgresql-11 and re-enable all Haskell packages that use postgres. --- survey/default.nix | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/survey/default.nix b/survey/default.nix index 462c366..bdcb8fa 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -265,17 +265,6 @@ let # https://github.com/nh2/static-haskell-nix/issues/6#issuecomment-420494800 "sparkle" - # PostgreSQL's test suite doesn't pass: - # https://github.com/NixOS/nixpkgs/issues/150930 - # - # Even if the test suite is disabled, these Haskell binaries fail in - # linking with errors like: - # - # ld: libpq.a(fe-auth-scram.o): in function `pg_fe_scram_build_secret': - # /build/postgresql-13.4/src/interfaces/libpq/fe-auth-scram.c:839:0: error: - # undefined reference to `pg_saslprep' - "hasql-notifications" "hasql-queue" "postgresql-orm" "postgrest" "tmp-postgres" - # These ones currently don't compile for not-yet-investigated reasons: "amqp-utils" "elynx" @@ -667,7 +656,12 @@ let #patchelf = issue_61682_throw "patchelf" previous.patchelf; #xz = issue_61682_throw "xz" previous.xz; - postgresql = (previous.postgresql.overrideAttrs (old: { dontDisableStatic = true; })).override { + # The test-suite for PostgreSQL 13 fails: + # https://github.com/NixOS/nixpkgs/issues/150930 + # + # Even if you disable the test-suite, there are various linking issues. + # PostgreSQL 12 has similar issues, so we drop to PostgreSQL 11. + postgresql = (previous.postgresql_11.overrideAttrs (old: { dontDisableStatic = true; })).override { # We need libpq, which does not need systemd, # and systemd doesn't currently build with musl. enableSystemd = false; @@ -1614,7 +1608,7 @@ in bench dhall dhall-json - # postgrest # postgresql's test fail + postgrest proto3-suite hsyslog # Small example of handling https://github.com/NixOS/nixpkgs/issues/43849 correctly # aura # `aur` maked as broken in nixpkgs, but works here with `allowBroken = true;` actually From 14d4ace3f095088cac84b9b17c8607e40b876e67 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Wed, 27 Jul 2022 16:15:23 +0000 Subject: [PATCH 16/29] new ncurses --- survey/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/survey/default.nix b/survey/default.nix index bdcb8fa..4c0b38f 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -1562,7 +1562,7 @@ let [ "--enable-executable-static" # requires `useFixedCabal` # `enableShared` seems to be required to avoid `recompile with -fPIC` errors on some packages. - "--extra-lib-dirs=${final.ncurses.override { enableStatic = true; enableShared = true; }}/lib" + "--extra-lib-dirs=${final.ncurses.override { enableStatic = true; }}/lib" ] # TODO Figure out why this and the below libffi are necessary. # `working` and `workingStackageExecutables` don't seem to need that, From 6bdf17bcb709925a8c68b9dd95ff76bdb60a01c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Sat, 10 Jun 2023 17:14:42 +0000 Subject: [PATCH 17/29] Update to nixos-23.05 --- nixpkgs | 2 +- survey/default.nix | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nixpkgs b/nixpkgs index 5730959..85bcb95 160000 --- a/nixpkgs +++ b/nixpkgs @@ -1 +1 @@ -Subproject commit 573095944e7c1d58d30fc679c81af63668b54056 +Subproject commit 85bcb95aa83be667e562e781e9d186c57a07d757 diff --git a/survey/default.nix b/survey/default.nix index 4c0b38f..9dec2a0 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -22,7 +22,7 @@ in ])."${approach}", # When changing this, also change the default version of Cabal declared below - compiler ? "ghc8107", + compiler ? "ghc927", # See: # * https://www.snoyman.com/base/ @@ -41,6 +41,8 @@ in ghc8105 = "Cabal_3_2_1_0"; ghc8107 = "Cabal_3_2_1_0"; ghc901 = "Cabal_3_4_0_0"; + ghc927 = "Cabal_3_6_3_0"; + ghc962 = "Cabal_3_10_1_0"; }."${compiler}"), # Use `integer-simple` instead of `integer-gmp` to avoid linking in From b11ecc6b0d7aba1d5d293c938a7f6fe70609e46d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Sat, 10 Jun 2023 17:38:07 +0000 Subject: [PATCH 18/29] Fix `approachPkgs` being the wrong value. It picked the one from the line below it due to `let rec` instead of the one from the top-level arguments. --- survey/default.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/survey/default.nix b/survey/default.nix index 9dec2a0..7deda83 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -79,6 +79,8 @@ let lib = pkgs.lib; + approachPkgs = pkgs; + # Function that tells us if a given entry in a `haskellPackages` package set # is a proper Haskell package (as opposed to some fancy function like # `.override` and the likes). @@ -1677,7 +1679,7 @@ in ]; inherit normalPkgs; - approachPkgs = pkgs; + inherit approachPkgs; # Export as `pkgs` our final overridden nixpkgs. pkgs = pkgsWithStaticHaskellBinaries; From 9dfc7f20deec72e35f6b549de1139145bc573f5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Sat, 10 Jun 2023 19:03:34 +0000 Subject: [PATCH 19/29] Add comment on curl brotli disabling --- survey/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/survey/default.nix b/survey/default.nix index 7deda83..bdccdc6 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -511,7 +511,7 @@ let # `archiveFilesOverlay` below where `statify_curl_including_exe` is used. gssSupport = false; zlib = zlib_both; - brotliSupport = false; + brotliSupport = false; # When brotli is enabled, the `curl` package currently fails to link in `CCLD curl` with error `ld: ../lib/.libs/libcurl.so: undefined reference to `_kBrotliPrefixCodeRanges'` })).overrideAttrs (old: { dontDisableStatic = true; From d90f0ec550a445d489c39a146d2dfd60febb97f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Sat, 10 Jun 2023 20:26:28 +0000 Subject: [PATCH 20/29] Disable GHC dwarf support --- survey/default.nix | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/survey/default.nix b/survey/default.nix index bdccdc6..22ef72e 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -1544,10 +1544,36 @@ let pkgsWithHaskellLibsReadyForStaticLinking = pkgsWithArchiveFiles.extend haskellLibsReadyForStaticLinkingOverlay; + fixGhc = ghcPackage0: lib.pipe ghcPackage0 [ + # musl does not support libdw's alleged need for `dlopen()`, see: + # https://github.com/nh2/static-haskell-nix/pull/116#issuecomment-1585786484 + # + # Nixpkgs has the `enableDwarf` argument only for GHCs versions that are built + # with Hadrian (`common-hadrian.nix`), which in nixpkgs is the case for GHC >= 9.6. + # So set `enableDwarf = true`, but not for older versions known to not use Hadrian. + (ghcPackage: + if lib.any (prefix: lib.strings.hasPrefix prefix compiler) ["ghc8" "ghc90" "ghc92" "ghc94"] + then ghcPackage # GHC < 9.6, no Hadrian + else ghcPackage.override { enableDwarf = false; } + ) + ]; # Overlay all Haskell executables are statically linked. staticHaskellBinariesOverlay = final: previous: { haskellPackages = previous.haskellPackages.override (old: { + + # To override GHC, we need to override both `ghc` and the one in + # `buildHaskellPackages` because otherwise this code in `geneic-builder.nix` + # will make our package depend on 2 different GHCs: + # nativeGhc = buildHaskellPackages.ghc; + # depsBuildBuild = [ nativeGhc ] ... + # nativeBuildInputs = [ ghc removeReferencesTo ] ... + # + ghc = fixGhc old.ghc; + buildHaskellPackages = old.buildHaskellPackages.override (oldBuildHaskellPackages: { + ghc = fixGhc oldBuildHaskellPackages.ghc; + }); + overrides = final.lib.composeExtensions (old.overrides or (_: _: {})) (self: super: let # We have to use `useFixedCabal` here, and cannot just rely on the From c91a9b42674fc87af95512d37605932c29cf370c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Sun, 11 Jun 2023 15:10:33 +0000 Subject: [PATCH 21/29] Add `useArchiveFilesForTemplateHaskell` option. The motivation is that @aherrmann and @jonathanlking want to use Bazel and found that it might it easier to use `.a` files in TH than to try to provide `.so` AND `.a` files of all dependencies. --- survey/default.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/survey/default.nix b/survey/default.nix index 22ef72e..608f594 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -24,6 +24,9 @@ in # When changing this, also change the default version of Cabal declared below compiler ? "ghc927", + # Tries to use `.a` files when evaluating TH, instead of `.so` files. + useArchiveFilesForTemplateHaskell ? false, + # See: # * https://www.snoyman.com/base/ # * https://www.haskell.org/cabal/download.html @@ -1556,6 +1559,9 @@ let then ghcPackage # GHC < 9.6, no Hadrian else ghcPackage.override { enableDwarf = false; } ) + (ghcPackage: + ghcPackage.override { enableRelocatedStaticLibs = useArchiveFilesForTemplateHaskell; } + ) ]; # Overlay all Haskell executables are statically linked. From 0236a8261cad1ac046e3fa3e8bda139ad7753e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Mon, 12 Jun 2023 11:46:15 +0000 Subject: [PATCH 22/29] Fix `workingStackageExecutables`'s YAML loading. See https://stackoverflow.com/questions/69564817/typeerror-load-missing-1-required-positional-argument-loader-in-google-col/69581453#69581453 --- survey/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/survey/default.nix b/survey/default.nix index 608f594..ddfefdf 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -124,7 +124,7 @@ let stackageInfoPath = pkgs.path + "/pkgs/development/haskell-modules/configuration-hackage2nix/stackage.yaml"; pythonWithYaml = normalPkgs.python3Packages.python.withPackages (pkgs: [pkgs.pyyaml]); stackage-packages-file = normalPkgs.runCommand "stackage-packages" {} '' - ${pythonWithYaml}/bin/python -c 'import yaml, json; x = yaml.load(open("${stackageInfoPath}")); print(json.dumps([line.split(" ")[0] for line in x["default-package-overrides"]]))' > $out + ${pythonWithYaml}/bin/python -c 'import yaml, json; x = yaml.safe_load(open("${stackageInfoPath}")); print(json.dumps([line.split(" ")[0] for line in x["default-package-overrides"]]))' > $out ''; stackage-packages = builtins.fromJSON (builtins.readFile stackage-packages-file); in From 2c20f1466335f326fbb378f51faa5385e0c7bd6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Tue, 13 Jun 2023 00:06:32 +0000 Subject: [PATCH 23/29] Add nixpkgs patch to add .a files to bzip2 and zstd --- nixpkgs | 2 +- survey/default.nix | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/nixpkgs b/nixpkgs index 85bcb95..2bb2dd4 160000 --- a/nixpkgs +++ b/nixpkgs @@ -1 +1 @@ -Subproject commit 85bcb95aa83be667e562e781e9d186c57a07d757 +Subproject commit 2bb2dd4e348ec4fabf0acdd9ba8c06ce1252bb30 diff --git a/survey/default.nix b/survey/default.nix index ddfefdf..ae17600 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -613,7 +613,7 @@ let acl_static = previous.acl.overrideAttrs (old: { dontDisableStatic = true; }); attr_static = previous.attr.overrideAttrs (old: { dontDisableStatic = true; }); bash_static = previous.bash.overrideAttrs (old: { dontDisableStatic = true; }); - bzip2_static = previous.bzip2.overrideAttrs (old: { dontDisableStatic = true; }); + bzip2_static = (previous.bzip2.override { enableStatic = true; }).overrideAttrs (old: { dontDisableStatic = true; }); coreutils_static = previous.coreutils.overrideAttrs (old: { dontDisableStatic = true; }); diffutils_static = previous.diffutils.overrideAttrs (old: { dontDisableStatic = true; }); findutils_static = previous.findutils.overrideAttrs (old: { dontDisableStatic = true; }); @@ -760,6 +760,8 @@ let openssl = previous.openssl.override { static = true; }; + zstd = previous.zstd.override { enableStatic = true; }; + libsass = previous.libsass.overrideAttrs (old: { dontDisableStatic = true; }); # Disabling kerberos support for now, as openssh's `./configure` fails to @@ -1186,10 +1188,14 @@ let # doctests: doctests: unable to load package `ghc-prim-0.5.3' yesod-paginator = dontCheck super.yesod-paginator; - # Disabling test suite because it takes extremely long (> 30 minutes): - # https://github.com/mrkkrp/zip/issues/55 - # TODO: Re-enable when we have version `1.3.1` of it which has the fix. - zip = dontCheck super.zip; + # Workaround for `zip`'s dependency `bzlib-conduit` using `extra-libraries: bz` + # instead of `pkgconfig-depends`. + # TODO: Make a PR to fix that. + zip = + addStaticLinkerFlagsWithPkgconfig + (super.zip.overrideAttrs (old: { configureFlags = (old.configureFlags or []) ++ ["--ghc-options=-v"]; })) + [ final.bzip2_static ] + "--libs bzip2"; # Override libs explicitly that can't be overridden with overlays. # See note [Packages that can't be overridden by overlays]. @@ -1320,8 +1326,8 @@ let hopenpgp-tools = addStaticLinkerFlagsWithPkgconfig super.hopenpgp-tools - [ final.nettle final.bzip2 ] - "--libs nettle bz2"; + [ final.nettle final.bzip2_static ] + "--libs nettle bzip2"; sdl2-gfx = addStaticLinkerFlagsWithPkgconfig From 70aa4a17145d114e808e7f756ee66f0fa5460028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Tue, 13 Jun 2023 00:07:06 +0000 Subject: [PATCH 24/29] Make `.working` pass --- survey/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/survey/default.nix b/survey/default.nix index ae17600..d317739 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -1651,7 +1651,7 @@ in dhall dhall-json postgrest - proto3-suite + # proto3-suite # Dependency `proto3-wire-1.4.0` does not build due to `bytestring >=0.10.6.0 && <0.11.0` hsyslog # Small example of handling https://github.com/NixOS/nixpkgs/issues/43849 correctly # aura # `aur` maked as broken in nixpkgs, but works here with `allowBroken = true;` actually ; From 9dd4c43221536fc8e1d2e59379378a214dd3e430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Tue, 13 Jun 2023 00:07:19 +0000 Subject: [PATCH 25/29] Remove old compilers: Those no longer packaged by nixpkgs, and 8.8, so that we can assume >= 8.10. --- survey/default.nix | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/survey/default.nix b/survey/default.nix index d317739..7115537 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -27,23 +27,11 @@ in # Tries to use `.a` files when evaluating TH, instead of `.so` files. useArchiveFilesForTemplateHaskell ? false, - # See: - # * https://www.snoyman.com/base/ - # * https://www.haskell.org/cabal/download.html - # section "Older Releases" - # * https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/libraries/version-history + # See https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/libraries/version-history defaultCabalPackageVersionComingWithGhc ? ({ - ghc822 = "Cabal_2_2_0_1"; # TODO this is technically incorrect for ghc 8.2.2, should be 2.0.1.0, but nixpkgs doesn't have that - ghc844 = "Cabal_2_2_0_1"; - ghc863 = throw "static-haskell-nix: ghc863 is no longer supported, please upgrade"; - ghc864 = throw "static-haskell-nix: ghc864 is no longer supported, please upgrade"; - ghc865 = "Cabal_2_4_1_0"; # TODO this is technically incorrect for ghc 8.6.5, should be 2.4.0.1, but nixpkgs doesn't have that - ghc881 = "Cabal_3_0_0_0"; - ghc8104 = "Cabal_3_2_1_0"; - ghc8105 = "Cabal_3_2_1_0"; ghc8107 = "Cabal_3_2_1_0"; - ghc901 = "Cabal_3_4_0_0"; + ghc902 = "Cabal_3_4_1_0"; ghc927 = "Cabal_3_6_3_0"; ghc962 = "Cabal_3_10_1_0"; }."${compiler}"), From da073d57467f13922ec88145bc0f25f82a978a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Tue, 13 Jun 2023 00:08:18 +0000 Subject: [PATCH 26/29] Remove workarounds no longer necessary with nixos-23.05 --- survey/default.nix | 101 ++++++++++++++------------------------------- 1 file changed, 32 insertions(+), 69 deletions(-) diff --git a/survey/default.nix b/survey/default.nix index 7115537..fa65792 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -588,16 +588,21 @@ let lzma = previous.lzma.overrideAttrs (old: { dontDisableStatic = true; }); - # Note [Packages that can't be overridden by overlays] - # TODO: Overriding the packages mentioned here has no effect in overlays. - # This is because of https://github.com/NixOS/nixpkgs/issues/61682. - # That's why we make up new package names with `_static` at the end, - # and explicitly give them to packages or as linker flags in `statify`. - # See also that link for the total list of packages that have this problem. - # As of original finding it is, as per `pkgs/stdenv/linux/default.nix`: - # gzip bzip2 xz bash coreutils diffutils findutils gawk - # gnumake gnused gnutar gnugrep gnupatch patchelf - # attr acl zlib pcre + # Note [Packages that cause bootstrap compiler recompilation] + # The following packages are compiler bootstrap dependencies. + # While we could override them to have static libraries + # (now that https://github.com/NixOS/nixpkgs/issues/61682 is fixed), + # we don't currently because that would make even the compiler bootstrapping recompile. + # Instead we make up new package names with `_static` at the end, + # and explicitly give them to packages. + # See also the above link for the total list of packages that are relevant for this. + # As of original finding it is, as per `pkgs/stdenv/linux/default.nix`: + # gzip bzip2 xz bash coreutils diffutils findutils gawk + # gnumake gnused gnutar gnugrep gnupatch patchelf + # attr acl zlib pcre + # TODO: Check if this really saves enough compilation to be worth the added complexity. + # Alternatively, try to override the bootstrap compiler to use the original + # ones; then we can override the normal names here. acl_static = previous.acl.overrideAttrs (old: { dontDisableStatic = true; }); attr_static = previous.attr.overrideAttrs (old: { dontDisableStatic = true; }); bash_static = previous.bash.overrideAttrs (old: { dontDisableStatic = true; }); @@ -628,28 +633,6 @@ let # # So somehow, the above `zlib_static` uses *this* `zlib`, even though # the above uses `previous.zlib.override` and thus shouldn't see this one. - #zlib = issue_61682_throw "zlib" previous.zlib; - # Similarly, we don't know why these are are evaluated, but it happens for - # https://github.com/nh2/static-haskell-nix/issues/47. - #bzip2 = issue_61682_throw "bzip2" previous.bzip2; - #pcre = issue_61682_throw "pcre" previous.pcre; - # Since the update to nixpkgs master for #61 also for these, - # see https://github.com/NixOS/nixpkgs/issues/61682#issuecomment-544215621 - #acl = issue_61682_throw "acl" previous.acl; - #attr = issue_61682_throw "attr" previous.attr; - #bash = issue_61682_throw "bash" previous.bash; - #coreutils = issue_61682_throw "coreutils" previous.coreutils; - #diffutils = issue_61682_throw "diffutils" previous.diffutils; - #findutils = issue_61682_throw "findutils" previous.findutils; - #gawk = issue_61682_throw "gawk" previous.gawk; - #gnugrep = issue_61682_throw "gnugrep" previous.gnugrep; - #gnumake = issue_61682_throw "gnumake" previous.gnumake; - #gnupatch = issue_61682_throw "gnupatch" previous.gnupatch; - #gnused = issue_61682_throw "gnused" previous.gnused; - #gnutar = issue_61682_throw "gnutar" previous.gnutar; - #gzip = issue_61682_throw "gzip" previous.gzip; - #patchelf = issue_61682_throw "patchelf" previous.patchelf; - #xz = issue_61682_throw "xz" previous.xz; # The test-suite for PostgreSQL 13 fails: # https://github.com/NixOS/nixpkgs/issues/150930 @@ -734,17 +717,7 @@ let libjpeg = previous.libjpeg.override (old: { enableStatic = true; }); libjpeg_turbo = previous.libjpeg_turbo.override (old: { enableStatic = true; }); - openblas = (previous.openblas.override { enableStatic = true; }).overrideAttrs (old: { - # openblas doesn't create symlinks for static archives like libblas.a and - # liblapack.a. The following lines fixes this. - # https://github.com/NixOS/nixpkgs/pull/151049 - postInstall = old.postInstall + '' - ln -s $out/lib/libopenblas.a $out/lib/libblas.a - ln -s $out/lib/libopenblas.a $out/lib/libcblas.a - ln -s $out/lib/libopenblas.a $out/lib/liblapack.a - ln -s $out/lib/libopenblas.a $out/lib/liblapacke.a - ''; - }); + openblas = (previous.openblas.override { enableStatic = true; }); openssl = previous.openssl.override { static = true; }; @@ -773,7 +746,7 @@ let woff2 = previous.woff2.override { static = true; }; # See comments on `statify_curl_including_exe` for the interaction with krb5! - # As mentioned in [Packages that can't be overridden by overlays], we can't + # As mentioned in [Packages that cause bootstrap compiler recompilation], we can't # override zlib to have static libs, so we have to pass in `zlib_both` explicitly # so that `curl` can use it. curl = statify_curl_including_exe previous.curl final.zlib_both; @@ -784,7 +757,7 @@ let # `fetchurl` uses our overridden `curl` above, but `fetchurl` overrides # `zlib` in `curl`, see # https://github.com/NixOS/nixpkgs/blob/4a5c0e029ddbe89aa4eb4da7949219fe4e3f8472/pkgs/top-level/all-packages.nix#L296-L299 - # so because of [Packages that can't be overridden by overlays], + # so because of [Packages that cause bootstrap compiler recompilation], # it will undo our `zlib` override in `curl` done above (for `curl` # use via `fetchurl`). # So we need to explicitly put our zlib into that one's curl here. @@ -888,21 +861,14 @@ let # Helper function to add pkg-config static lib flags to a Haskell derivation. # We put it directly into the `pkgs` package set so that following overlays # can use it as well if they want to. + # + # Note that for linking the order of libraries given on the command line matters: + # https://stackoverflow.com/questions/11893996/why-does-the-order-of-l-option-in-gcc-matter + # Before my GHC change https://gitlab.haskell.org/ghc/ghc/merge_requests/1589 + # was merged that ensured the order is correct, we used a hack using + # `--ld-option=-Wl,--start-group` to make the order not matter. staticHaskellHelpers.addStaticLinkerFlagsWithPkgconfig = haskellDrv: pkgConfigNixPackages: pkgconfigFlagsString: - with final.haskell.lib; overrideCabal (appendConfigureFlag haskellDrv [ - # Ugly alert: We use `--start-group` to work around the fact that - # the linker processes `-l` flags in the order they are given, - # so order matters, see - # https://stackoverflow.com/questions/11893996/why-does-the-order-of-l-option-in-gcc-matter - # and GHC inserts these flags too early, that is in our case, before - # the `-lcurl` that pulls in these dependencies; see - # https://github.com/haskell/cabal/pull/5451#issuecomment-406759839 - # Note that current binutils emit a warning: - # ld: missing --end-group; added as last command line option - # TODO: This can be removed once we have GHC 8.10, due to my merged PR: - # https://gitlab.haskell.org/ghc/ghc/merge_requests/1589 - "--ld-option=-Wl,--start-group" - ]) (old: { + with final.haskell.lib; overrideCabal haskellDrv (old: { # We can't pass all linker flags in one go as `ld-options` because # the generic Haskell builder doesn't let us pass flags containing spaces. preConfigure = builtins.concatStringsSep "\n" [ @@ -1023,7 +989,7 @@ let # Override zlib Haskell package to use the system zlib package # that has `.a` files added. # This is because the system zlib package can't be overridden accordingly, - # see note [Packages that can't be overridden by overlays]. + # see note [Packages that cause bootstrap compiler recompilation]. zlib = super.zlib.override { zlib = final.zlib_both; }; # The `properties` test suite takes > 30 minutes with `-O0`. @@ -1186,7 +1152,7 @@ let "--libs bzip2"; # Override libs explicitly that can't be overridden with overlays. - # See note [Packages that can't be overridden by overlays]. + # See note [Packages that cause bootstrap compiler recompilation]. regex-pcre = super.regex-pcre.override { pcre = final.pcre_static; }; pcre-light = super.pcre-light.override { pcre = final.pcre_static; }; bzlib-conduit = super.bzlib-conduit.override { bzip2 = final.bzip2_static; }; @@ -1405,14 +1371,6 @@ let sha256 = "05bbn63sn18s6c7gpcmzbv4hyfhn1i9bd2bw76bv6abr58lnrwk3"; }) {}; - # Override yaml on old versions to fix https://github.com/NixOS/cabal2nix/issues/372. - # I've checked that versions >= 0.11.0.0 in nixpkgs on ghc864 don't need this - # but `yaml-0.8.32` on ghc844 still does. - yaml = - if final.lib.versionOlder super.yaml.version "0.11.0.0" - then disableCabalFlag super.yaml "system-libyaml" - else super.yaml; - # TODO Find out why these overrides are necessary, given that they all come from `final` # (somehow without them, xmonad gives linker errors). # Most likely it is because the `libX*` packages are available once on the top-level @@ -1533,6 +1491,11 @@ let # Exception: test-files/trivial.proto: openFile: does not exist (No such file or directory) # 2 out of 71 tests failed (1.97s) proto3-suite = dontCheck super.proto3-suite; + + # Fix syntax error in test. + # Remove when nixpkgs has data-diverse >= 4.7.1.0, see: + # https://github.com/louispan/data-diverse/commit/50d79a011d2a9c55ca4b21a424f177d6bbd2663c + data-diverse = markUnbroken (dontCheck super.data-diverse); }); }); From 579393263cc2009340d29faafb5917489c50c519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Tue, 13 Jun 2023 09:53:26 +0000 Subject: [PATCH 27/29] Fix arbtt needing libxcb --- survey/default.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/survey/default.nix b/survey/default.nix index fa65792..95c115c 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -1002,6 +1002,19 @@ let (if disableOptimization then dontCheck else lib.id) super.ap-normalize; + arbtt = + addStaticLinkerFlagsWithPkgconfig + super.arbtt + (with final; [ + nettle + + libX11 + libXdmcp + libXau + libxcb + ]) + "--libs nettle x11-xcb"; + # `criterion`'s test suite fails with a timeout if its dependent # libraries (apparently `bytestring`) are compiled with `-O0`. # Even increasing the timeout 5x did not help! From 63232fca05629e9ecca7089a9dfb16d623168fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Thu, 13 Jul 2023 19:36:04 +0000 Subject: [PATCH 28/29] Fix more packages. `workingStackageExecutables` builds on top of nixos-23.05. Only minimal patches are put on top of the `nixos-23.05` branch to support more of Stackage. All have nixpkgs PRs. nix-build --no-link survey/default.nix -A workingStackageExecutables | wc -l 368 --- README.md | 13 +++++++++++ nixpkgs | 2 +- survey/default.nix | 58 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 95b1000..0eebe19 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,12 @@ Until Stack 2.3, the official static build of `stack` itself was built using thi The [`static-stack`](./static-stack) directory shows how Stack itself can be built statically with static-haskell-nix. `stack` is a big package with many dependencies, demonstrating that it works also for large projects. +## Related important open issues + +You can contribute to these to help static Haskell executables: + +* https://github.com/haskell/cabal/issues/8455 + ## FAQ * I get `cannot find section .dynamic`. Is this an error? @@ -116,6 +122,13 @@ The [`static-stack`](./static-stack) directory shows how Stack itself can be bui then `/nix/store/dax3wjbjfrcwj6r3mafxj5fx6wcg5zbp-stack-2.3.0.1` is your final output _store path_ whose `/bin` directory contains your static executable. * I get `stack2nix: user error (No such package mypackage-1.2.3 in the cabal database. Did you run cabal update?)`. * You most likely have to bump the date like `hackageSnapshot = "2019-05-08T00:00:00Z";` to a newer date (past the time that package-version was added to Hackage). +* I get a linker error. + What's a good way to investigate what the linker invocation is? + * Pass `-v` to Cabal, and to GHC itself: + ```sh + nix-build --expr '(import ./survey/default.nix {}).haskellPackages.YOURPACKAGE.overrideAttrs (old: { configureFlags = (old.configureFlags or []) ++ ["-v" "--ghc-options=-v"]; })' + ``` + Look for `*** Linker:` in the GHC output. * Can I build Stack projects with resolvers that are too old to be supported by Stack >= 2? * 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. * I get some other error. Can I just file an issue and have you help me with it? diff --git a/nixpkgs b/nixpkgs index 2bb2dd4..fbceb79 160000 --- a/nixpkgs +++ b/nixpkgs @@ -1 +1 @@ -Subproject commit 2bb2dd4e348ec4fabf0acdd9ba8c06ce1252bb30 +Subproject commit fbceb790848ba37db849ec78dea882565c63d8ca diff --git a/survey/default.nix b/survey/default.nix index 95c115c..023770c 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -719,6 +719,9 @@ let openblas = (previous.openblas.override { enableStatic = true; }); + libusb1 = previous.libusb1.override { withStatic = true; enableUdev = false; }; + libusb-compat-0_1 = previous.libusb-compat-0_1.overrideAttrs (old: { dontDisableStatic = true; }); + openssl = previous.openssl.override { static = true; }; zstd = previous.zstd.override { enableStatic = true; }; @@ -737,14 +740,35 @@ let staticOnly = true; }; - # Brotli can currently build only static or shared libraries, - # see https://github.com/google/brotli/pull/655#issuecomment-864395830 - brotli = previous.brotli.override { staticOnly = true; }; + # For unclear reasons, brotli builds its `.a` files by default, but adds a `-static` + # infix to their names: + # + # libbrotlicommon-static.a + # libbrotlidec-static.a + # libbrotlienc-static.a + # + # Its pkg-config `.pc` file thus does not support static linking. See: + # https://github.com/google/brotli/issues/795#issuecomment-1373595520 + # and + # https://github.com/google/brotli/pull/655#issuecomment-864395830 + # + # In my opinion this is rather pointless, because `.a` files are always "static". + # + # We correct it here by renaming the files accordingly. + brotli = previous.brotli.overrideAttrs (old: { + postInstall = '' + for f in "$lib"/lib/*-static.a; do + ln -s --verbose "$f" "$(dirname "$f")/$(basename "$f" '-static.a').a" + done + ''; + }); # woff2 currently builds against the `brotli` static libs only with a patch # that's enabled by its `static` argument. woff2 = previous.woff2.override { static = true; }; + libnfc = previous.libnfc.override { static = true; }; + # See comments on `statify_curl_including_exe` for the interaction with krb5! # As mentioned in [Packages that cause bootstrap compiler recompilation], we can't # override zlib to have static libs, so we have to pass in `zlib_both` explicitly @@ -890,6 +914,11 @@ let # putting `curl_static` into `libraryPkgconfigDepends` is enough # and the manual modification of `configureFlags` is not necessary. libraryPkgconfigDepends = (old.libraryPkgconfigDepends or []) ++ pkgConfigNixPackages; + # `generic-builder.nix` already adds `pkg-config` as a `nativeBuildInput` + # e.g. if `libraryPkgconfigDepends` is not empty, but if it was, and we + # override it here, it does not notice, so we add `pkg-config` explicitly + # in that case. + buildTools = (old.buildTools or []) ++ [ pkgs.pkg-config ]; }); @@ -1272,6 +1301,13 @@ let [ final.openssl ] "--libs openssl"; + # This one needs `libcrypto` explicitly for reasons not yet investigated. `libpq` should pull it in via `openssl`. + postgresql-migration = + addStaticLinkerFlagsWithPkgconfig + super.postgresql-migration + [ final.openssl final.postgresql ] + "--libs libpq libcrypto"; + xml-to-json = addStaticLinkerFlagsWithPkgconfig super.xml-to-json @@ -1283,6 +1319,12 @@ let # See https://github.com/curl/curl/issues/2775 for an investigation of why. "--libs-only-L --libs-only-l libcurl expat"; + nfc = + addStaticLinkerFlagsWithPkgconfig + super.nfc + [ final.libusb-compat-0_1 final.libusb1 ] + "--libs libusb"; + # This package's dependency `rounded` currently fails its test with a patterm match error. aern2-real = addStaticLinkerFlagsWithPkgconfig @@ -1664,20 +1706,28 @@ in "cuda" # needs `allowUnfree = true`; enabling it gives `unsupported platform for the pure Linux stdenv` "debug" # `regex-base <0.94` on `regex-tdfa-text` "diagrams-builder" # `template-haskell >=2.5 && <2.16` on `size-based` + "diagrams-cairo" # `gtk2hs` bug building `glib`: https://github.com/nh2/static-haskell-nix/issues/4#issuecomment-1634681846 "gloss-examples" # `base >=4.8 && <4.14` on `repa-io` + "gtk-sni-tray" # needs `gi-gtk` which requires `glib` which is problematic "gtk3" # Haskell package `glib` fails with `Ambiguous module name ‘Gtk2HsSetup’: it was found in multiple packages: gtk2hs-buildtools-0.13.8.0 gtk2hs-buildtools-0.13.8.0` - "H" # error: anonymous function at pkgs/applications/science/math/R/default.nix:1:1 called with unexpected argument 'javaSupport', at lib/customisation.nix:69:16 + "H" # error: anonymous fun2rsyHqx27f4EQHEUjWU/libHScipher-aes-0.2.11-CpO2rsyHqx27f4EQHEUjWU.a(gf.o):(.text+0x0): first defined herection at pkgs/applications/science/math/R/default.nix:1:1 called with unexpected argument 'javaSupport', at lib/customisation.nix:69:16 + "hackage-cli" # error: error: multiple definition of `gf_mul'; /nix/store/...-cipher-aes-0.2.11/lib/ghc-9.2.7/x86_64-linux-ghc-9.2.7/cipher-aes-0.2.11-[..]/libHScipher-aes-0.2.11-[..].a(gf.o):(.text+0x0): first defined here "hamilton" # `_gfortran_concat_string` linker error via openblas "hquantlib" # `time >=1.4.0.0 && <1.9.0.0` on `hquantlib-time` "ihaskell" # linker error "LambdaHack" # fails `systemd` dependency erroring on `#include ` "language-puppet" # `base >=4.6 && <4.14, ghc-prim >=0.3 && <0.6` for dependency `protolude` "learn-physics" # needs opengl: `cannot find -lGLU` `-lGL` + "LPFP" # `gtk2hs` bug building `glib`: https://github.com/nh2/static-haskell-nix/issues/4#issuecomment-1634681846 "magico" # undefined reference to `_gfortran_concat_string' + "monomer" # needs `nanovg` which is in this list + "nanovg" # needs opengl: `cannot find -lGLU` `-lGL` "odbc" # `odbcss.h: No such file or directory` + "pango" # `gtk2hs` bug building `glib`: https://github.com/nh2/static-haskell-nix/issues/4#issuecomment-1634681846 "qchas" # `_gfortran_concat_string` linker error via openblas "rhine-gloss" # needs opengl: `cannot find -lGLU` `-lGL` "soxlib" # fails `systemd` dependency erroring on `#include ` + "termonad" # needs `glib` which is problematic ]; inherit normalPkgs; From ce1f7372400e156ebc8d42d1fa2bb3897dd09f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Thu, 13 Jul 2023 19:48:41 +0000 Subject: [PATCH 29/29] Implement suggestion for bazel / rules_haskell From https://github.com/nh2/static-haskell-nix/pull/116#pullrequestreview-1474795596 --- nixpkgs | 2 +- nixpkgs.nix | 4 ++-- survey/default.nix | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/nixpkgs b/nixpkgs index fbceb79..9e49f8f 160000 --- a/nixpkgs +++ b/nixpkgs @@ -1 +1 @@ -Subproject commit fbceb790848ba37db849ec78dea882565c63d8ca +Subproject commit 9e49f8f1f37bc906cda1adb33064c325d760819a diff --git a/nixpkgs.nix b/nixpkgs.nix index 75886cd..5cadc43 100644 --- a/nixpkgs.nix +++ b/nixpkgs.nix @@ -25,5 +25,5 @@ if builtins.getEnv "STATIC_HASKELL_NIX_CI_NIXPKGS_UNSTABLE_BUILD" == "1" if builtins.pathExists ./nixpkgs/pkgs then import ./nixpkgs {} # Pinned nixpkgs version; should be kept up-to-date with our submodule. - # This is nixos-21.11 as of 2021-12-15. - else import (fetchTarball https://github.com/NixOS/nixpkgs/archive/573095944e7c1d58d30fc679c81af63668b54056.tar.gz) {} + # This is nixos-23.05 as of 2023-06-08, with minimal patches currently having open nixpkgs PR (see commits for PR links). + else import (fetchTarball https://github.com/nh2/nixpkgs/archive/9e49f8f1f37bc906cda1adb33064c325d760819a.tar.gz) {} diff --git a/survey/default.nix b/survey/default.nix index 023770c..4c451e4 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -1572,7 +1572,10 @@ let else ghcPackage.override { enableDwarf = false; } ) (ghcPackage: - ghcPackage.override { enableRelocatedStaticLibs = useArchiveFilesForTemplateHaskell; } + ghcPackage.override { + enableRelocatedStaticLibs = useArchiveFilesForTemplateHaskell; + enableShared = !useArchiveFilesForTemplateHaskell; + } ) ];