NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.99k stars 14.01k forks source link

haskell: Setup register refuses to install a library that includes a plugin in its cabal files' ghc-options #341196

Closed MangoIV closed 1 month ago

MangoIV commented 1 month ago

Describe the bug

when trying to build a library which depends on a plugin, the installPhase fails when calling Setup register with the following problem:

> Installing library in /nix/store/2y5x510ipfswl631ygbbz1l8y08cl6c4-reproducer-0.1.0.0/lib/ghc-9.8.2/lib/x86_64-linux-ghc-9.8.2/reproducer-0.1.0.0-GVHWldQUbsi1fhUKDcLu7H
> Error: Setup: '/nix/store/ckjnjsfhghla0bzw7pgxg6rxcrcxarhv-ghc-9.8.2/bin/ghc'
> exited with an error:
> <command line>: Could not find module ‘Polysemy.Plugin’.
> Use -v to see a list of the files searched for.

Steps To Reproduce

here's a reproducer, just run nix build .#reproducer https://github.com/MangoIV/nixpkgs-plugin-reproducer

Expected behavior

two different possibilities:

  1. cabal doesn't require a plugin in Setup register
  2. make the plugin available to Setup register

Additional context

  1. the bug is ghc 9.8 specific, it does not reproduce with ghc 9.6
  2. the bug is nixpkgs specific, it does not reproduce with plain cabal
  3. adding
    export NIX_GHC_PACKAGE_PATH_FOR_TEST="''${NIX_GHC_PACKAGE_PATH_FOR_TEST:-$packageConfDir:}"
    if [[ -n "''${NIX_GHC_PACKAGE_PATH_FOR_TEST}" ]]; then
      export GHC_PACKAGE_PATH="''${NIX_GHC_PACKAGE_PATH_FOR_TEST}"
    fi

    to the installPhase doesn't fix the issue, but improves the situation in that cabal will now die while complaining that the package that exposes the module is private.

    ++ export NIX_GHC_PACKAGE_PATH_FOR_TEST=/build/tmp.rCFTAQTR24/package.conf.d:
    ++ NIX_GHC_PACKAGE_PATH_FOR_TEST=/build/tmp.rCFTAQTR24/package.conf.d:
    ++ [[ -n /build/tmp.rCFTAQTR24/package.conf.d: ]]
    ++ export GHC_PACKAGE_PATH=/build/tmp.rCFTAQTR24/package.conf.d:
    ++ GHC_PACKAGE_PATH=/build/tmp.rCFTAQTR24/package.conf.d:
    ++ runHook preInstall
    ++ local hookName=preInstall
    <snip>
    ++ ./Setup copy
    Installing library in /nix/store/4xw0kylznhhvp9gkklp5fngx49rwsdzz-pkg-0.1.0/lib/ghc-9.8.2/lib/x86_64-linux-ghc-9.8.2/pkg-0.1.0-KVsuGUjsxi5DaiM26qpZ9T
    ++ local packageConfDir=/nix/store/4xw0kylznhhvp9gkklp5fngx49rwsdzz-pkg-0.1.0/lib/ghc-9.8.2/lib/package.conf.d
    ++ local packageConfFile=/nix/store/4xw0kylznhhvp9gkklp5fngx49rwsdzz-pkg-0.1.0/lib/ghc-9.8.2/lib/package.conf.d/pkg-0.1.0.conf
    ++ mkdir -p /nix/store/4xw0kylznhhvp9gkklp5fngx49rwsdzz-pkg-0.1.0/lib/ghc-9.8.2/lib/package.conf.d
    ++ ./Setup register --gen-pkg-config=/nix/store/4xw0kylznhhvp9gkklp5fngx49rwsdzz-pkg-0.1.0/lib/ghc-9.8.2/lib/package.conf.d/pkg-0.1.0.conf
    Error: Setup: '/nix/store/pndpvzz83bqdl61pag3jyckjqa9zga4j-ghc-9.8.2/bin/ghc' exited with an error:
    <command line>: Could not load module ‘The.Plugin’.
    It is a member of the hidden package ‘library-of-plugin-version'.
    Perhaps you need to add ‘library-of-plugin-version’ to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.
  4. tests etc. all pass, it is only the installPhase that is problematic
  5. the bug does not reproduce if the plugin option is set as a pragma in the source files, as compared to in the ghc-options stanza in the cabal file

Notify maintainers

@sternenseemann @maralorn

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
- system: `"x86_64-linux"`
 - host os: `Linux 6.6.49, NixOS, 24.11 (Vicuna), 24.11.20240905.9bb1e75`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Lix, like Nix) 2.91.0
System type: x86_64-linux
Additional system types: aarch64-linux, i686-linux
Features: gc, signed-caches
System configuration file: /etc/nix/nix.conf
User configuration files: /home/mangoiv/.config/nix/nix.conf:/etc/xdg/nix/nix.conf:/home/mangoiv/.nix-profile/etc/xdg/nix/nix.conf:/nix/profile/etc/xdg/nix/nix.conf:/home/mangoiv/.local/state/nix/profile/etc/xdg/nix/nix.conf:/etc/profiles/per-user/mangoiv/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf
Store directory: /nix/store
State directory: /nix/var/nix
Data directory: /nix/store/dzs6wmlzg8hdh9mjailpghvxrzs43jdn-lix-2.91.0/share`
 - nixpkgs: `/nix/store/x615nvk9kw68cmsg01aahd1v0kzv9ifn-source`

Add a :+1: reaction to issues you find important.

sternenseemann commented 1 month ago

Sounds like #302464. In that case that'd be a Cabal bug that's fixed in whatever GHC 9.10 ships.

MangoIV commented 1 month ago

@sternenseemann do I understand correctly that how it looks now there’s not going to be a haskellPackages with ghc 9.8? Because if plugins not work?

MangoIV commented 1 month ago

or just until 983?

MangoIV commented 1 month ago

https://gitlab.haskell.org/ghc/ghc/-/issues/24518

I think it’ll be blocked by this ticket and until 9.8.3

sternenseemann commented 1 month ago

There will be a haskellPackages with 9.8 whenever there's a Stackage LTS with 9.8 usually.

MangoIV commented 1 month ago

@sternenseemann would there be a haskellPackages with broken plugin support?

MangoIV commented 1 month ago

Even if stackage LTS does the upgrade?

maralorn commented 1 month ago

@MangoIV I don’t understand why you are pressing this point. This is a complicated issue and no one has made an executive decision about whether we skip 9.8 because of this. Generally switching ghcs is a lot of work. When we are at that point we will try it out and determine feasibility based on factors like how many packages it breaks. But this issue doesn’t sound like we can’t find a work around, does it?

MangoIV commented 1 month ago

Sorry if that got across the wrong way - for me it sounded like sterni was going to make the switch depend on when stackage does - I’d be concerned about this as this would break plugin support downstream which I think is prohibitive.

maralorn commented 1 month ago

Well, in the last years there is no precedent for us to not follow stackage lts and it would probably hard to figure out an alternative. I am confident that we will be able to find a fix for this once it is required.

MangoIV commented 1 month ago

Let’s see - as I said, I suspect that stackage will not go to 9.8 until minor version 3 is out since stack is affected as well iiuc

sternenseemann commented 1 month ago

Closing as duplicate https://github.com/NixOS/nixpkgs/issues/302464.