Commit Graph

88 Commits

Author SHA1 Message Date
Aliaksandr
35ce861650 ghcWithPackages: throw on non-derivation inputs
Previously the user-supplied package list was passed directly through
`lib.closePropagation` and an `isHaskellLibrary`-attribute filter, so
mistakes such as `[ dontCheck hp.foo ]` (forgetting parentheses around
the override) silently produced a GHC environment with the affected
package missing instead of failing.

Validate each top-level entry up front. We deliberately accept any
derivation (not just Haskell libraries), because shellFor passes
mixed inputs like `libraryFrameworkDepends` through here on Darwin;
those are still silently dropped by the existing closure-side filter.
The user-error case the issue is about -- non-derivation values like
functions or strings -- is now rejected with a helpful message that
points at the canonical fix.

Fixes #30304

Assisted-by: claude-code with claude-opus-4-8[1m]-high
2026-06-16 18:47:38 +03:00
sternenseemann
3bd7971889 haskell.compiler.ghc{948,967,984,9102,9103,9121,9122}: backport patches for LLVM support (#440774) 2025-10-18 23:05:44 +00:00
Emily
b6be8a03a7 haskell.compiler.ghc{948,967,984,9102,9103,9121,9122}: backport patches for LLVM support
LLVM 12–17 have been dropped for Nixpkgs 25.11. As discussed recently
on Matrix, this backports upstream changes to allow the use of
LLVM 20 for all GHC versions from 9.4.8 onward.

I looked over GHC commits mentioning LLVM since the release of 9.4.8,
and read the discussions and issues around the relevant bumps, and
attempted to be quite thorough, but I obviously cannot guarantee that
this is wholly comprehensive. It seems like upstream generally bumps
the upper bound on the basis of “it builds successfully for me”,
with specific adaptations for new versions being fairly uncommon and
only coming for obvious build blockers or reactively in response to
bug reports. I have backported both kinds of changes here.

For some commits, trivial conflict resolutions and adaptations
were required. It would be possible to pass the affected files to
`fetchpatch` as `excludes` and keep smaller fix‐up patches in tree in
some cases, but I opted to keep it simple and vendor complete backport
patches instead. I did not attempt to backport every single change to
the LLVM backend, only those that seemed directly relevant to support
for newer versions; if you’d get the same issue with the older LLVM,
that’s just a GHC bug.

These changes should actually make it easier to cross‐compile for
new architectures, as more recent LLVMs will have better support for
newer platforms, and it will be easier to backport GHC changes to
enable new platforms with less drift in the backend.

These patches do result in two breaking changes. Firstly, the minimum
LLVM version is bumped to 13 across the board. This is irrelevant for
Nixpkgs as we pin a specific LLVM version anyway, and versions below
LLVM 18 will be removed imminently. Secondly, support for the hidden
`-fno-llvm-tbaa` flag is dropped. This can be replaced with custom
`-optlo` flags to control the passes more directly, but the main
use of this undocumented flag appears to have been to [work around]
the lack of support for newer LLVM versions, anyway.

[work around]: <https://gitlab.haskell.org/ghc/ghc/-/issues/22220>

I successfully built the following on `aarch64-linux`:

* `pkgsCross.armv7l-hf-multiplatform.buildPackages.haskell.compiler.ghc948`
* `pkgsCross.armv7l-hf-multiplatform.buildPackages.haskell.compiler.ghc967`
* `pkgsCross.armv7l-hf-multiplatform.buildPackages.haskell.compiler.ghc984`
* `pkgsCross.armv7l-hf-multiplatform.buildPackages.haskell.compiler.ghc9102`
* `pkgsCross.armv7l-hf-multiplatform.buildPackages.haskell.compiler.ghc9121`
* `pkgsCross.armv7l-hf-multiplatform.buildPackages.haskell.compiler.ghc9122`
* `pkgsCross.riscv64.haskell.compiler.ghc948`

The GHC 9.4.8 with an ARMv7 host platform segfaults when I try to run
GHC, though e.g. `ghc-pkg --help` runs successfully. The GHC 9.10.3
build targeting ARMv7 crashed inside `llc(1)`, so I tried RISC‐V,
which has some platform mismatch issue relating to `libffi`, so I
tried z/Architecture, which failed with an invalid floating point
constant in the LLVM IR, so I tried 64‐bit MIPS, which failed with
a different `libffi` issue, so I tried 32‐bit MIPS, which failed
to compile `compiler-rt`, so I gave up. I confirmed that both of the
ARMv7 issues reproduce with 944e8fd4f4,
the revision before they were bumped from their old versions of LLVM,
so these are not regressions.

I built a test program with the ARMv7 cross‐compilers and
confirmed that they run on the AArch64 builder. I also confirmed
that the cross‐compiled RISC‐V GHC successfully runs under
`qemu-riscv64(1)`. It will only try to build programs via the C
backend, though, as that is the only option for unregisterised™
targets, so it’s not clear to me how useful LLVM support in 9.4.8
really is for bootstrapping new platforms; I guess even RISC‐V
would require more backporting work to produce a cross‐compiled
GHC that will use LLVM to compile its own input. I didn’t bother
setting up all the binfmt machinery to get it through compiling and
running a test program, but it at least makes the attempt.
2025-10-15 16:25:12 +01:00
nixpkgs-ci[bot]
99bf2f7c42 Merge 0832d1b3a0 into haskell-updates 2025-10-05 00:22:14 +00:00
NAHO
c8d4dabc43 pkgs: remove optional builtins prefixes from prelude functions
Remove optional builtins prefixes from prelude functions by running:

    builtins=(
      abort
      baseNameOf
      break
      derivation
      derivationStrict
      dirOf
      false
      fetchGit
      fetchMercurial
      fetchTarball
      fetchTree
      fromTOML
      import
      isNull
      map
      null
      placeholder
      removeAttrs
      scopedImport
      throw
      toString
      true
    )

    fd \
      --type file \
      . \
      pkgs \
      --exec-batch sed --in-place --regexp-extended "
        s/\<builtins\.($(
          printf '%s\n' "${builtins[@]}" |
            paste --delimiter '|' --serial -
        ))\>/\1/g
      "

    nix fmt
2025-10-04 19:02:37 +02:00
sternenseemann
b7c88f16f4 ghcWithPackages: make krank ignore informational issue references 2025-09-26 14:17:29 +02:00
Emily
ac290135ea haskell.compiler.ghc{948,963,967,984,9101,9102,9121,9122}: bump LLVM
Bump the LLVM version used by our GHC packages in preparation for
the LLVM drops. This breaks the LLVM backend; it will be fixed soon
by backporting patches, but that will require a mass rebuild.
2025-09-14 19:03:24 +01:00
sternenseemann
a2b6624139 {forceLlvmCodegenBackend,ghcWithPackages}: update clang -fllvm logic
- The LLVM backend always needs an LLVM specific assembler, i.e. clang
  that ideally matches the version of LLVM actually used for codegen.

- The LLVM backend on Darwin requires some version of clang to be
  available. In light of LLVMAS, using a matching version seems to be
  best though this does risk messing with clang used for compiling C
  in the derivation.

  This mess can be avoided by compiling GHC with useLLVM = true which
  sets absolute paths in GHC's settings file. Due to closure size
  constraints, we can't really do that if NCG is available.
2025-09-11 15:45:26 +02:00
Emily
921f5db298 haskellPackages.llvmPackages: drop
There’s no sensible notion of a Haskell package set’s LLVM, only a
GHC’s LLVM. `haskellPackages.ghc.llvmPackages` is still accessible,
although you probably don’t actually want to use it very often.

Co-authored-by: sternenseemann <sternenseemann@systemli.org>
2025-09-11 15:13:56 +02:00
sternenseemann
de1e068b1f ghcWithPackages: expose targetPrefix 2025-09-09 15:46:34 +02:00
sternenseemann
7b5b5fe515 treewide: drop GHCJS specific code
This affects haskelPackages.mkDerivation, ghcWithPackages and
hoogleWithPackages which means that it is not possible to re-introduce
a ghcjs derivation downstream and create a ghcjs package set with an up
to date Nixpkgs.
2025-09-06 14:56:31 +02:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Rebecca Turner
c2ffd1f4a8 haskell.packages.*.ghcWithPackages: Fix on darwin
Previously, `ghcWithPackages` would fail to build on macOS because
package `.conf` files now contain a literal `${pkgroot}` (which of
course does not exist):

```
$ grep -Poz "dynamic-library-dirs:\s*\K .+\n" /nix/store/s5xrmb3583fd5qjrqsg73fblaq46gqpd-ghc-9.10.1-with-packages/lib/ghc-9.10.1/lib/package.conf.d/*
...
/nix/store/s5xrmb3583fd5qjrqsg73fblaq46gqpd-ghc-9.10.1-with-packages/lib/ghc-9.10.1/lib/package.conf.d/unix-2.8.5.1-ce1b.conf.copy: ${pkgroot}/../lib/aarch64-osx-ghc-9.10.1
...
```

Therefore, we use `ghc-pkg --simple-output list` to get a list of
`.conf` files and `ghc-pkg --simple-output field "$pkg"
dynamic-library-dirs` to get the value of the field while expanding
`${pkgroot}` prefixes.
2025-06-10 10:36:07 -07:00
KireinaHoro
f6c188fd6a use find to locate dylib to link 2025-05-28 15:52:48 +02:00
Rebecca Turner
03c44317c8 haskellPackages.ghcWithHoogle: add passthru.hoogle
Package sets built with `haskellPackages.ghcWithHoogle` provide a Hoogle
executable which points to a Hoogle database, but there's no way to
programmatically access the derivation containing the Hoogle database
from the package set.

This adds a `passthru.hoogle` attribute to package sets built with
`haskellPackages.ghcWithHoogle`, and a `passthru.database` helper to
derivations built with `haskellPackages.hoogleWithPackages`.
2025-05-01 16:19:22 -07:00
Silvan Mosberger
4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00
Wolfgang Walther
eb56edbce0 haskellPackages.mkDerivation: remove version checks for unsupported GHC
Most of the version checks for GHC can be removed, because they target versions
which are not part of nixpkgs anymore.
2024-02-08 14:39:02 +01:00
Ian-Woo Kim
77504c6a1e ghcWithPackages: Fix a sed bug in patching package conf file
When making ghcWithPackages, haskell package db configuration
is modified by sed, but newlines are not handled properly, so
resulting in
```
dynamic-library-dirs: ${pkgroot}/../lib/aarch64-osx-ghc-9.6.1
data-dir:
    ${pkgroot}/../share/aarch64-osx-ghc-9.6.1/filepath-1.4.100.1
```
is replaced like (data-dir: is swallowed)
```
dynamic-library-dirs:
    /nix/store/zxmwvns8zg4ff47vw9hqgazjkiqa26kv-ghc-9.6.1-with-packages/lib/links
    ${pkgroot}/../share/aarch64-osx-ghc-9.6.1/filepath-1.4.100.1
```
This fixes the bug.
2023-06-14 10:14:57 -07:00
Ian-Woo Kim
b1600b5672 ghcWithPackages: handle the boot dylib links separately for GHC 9.6
From GHC 9.6 on, the boot libraries (dependencies of the ghc library) are
present in a separate directory after the installation, and thus the
wrapper environment provided by ghcWithPackages needs to handle the links
to the boot dynamic libraries separately than other ordinary ones.
2023-06-14 10:04:56 -07:00
sternenseemann
5318038186 haskellPackages.ghcWithPackages: fix whitespace alignment 2023-02-05 14:01:25 +01:00
sternenseemann
f45f7cb3e0 haskellPackages: support hadrian libdir layout 2023-02-05 14:01:25 +01:00
sternenseemann
e75c36d055 haskellPackages.ghcWithPackages: suppport ghcs without doc output
This is the case for all bindist-based GHC derivations.
2023-01-22 13:02:18 +01:00
maralorn
0d88794d58 Merge pull request #210762 from sternenseemann/nix-ghc-docdir
ghc.withPackages: install documentation to -with-packages output
2023-01-15 19:38:56 +01:00
sternenseemann
727491cd95 ghc.withPackages: install documentation to -with-packages output
* Will make it so that GHC.Paths's docdir NIX_GHC_DOCDIR points to an
  actual directory.

* Documentation of all packages in the environment is available in
  `$out/share/doc`.

This has previously been attempted in #76842 and reverted in #77442,
since documentation can collide when the libraries wouldn't (thanks to
the hash in the lib filename). `symlinkJoin` allows collision, so this
solution should be akin to #77523 (minus `buildEnv`, one step at a
time). `installDocumentation = false` restores the old behavior.

Collision in the documentation only happen if the dependency closure of
the given packages has more than one different derivation for the same
library of the very same version. I'm personally inclined not to claim
that our infrastructure does anything sensible in this case.
Additionally, the documentation is likely largely the same in such
cases (unless it is heavily patched).

Resolves #150666.
Resolves #76837.
Closes #150968.
Closes #77523.
2023-01-15 17:35:42 +01:00
sternenseemann
af3e04d3f6 ghc.withPackages: set preferLocalBuild in the correct place 2023-01-14 22:37:52 +01:00
sternenseemann
456faf71e5 ghcWithPackages: use haskellCompilerName for ghclibdir
This is done for consistency with generic-builder.nix and because it's
easier for downstream users to replicate which will inevitably use our
code as inspiration.
2022-03-31 12:50:43 +02:00
sternenseemann
383fbfadcc ghcWithPackages: use packageCfgDir over ghc.name where appropriate
This is an incorrectness pointed out in #153319 which we already have
a proper solution for.
2022-03-31 12:37:00 +02:00
sternenseemann
8c27f7a2bd haskellPackages.ghcWithPackages: throw on old override interface
Adding a fake override function via passthru will at least give users of
the old override interface a more helpful error message. Additionally we
also document the changes in the changelog.
2022-02-08 13:28:30 +01:00
sternenseemann
fb075fab73 haskellPackages.{ghcWithPackages, ghcWithHoogle}: make overrideable
This is achieved by passing the entire package set to the respective
wrappers and passing the select function as a second attribute. Together
with the new support for callPackage-ing functions this allows for
things like `ghcWithPackages.override { useLLVM = true; } (p: [ … ])`.

To make this possible for `ghcWithHoogle` as well, we need to make the
wrapper a bit more bespoke and inline the hoogle feature as well. The
hoogle wrapper, however, can remain separate and is exposed as
`hoogleWithPackages` additionally, as it can also serve standalone use.
`hoogleLocal` is kept for backwards compatibility (including the old,
suboptimal API), but will inform users about the better alternative via
a warning.
2022-01-06 12:21:45 +01:00
sternenseemann
f662c8be61 ghcWithPackages: remove check for GHC >= 6.12
It's been quite a while since any version below that has been in use in
nixpkgs, so this check is almost certainly safe to remove.
2022-01-06 12:21:45 +01:00
sternenseemann
50f256f5ef ghcWithPackages: don't wrap GHC with LLVM unnecessarily
Since GHC now will have LLVM available when needed, we don't need to add
it in the wrapper anymore. It can still be added if NCG is available,
but -fllvm should be used (e. g. to work around an NCG bug).
2021-11-25 19:28:57 +01:00
sternenseemann
c32095b400 ghcWithPackages: rename withLLVM to useLLVM
useLLVM is what we are using in the GHC derivations already -- for
better or for worse -- so we should rename the argument here for
consistency which we are free to do as this is purely internal at the
moment (with overriding being impossible).
2021-11-24 10:21:39 +01:00
sternenseemann
2f98c1824c ghcWithPackages: GHC 8.10.7 still needs LLVM for aarch64-darwin
This check was wrong and caused by a bit of confusion on my part.
GHC >= 8.10.5 && < 9 supports aarch64-darwin via LLVM and GHC >= 9.2.1
introduces the NCG backend for aarch64-darwin.
2021-11-23 16:01:45 +01:00
sternenseemann
571f3e504b ghcWithPackages: list missing targets with NCG available
Based on https://gitlab.haskell.org/ghc/ghc/-/wikis/platforms, although
it sadly doesn't list when the backends were introduced.

