Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cabal-paths patch for ghc 9.2.x #216857

Merged

Conversation

sloane-shark
Copy link
Contributor

@sloane-shark sloane-shark commented Feb 17, 2023

Description of changes

Continuation of #184041

I tweaked the cabal-paths.patch file included for GHC builds (see #140774) to work on the updated Cabal PathsModule code that is used in GHC 9.2.3+.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Copy link
Contributor Author

@sloane-shark sloane-shark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes had been requested on the last version of this PR, #184041

Comment on lines 45 to 46
+ | (splitPath flat_prefix) `isPrefixOf` (splitPath flat_bindir) = True
+ | (splitPath flat_prefix) `isPrefixOf` (splitPath p) = False
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sternenseemann Continuing the review from the last PR, what do you think is the proper fix here? I can't work out why splitPath was included originally (I copied this from the existing cabal-paths.patch file), but I imagine the correct code would be one of the following:

Suggested change
+ | (splitPath flat_prefix) `isPrefixOf` (splitPath flat_bindir) = True
+ | (splitPath flat_prefix) `isPrefixOf` (splitPath p) = False
+ | flat_prefix `isPrefixOf` flat_bindir = True
+ | flat_prefix `isPrefixOf` p = False
Suggested change
+ | (splitPath flat_prefix) `isPrefixOf` (splitPath flat_bindir) = True
+ | (splitPath flat_prefix) `isPrefixOf` (splitPath p) = False
+ | [flat_prefix] `isPrefixOf` (splitPath flat_bindir) = True
+ | [flat_prefix] `isPrefixOf` (splitPath p) = False

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested both of these with ghcid, and the top one seems to work as expected, while the bottom one fails to resolve the "cycle detected" error. I will go ahead and rework it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this with a variation on the top patch, which gets rid of splitPath entirely.

@sloane-shark sloane-shark marked this pull request as draft February 17, 2023 20:23
@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Feb 17, 2023
@sloane-shark
Copy link
Contributor Author

Confirmed that haskell.compilers.{ghc924,ghc925} both build.

jacinda still fails, by way of regex-rure.

I've tried nix run .#haskell.packages.{ghc924,ghc925}.{ormolu,ghcid.bin}, and while both failed, it was for two different reasons, neither related to the error that occurs without the patch.

@sloane-shark sloane-shark marked this pull request as ready for review February 18, 2023 01:03
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Feb 18, 2023
@ofborg ofborg bot requested review from expipiplus1 and guibou February 18, 2023 01:22
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Feb 18, 2023
@sloane-shark sloane-shark changed the title Add cabal-paths patch for ghc 9.2.4 Add cabal-paths patch for ghc 9.2.x Feb 18, 2023
@sloane-shark
Copy link
Contributor Author

Result of nixpkgs-review pr 216857 run on aarch64-darwin 1

55 packages marked as broken and skipped:
  • cedille
  • diagrams-builder
  • emacsPackages.cedille
  • emacsPackages.shm
  • ghostwriter
  • gssdp-tools
  • gssdp_1_6
  • hledger-iadd
  • hyper-haskell-server-with-packages
  • icepeak
  • ldgallery
  • madlang
  • napari
  • nix-delegate
  • nix-linter
  • notcurses
  • petrinizer
  • python310Packages.Nikola
  • python310Packages.arviz
  • python310Packages.augmax
  • python310Packages.batchspawner
  • python310Packages.dalle-mini
  • python310Packages.dockerspawner
  • python310Packages.elegy
  • python310Packages.jupyterhub
  • python310Packages.jupyterhub-ldapauthenticator
  • python310Packages.jupyterhub-systemdspawner
  • python310Packages.jupyterhub-tmpauthenticator
  • python310Packages.n3fit
  • python310Packages.napari
  • python310Packages.napari-npe2
  • python310Packages.oauthenticator
  • python310Packages.pymc
  • python310Packages.treex
  • python310Packages.validphys2
  • python311Packages.Nikola
  • python311Packages.augmax
  • python311Packages.batchspawner
  • python311Packages.dockerspawner
  • python311Packages.jupyterhub
  • python311Packages.jupyterhub-ldapauthenticator
  • python311Packages.jupyterhub-systemdspawner
  • python311Packages.jupyterhub-tmpauthenticator
  • python311Packages.oauthenticator
  • python311Packages.validphys2
  • stack2nix
  • stutter
  • stylish-cabal
  • tamarin-prover
  • taskell
  • tlaps
  • tweet-hs
  • uuagc
  • uusi
  • validphys2
19 packages failed to build:
  • fishPlugins.fishtape_3
  • fishPlugins.fzf-fish
  • gitit
  • hledger-check-fancyassertions
  • jacinda
  • klipper-genconf
  • nix-serve-ng
  • python310Packages.ansible-kernel
  • python310Packages.jupyter-server-mathjax
  • python310Packages.jupyterlab-git
  • python310Packages.nbdime
  • python311Packages.ansible-kernel
  • python311Packages.httpie
  • python311Packages.httpie-ntlm
  • python311Packages.jupyter-server-mathjax
  • python311Packages.jupyterlab-git
  • python311Packages.nbdime
  • spacecookie
  • trenchbroom
179 packages built:
  • actionlint
  • agda
  • alex
  • apksigcopier
  • arion
  • bashblog
  • bench
  • bgnet
  • blucontrol
  • bup
  • cabal-install
  • cabal2nix
  • cabal2nix-unwrapped
  • cachix
  • carp
  • client-ip-echo
  • coursera-dl
  • darcs
  • darcs-to-git
  • dconf2nix
  • dhall
  • dhall-bash
  • dhall-docs
  • dhall-json
  • dhall-lsp-server
  • dhall-nix
  • dhall-nixpkgs
  • dhallPackages.Prelude
  • dhallPackages.dhall-cloudformation
  • dhallPackages.dhall-grafana
  • dhallPackages.dhall-kubernetes
  • dogdns
  • echidna
  • eget
  • elm2nix
  • emacsPackages.agda2-mode
  • emacsPackages.hindent
  • emanote
  • exa
  • fend
  • fffuu
  • fishPlugins.bass
  • fishPlugins.done
  • fishPlugins.fishtape
  • futhark
  • gg-scm
  • ghc
  • ghcid
  • git-annex
  • git-brunch
  • git-ftp
  • git-open
  • glirc
  • gocryptfs
  • hadolint
  • happy
  • haskell-ci
  • haskell-language-server
  • hci
  • hercules-ci-agent
  • hinit
  • hledger
  • hledger-interest
  • hledger-ui
  • hledger-utils (python310Packages.hledger-utils)
  • hledger-web
  • hlint
  • hpack
  • hscolour
  • http-prompt
  • httpie (python310Packages.httpie)
  • idris
  • ihaskell
  • isabelle
  • isabelle-components.isabelle-linter
  • jl
  • jo
  • json2yaml
  • jupyter
  • koka
  • krank
  • lambdabot
  • ledger-autosync
  • lhs2tex
  • lsd
  • matterhorn
  • memo
  • mp3fs
  • mpdcron
  • mueval
  • naproche
  • niv
  • nix-deploy
  • nix-diff
  • nix-info-tested
  • nix-output-monitor
  • nix-script
  • nix-tree
  • nixfmt
  • nominatim
  • nota
  • nvfetcher
  • ormolu
  • osmium-tool
  • ov
  • pandoc
  • passExtensions.pass-checkup
  • pinboard-notes-backup
  • place-cursor-at
  • pretty-simple
  • purenix
  • python310Packages.einops
  • python310Packages.git-annex-adapter
  • python310Packages.httpie-ntlm
  • python310Packages.jupyter
  • python310Packages.jupyter-lsp
  • python310Packages.jupyter-server
  • python310Packages.jupyterlab
  • python310Packages.jupyterlab-lsp
  • python310Packages.jupyterlab_launcher
  • python310Packages.jupyterlab_server
  • python310Packages.jupytext
  • python310Packages.mkdocs-jupyter
  • python310Packages.nbclassic
  • python310Packages.nix-kernel
  • python310Packages.notebook
  • python310Packages.notebook-shim
  • python310Packages.notedown
  • python310Packages.pelican
  • python310Packages.phik
  • python310Packages.pymoo
  • python310Packages.pypandoc
  • python310Packages.pytm
  • python310Packages.pytomlpp
  • python310Packages.reportengine
  • python310Packages.vector
  • python310Packages.vega
  • python310Packages.xarray-einstats
  • python311Packages.einops
  • python311Packages.git-annex-adapter
  • python311Packages.hledger-utils
  • python311Packages.jupyter
  • python311Packages.jupyter-lsp
  • python311Packages.jupyter-server
  • python311Packages.jupyterlab
  • python311Packages.jupyterlab-lsp
  • python311Packages.jupyterlab_launcher
  • python311Packages.jupyterlab_server
  • python311Packages.jupytext
  • python311Packages.mkdocs-jupyter
  • python311Packages.nbclassic
  • python311Packages.nix-kernel
  • python311Packages.notebook
  • python311Packages.notebook-shim
  • python311Packages.notedown
  • python311Packages.pelican
  • python311Packages.pypandoc
  • python311Packages.pytm
  • python311Packages.pytomlpp
  • python311Packages.reportengine
  • python311Packages.vega
  • ripgrep-all
  • scriv
  • shake
  • shellcheck
  • splot
  • stack
  • stylish-haskell
  • tldr-hs
  • update-nix-fetchgit
  • vaultenv
  • vimPlugins.cmp-pandoc-nvim
  • vimPlugins.vim-stylish-haskell
  • vscode-extensions.timonwong.shellcheck
  • wayback-machine-archiver
  • wstunnel
  • xmonad-with-packages
  • xmonadctl
  • zsh-git-prompt

@sloane-shark
Copy link
Contributor Author

sloane-shark commented Feb 19, 2023

@srid @domenkozar if either of you has an x86_64-darwin machine to test this PR, I think that would help make it a bit more convincing for merging. maybe nixpkgs-review, but primarily running ormolu or ghcid.

for reference, when I try to run ghcid on my aarch64-darwin machine, I get this failure:

❯ nix run .#haskell.packages.ghc924.ghcid.bin
Loading ghci -fno-code -fno-break-on-exception -fno-break-on-error -v1 -ferror-spans -j ...
GHCi, version 9.2.4: https://www.haskell.org/ghc/  :? for help

No files loaded, GHCi is not working properly.
Command: ghci -fno-code -fno-break-on-exception -fno-break-on-error -v1 -ferror-spans -j

can't tell if this is due to the patch, or some unrelated issue.

@sloane-shark
Copy link
Contributor Author

sloane-shark commented Feb 19, 2023

another strange error for ormolu:

❯ nix run .#haskell.packages.ghc924.ormolu
error: unable to execute '/nix/store/1y4bg6lk0qqlrpqhnxw1j83bgw5c2rds-ormolu-0.5.0.1/bin/ormolu': No such file or directory

❯ ls /nix/store/1y4bg6lk0qqlrpqhnxw1j83bgw5c2rds-ormolu-0.5.0.1/
lib  nix-support

@sternenseemann
Copy link
Member

I think we can actually make it even simple, I'll try to come up with an alternative patch and a way to test this that doesn't require rebuilding GHC everytime which will probably come in handy.

@sternenseemann
Copy link
Member

sternenseemann commented Feb 28, 2023

@matthewess What do you think of this? I tried moving all code generation logic into the Template, so that only the decision whether stuff is emitted or not (and the generation of the warning text) is left in the PathsModule module. This way the amount of weird code in there is limited and things are hopefully a bit clearer or easier to understand thanks to the separation.

For testing I have the following Nix expression which uses my local working copy of Cabal and injects it into setupHaskellDepends. The patched version takes precedence over the bundled one. The project in ./. is just a simple example usage of Paths_*. Could be polished a bit more with expected failures etc. which may be interesting for porting that as a test to nixpkgs.

{ pkgs ? import <nixpkgs> { } }:

let
  inherit (pkgs) haskellPackages lib;
  Cabal = haskellPackages.callCabal2nix "Cabal.cabal.nix" ~/src/hs/ghc/libraries/Cabal/Cabal { };

in
haskellPackages.mkDerivation {
  pname = "paths-test";
  version = "0";
  src = ./.;
  setupHaskellDepends = [ Cabal ];
  license = lib.licenses.bsd3;
  # Change these to make the patch do something
  enableSeparateDataOutput = false;
  enableSeparateBinOutput = false;
}

@sloane-shark
Copy link
Contributor Author

@sternenseemann that looks very clean! i can try and work those changes into this PR this weekend

@sternenseemann
Copy link
Member

@matthewess If you want, I can take that off your hands; then I'd just need your help with reviewing and testing (since I lack the hardware).

@sternenseemann
Copy link
Member

@ofborg build haskell.compiler.ghc927 haskell.compiler.ghc926

For anyone reviewing, viewing the patch this way may be easier.

@sternenseemann
Copy link
Member

@ofborg build haskell.compiler.ghc927 haskell.compiler.ghc926

@Kranzes
Copy link
Member

Kranzes commented Mar 10, 2023

What's the current situation on this PR? This is a pretty major blocker for many users. It seems that ofborg build failed with a timeout?

@sternenseemann
Copy link
Member

Needs to be tested still. I think it's okay, but would be preferable if someone else could also review the actual code.

@sloane-shark
Copy link
Contributor Author

Playing around with this today. Are there any good test candidates besides making sure that e.g. ormolu and ghcid will run?

@sternenseemann
Copy link
Member

@matthewess plus niv, nfc and citeproc

Copy link
Member

@maralorn maralorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot claim that I have understood this change in full depth. Especially since I hadn’t looked at the Cabal code base before.

Still, this change is well documented, and the code looks like it does what the comment says. Also, to prove that I really read it, I found a subtle typo.

@sloane-shark
Copy link
Contributor Author

The following commands worked for me on aarch64-darwin:

❯ nix run .#haskell.packages.ghc924.ormolu.bin
❯ nix run .#haskell.packages.ghc924.ghcid.bin -- --help
❯ nix run .#haskell.packages.ghc924.niv.bin
❯ nix run .#haskell.packages.ghc924.citeproc.bin -- --help

attempting to run haskell.packages.ghc924.nfc[.bin] threw an error, and when I inspected the nix store folder, I saw the same no-bin contents as here: #216857 (comment)

@sternenseemann
Copy link
Member

@matthewess The thing for ormolu is to be expected as you were not actually looking at the bin output when listing the store path. Not sure why nix run misbehaves here, no experience with the flakes CLI's behavior.

Due to link time dead code elimination not working on aarch64-darwin,
some unused store path references in Paths_* modules are retained. This
causes reference cycles when a separate `bin` output is used.

To prevent this, add a patch to Cabal as shipped by GHC which infers
based on the installation layout (which is influenced by
enableSeparateBinOutput, enableSeparateDataOutput etc. in a Nix build)
which references can be retained without causing a reference cycle. This
ensures that packages that were fine with a bin output will also work on
aarch64-darwin. Packages that cause a reference cycle anyways (by
actually using references that do cause one) fail due to a missing
symbol – here we are trading the overall benefit for a more confusing
error message.

For details, refer to the explanation comment in the patch.
@ofborg ofborg bot requested a review from maralorn March 10, 2023 23:57
@sloane-shark
Copy link
Contributor Author

@matthewess The thing for ormolu is to be expected as you were not actually looking at the bin output when listing the store path. Not sure why nix run misbehaves here, no experience with the flakes CLI's behavior.

Good catch, you can see I figured that out for ormolu but I messed up with nfc. I think it must only have one oddly named binary?

❯ nix run .#haskell.packages.ghc924.nfc.bin
error: unable to execute '/nix/store/pd62xcxz72g335axy6872002fihq9qp1-nfc-0.1.1-bin/bin/nfc': No such file or directory

❯ ls /nix/store/pd62xcxz72g335axy6872002fihq9qp1-nfc-0.1.1-bin/bin/
print-mifare-uid-forever

@sternenseemann
Copy link
Member

@matthewess So GHC is still working on aarch64-darwin? Should we merge?

@sloane-shark
Copy link
Contributor Author

@matthewess So GHC is still working on aarch64-darwin? Should we merge?

Yes, GHC is working! My somewhat informed opinion on merging is also yes. I'm no Haskell maintainer, but this seems to fix the symptom that prompted the original PR well, and your changes set us up better to adjust it in the future if something ends up being amiss.

@sternenseemann sternenseemann merged commit 45aae5c into NixOS:master Mar 11, 2023
sternenseemann added a commit to mpscholten/nixpkgs that referenced this pull request Dec 12, 2023
This ports our infamous patch for `Cabal` which cheesily prevents an
output cycle for derivations that use separate bin outputs where
references caused by the `Paths_*` module can't be eliminated by the GHC
aarch64-darwin codegen backend.

See also

- the original issue NixOS#140774,
- the original patch for GHC 9.2 NixOS#216857
- the ported patch for GHC 9.4
  NixOS@f6f780f

Co-authored-by: sternenseemann <sternenseemann@systemli.org>
sternenseemann added a commit that referenced this pull request Dec 12, 2023
This ports our infamous patch for `Cabal` which cheesily prevents an
output cycle for derivations that use separate bin outputs where
references caused by the `Paths_*` module can't be eliminated by the GHC
aarch64-darwin codegen backend.

See also

- the original issue #140774,
- the original patch for GHC 9.2 #216857
- the ported patch for GHC 9.4
  f6f780f

Co-authored-by: sternenseemann <sternenseemann@systemli.org>
sternenseemann added a commit that referenced this pull request May 31, 2024
This ports our infamous patch for Cabal that prevents certain parts of
the Paths_* module from being generated in order to prevent unnecessary
references on aarch64-darwin, to GHC >= 9.10.

See also:

- Original issues: #140774
- Patches
  - Original patch for GHC >= 8.10 && < 9.2 / Cabal >= 3.2 && < 3.6:
    b0dcd7f
  - Patch for GHC >= 9.2 && < 9.10 / Cabal >= 3.6 && < 3.12: #216857,
    f6f780f129f50df536fb30,
    …
github-actions bot pushed a commit that referenced this pull request May 31, 2024
This ports our infamous patch for Cabal that prevents certain parts of
the Paths_* module from being generated in order to prevent unnecessary
references on aarch64-darwin, to GHC >= 9.10.

See also:

- Original issues: #140774
- Patches
  - Original patch for GHC >= 8.10 && < 9.2 / Cabal >= 3.2 && < 3.6:
    b0dcd7f
  - Patch for GHC >= 9.2 && < 9.10 / Cabal >= 3.6 && < 3.12: #216857,
    f6f780f129f50df536fb30,
    …

(cherry picked from commit 3885dfe)
sternenseemann added a commit that referenced this pull request Jun 8, 2024
This ports our infamous patch for Cabal that prevents certain parts of
the Paths_* module from being generated in order to prevent unnecessary
references on aarch64-darwin, to GHC >= 9.10.

See also:

- Original issues: #140774
- Patches
  - Original patch for GHC >= 8.10 && < 9.2 / Cabal >= 3.2 && < 3.6:
    b0dcd7f
  - Patch for GHC >= 9.2 && < 9.10 / Cabal >= 3.6 && < 3.12: #216857,
    f6f780f129f50df536fb30,
    …

(cherry picked from commit 3885dfe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: haskell 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants