Unverified Commit b989a6b1 authored by sternenseemann's avatar sternenseemann Committed by GitHub
Browse files

Merge pull request #315167 from NixOS/haskell-updates

haskellPackages: GHC 9.10 fix, infrastructure improvements
parents 1884b01e 50848d12
Loading
Loading
Loading
Loading
+53 −8
Original line number Diff line number Diff line
@@ -927,10 +927,55 @@ that may refer to other Haskell packages' store paths (like libraries and
  documentation). This dramatically reduces the closure size of the resulting
  derivation. Note that the executables are only statically linked against their
  Haskell dependencies, but will still link dynamically against libc, GMP and
other system library dependencies. If dependencies use their Cabal-generated
`Paths_*` module, this may not work as well if GHC's dead code elimination
is unable to remove the references to the dependency's store path that module
contains.
  other system library dependencies.

  If the library being built or its dependencies use their Cabal-generated
  `Paths_*` module, this may not work as well if GHC's dead code elimination is
  unable to remove the references to the dependency's store path that module
  contains. (See [nixpkgs#164630][164630] for more information.)

  Importing the `Paths_*` module may cause builds to fail with this message:

  ```
  error: output '/nix/store/64k8iw0ryz76qpijsnl9v87fb26v28z8-my-haskell-package-1.0.0.0' is not allowed to refer to the following paths:
           /nix/store/5q5s4a07gaz50h04zpfbda8xjs8wrnhg-ghc-9.6.3
  ```

  If that happens, first disable the check for GHC references and rebuild the
  derivation:

  ```nix
  pkgs.haskell.lib.overrideCabal
    (pkgs.haskell.lib.justStaticExecutables my-haskell-package)
    (drv: {
      disallowGhcReference = false;
    })
  ```

  Then use `strings` to determine which libraries are responsible:

  ```
  $ nix-build ...
  $ strings result/bin/my-haskell-binary | grep /nix/store/
  ...
  /nix/store/n7ciwdlg8yyxdhbrgd6yc2d8ypnwpmgq-hs-opentelemetry-sdk-0.0.3.6/bin
  ...
  ```

  Finally, use `remove-references-to` to delete those store paths from the produced output:

  ```nix
  pkgs.haskell.lib.overrideCabal
    (pkgs.haskell.lib.justStaticExecutables my-haskell-package)
    (drv: {
      postInstall = ''
        ${drv.postInstall or ""}
        remove-references-to -t ${pkgs.haskellPackages.hs-opentelemetry-sdk}
      '';
    })
  ```

[164630]: https://github.com/NixOS/nixpkgs/issues/164630

`enableSeparateBinOutput drv`
: Install executables produced by `drv` to a separate `bin` output. This
+8 −0
Original line number Diff line number Diff line
@@ -40,6 +40,14 @@
  before changing the package to `pkgs.stalwart-mail` in
  [`services.stalwart-mail.package`](#opt-services.stalwart-mail.package).

- `haskell.lib.compose.justStaticExecutables` now disallows references to GHC in the
  output by default, to alert users to closure size issues caused by
  [#164630](https://github.com/NixOS/nixpkgs/issues/164630). See ["Packaging
  Helpers" in the Haskell section of the Nixpkgs
  manual](https://nixos.org/manual/nixpkgs/unstable/#haskell-packaging-helpers)
  for information on working around `output '...' is not allowed to refer to
  the following paths` errors caused by this change.

- The `stalwart-mail` module now uses RocksDB as the default storage backend
  for `stateVersion` ≥ 24.11. (It was previously using SQLite for structured
  data and the filesystem for blobs).
+30 −49
Original line number Diff line number Diff line
{ lib, haskellPackages, haskell, removeReferencesTo
{ lib, stdenv, haskellPackages, haskell
# “Plugins” are a fancy way of saying gitit will invoke
# GHC at *runtime*, which in turn makes it pull GHC
# into its runtime closure. Only enable if you really need
@@ -7,55 +7,36 @@
, pluginSupport ? false
}:

# this is similar to what we do with the pandoc executable

let
  plain = haskellPackages.gitit;
  plugins =
    if pluginSupport
    then plain
    else haskell.lib.compose.disableCabalFlag "plugins" plain;
  static = haskell.lib.compose.justStaticExecutables plugins;
  inherit (haskell.lib.compose)
    enableCabalFlag
    disableCabalFlag
    justStaticExecutables
    overrideCabal
  ;

in
  (haskell.lib.compose.overrideCabal (drv: {
    buildTools = (drv.buildTools or []) ++ [ removeReferencesTo ];
  }) static).overrideAttrs (drv: {
  base = (if pluginSupport then enableCabalFlag else disableCabalFlag)
    "plugins"
    haskellPackages.gitit;

    # These libraries are still referenced, because they generate
    # a `Paths_*` module for figuring out their version.
    # The `Paths_*` module is generated by Cabal, and contains the
    # version, but also paths to e.g. the data directories, which
    # lead to a transitive runtime dependency on the whole GHC distribution.
    # This should ideally be fixed in haskellPackages (or even Cabal),
    # but a minimal gitit is important enough to patch it manually.
    disallowedReferences = [
      haskellPackages.pandoc-types
      haskellPackages.HTTP
      haskellPackages.pandoc
      haskellPackages.happstack-server
      haskellPackages.filestore
    ];
  # Removes erroneous references from dead code that GHC can't eliminate
  aarch64DarwinFix = overrideCabal (drv:
    lib.optionalAttrs (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) {
      postInstall = ''
      remove-references-to \
        -t ${haskellPackages.pandoc-types} \
        $out/bin/gitit
      remove-references-to \
        -t ${haskellPackages.HTTP} \
        $out/bin/gitit
      remove-references-to \
        -t ${haskellPackages.pandoc} \
        $out/bin/gitit
      remove-references-to \
        -t ${haskellPackages.happstack-server} \
        $out/bin/gitit
      remove-references-to \
        -t ${haskellPackages.filestore} \
        $out/bin/gitit
        ${drv.postInstall or ""}
        remove-references-to -t ${haskellPackages.HTTP} "$out/bin/gitit"
        remove-references-to -t ${haskellPackages.HTTP} "$out/bin/expireGititCache"
        remove-references-to -t ${haskellPackages.happstack-server} "$out/bin/gitit"
        remove-references-to -t ${haskellPackages.hoauth2} "$out/bin/gitit"
        remove-references-to -t ${haskellPackages.pandoc} "$out/bin/gitit"
        remove-references-to -t ${haskellPackages.pandoc-types} "$out/bin/gitit"
      '';
    });
in

    meta = drv.meta // {
      maintainers = drv.meta.maintainers or []
        ++ [ lib.maintainers.Profpatsch ];
    };
  })
if pluginSupport
then base
else lib.pipe (base.override { ghc-paths = null; }) [
  justStaticExecutables
  aarch64DarwinFix
]
+596 −0

File added.

Preview size limit exceeded, changes collapsed.

+5 −3
Original line number Diff line number Diff line
@@ -177,7 +177,9 @@
          # These cause problems as they're not eliminated by GHC's dead code
          # elimination on aarch64-darwin. (see
          # https://github.com/NixOS/nixpkgs/issues/140774 for details).
          ./Cabal-at-least-3.6-paths-fix-cycle-aarch64-darwin.patch
          (if lib.versionOlder version "9.10"
           then ./Cabal-at-least-3.6-paths-fix-cycle-aarch64-darwin.patch
           else ./Cabal-3.12-paths-fix-cycle-aarch64-darwin.patch)
        ]
        # Prevents passing --hyperlinked-source to haddock. This is a custom
        # workaround as we wait for this to be configurable via userSettings or
@@ -425,8 +427,8 @@ stdenv.mkDerivation ({
    "--disable-large-address-space"
  ] ++ lib.optionals enableDwarf [
    "--enable-dwarf-unwind"
    "--with-libdw-includes=${lib.getDev elfutils}/include"
    "--with-libdw-libraries=${lib.getLib elfutils}/lib"
    "--with-libdw-includes=${lib.getDev targetPackages.elfutils}/include"
    "--with-libdw-libraries=${lib.getLib targetPackages.elfutils}/lib"
  ] ++ lib.optionals targetPlatform.isDarwin [
    # Darwin uses llvm-ar. GHC will try to use `-L` with `ar` when it is `llvm-ar`
    # but it doesn’t currently work because Cabal never uses `-L` on Darwin. See:
Loading