* PowerPC, x86 (and x86_64) and Sparc have been supported for longer.

* aarch64-darwin is new in 9.2.1 and backported to 8.10.5, 8.10.6 and
  8.10.7 (check is dumb here since we'll grep for 8.10.7 anyways when
  upgrading)

Fixes ghcWithPackages failing to evaluate on aarch64-darwin because of
missing support for the platform in LLVM 9's compiler-rt.
2021-11-18 16:33:51 +01:00
sternenseemann
cfdc073da4 ghcWithPackages: check targetPlatform to decide if NCG is available
The availability of native codegen (which allows us to disable the LLVM
backend by default) hinges on the target platform of the compiler (that
is GHC), not on the platform it runs on (the host platform).
2021-11-18 16:33:51 +01:00
sternenseemann
9a2e728831 ghcWithPackages: set withLLVM if hostPlatform is not x86_64
We also don't add LLVM on PowerPC as GHC should have the ability to
generate native code for that platform itself.

Resolves #116235.
2021-05-03 10:42:52 +02:00
John Ericson
07ecf87693 treewide: Fix various tools wrappers "with packages"
Now that `buildEnv` is ready, always put `makeWrapper` in
`nativeBuildInputs`, rather than `buildInputs` or (worse) mucking around
with setup hooks by hand.

(C.f. #112276, which didn't catch these because the manual setup hook
sourcing is such a hack to being with!)

Fixes #114687
2021-03-02 22:38:04 +00:00
Malte Brandy
ae73fa0d56 haskellPackages.ghc.withPackages: Remove obsolete ghcide wrapper 2020-09-18 21:50:29 +02:00
Malte Brandy
af017c431a haskellPackages.haskell-language-server: 0.2.0 -> 0.3.0
While we are at it I:
* Disable tests, because I can‘t keep up with the speed hls introduces
more tests that cause trouble in nixpkgs.
* Fix builds of fourmolu and retrie
* Remove the wrapper for hls which is obsolete because of improved
package detection in hie-bios. And added a note that this can be removed
for ghcide soon, too.
2020-08-16 13:57:18 +02:00
Malte Brandy
ac8c823955 ghc.withPackages: Wrap hls with package lookup env 2020-07-24 13:02:55 +02:00
Malte Brandy
4e67e3da06 ghc.withPackages: Add wrapper for ghcide 2020-06-05 21:58:25 +02:00
Soares Chen
32d2de8e00 haskell: Fix with-packages-wrapper MacOS linker hack for GHC 8.8
`with-packages-wrapper.nix` has a hack to workaround the linker limit
in MacOS Sierra. However that is now broken with GHC 8.8, because of
slight change in the format of the package config.
In short, the package config produced by GHC 8.8 has a new line between
the key and list of values, while earlier versions have them separated
by a single space.

This PR fixes the linker hack by modifying the `grep` and `sed` commands
to pattern match on either space or new line, so that the hack can work
on all versions of GHC.
2020-05-29 22:28:47 +02:00
Guillaume Bouchard
abc4f961b4 haskellPackages.ghcWithPackages: fix for GHC 8.10
This closes #79441.

ghcWithPackages is using `ghc-pkg recache` to build its package
database. By doing so, it overrides the `package.cache[.lock]` files.

Details are unclear, but GHC 8.10 changed a bit the behavior.
Previously, it was unconditionally replacing the files by new ones. Now
it tries to open (for modification) the files. These files are symlinks
to another nix derivation, which is hence read-only.

This commit removes the files before running `ghc-pkg recache`, hence it
will just write the new files.

Tested with `haskellPackages.ghcWithPackages` (i.e. GHC 8.8) and
`haskell.packages.ghc8101.ghcWithPackages` (i.e GHC 8.10) with the
following nix file, at the root of the nixpkgs repository:

```
with import ./. {
  overlays = [
    (
      self: super: {
        haskellPackages = super.haskell.packages.ghc8101.override {
          overrides = selfh: superh: {
             th-lift-instances = super.haskell.lib.doJailbreak superh.th-lift-instances;
             th-expand-syns    = super.haskell.lib.doJailbreak superh.th-expand-syns;
             th-reify-many     = super.haskell.lib.doJailbreak superh.th-reify-many;
             th-orphans        = super.haskell.lib.doJailbreak superh.th-orphans;
             haskell-src-meta  = super.haskell.lib.doJailbreak superh.haskell-src-meta;
          };
        };
      }
  )
  ];
};
haskellPackages.ghcWithPackages(p:[p.PyF])
```

This will test with GHC 8.10. Comment out the `overlays` to test with
GHC 8.8.
2020-04-17 20:50:48 +02:00
Peter Simons
4a2aad0d39 Revert "haskell/with-packages-wrapper.nix: install "doc" outputs" 2020-01-10 15:20:08 +01:00
Matthew Bauer
93aabab760 haskell/with-packages-wrapper.nix: remove /bin symlink if it exists
The wrapper need a writable directory to work, so remove the symlink
to a read-only one if it occurs.
2020-01-06 18:25:50 -05:00
Matthew Bauer
e915608618 haskell/with-packages-wrapper.nix: install "doc" outputs
We were previously just installing the "out" output which broke when
we recently changed to generating multiple outputs.

Fixes #76837
2020-01-02 16:12:46 -05:00
John Ericson
0828e2d8c3 treewide: Remove usage of remaining redundant platform compatability stuff
Want to get this out of here for 18.09, so it can be deprecated
thereafter.
2018-08-30 17:20:32 -04:00
Matthew Bauer
e01db49bfa ghcjs-ng: Move to $out/lib/ghcjs-8.4
This is standard for ghc compilers & much more convenient. This seems
to fix the issues we have been having in ghcjs pkgs.

Fixes #42032
Fixes #42617
2018-06-26 17:43:58 -04:00
Matthew Bauer
34f57ac837 haskell: fix with-packages-wrapper in ghcjs
Fixes #42032
Fixes #42070
2018-06-18 20:17:06 -04:00
Sarah Brofeldt
2956cc8760 haskellPackages.ghcWithPackages: Wrap haddock with GHC lib dir 2018-03-15 20:16:54 +01:00