Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Support nix-based projects. #12

Closed
freuk opened this issue Jun 3, 2019 · 12 comments
Closed

Support nix-based projects. #12

freuk opened this issue Jun 3, 2019 · 12 comments

Comments

@freuk
Copy link

freuk commented Jun 3, 2019

Hello - first of all, thanks for providing this and uploading the builds. I'm running into an issue trying to make this work on a nix-based project, which I'm describing here. Sorry about the example not being minimal, I just thought I'd reach out to see if anyone is using all-hies on nix-based projects already.

Essentially, I'm trying to use the nix-env build from the first readme one-liner in this project:

nix-env -iA selection --arg selector 'p: { inherit (p) ghc864; }' -f https://github.com/infinisil/all-hies/tarball/master

I run HIE from inside a nix-shell in that directory root. That (non---pure) shell exposes the dependencies for the codebase as well as ghc 8.6.4 and cabal 2.4.1.0.

HIE is started through my editor via the hie-8.6.4 binary with arguments '--lsp -d -l ~/hie.log.

I'm running into cabal-helper related issues. The full HIE log is in this gist.

Running cabal-helper manually results in this error:

/nix/store/3g820cq05i62kj0vdlwfqv47apiwysw2-cabal-helper-0.9.0.0/bin/cabal-helper-wrapper --with-ghc=ghc --with-ghc-pkg=ghc-pkg --with-cabal=cabal v1-style /home/fre/workspace/dhrun /home/fre/workspace/dhrun/dist-newstyle/build/x86_64-linux/ghc-8.6.4/dhrun-1.0.0

cabal-helper-wrapper: /home/fre/workspace/dhrun/dist-newstyle/build/x86_64-linux/ghc-8.6.4/dhrun-1.0.0/setup-config: openFile: does not exist (No such file or directory)

It seems like cabal-helper is really looking for file setup-config via a v1-style invocation in the dist-newstyle folder. I'm unfamiliar with cabal build styles - does anyone have an idea of what's going on? Referencing a similar issue on the archived hie-nix tracker: domenkozar/hie-nix#36.

Thanks for your time again!

@chuwy
Copy link

chuwy commented Jun 3, 2019

I had a very similar issue recently. In the end I deleted all dist* directories and ran cabal build - this seems to be what fixed the problem.

@infinisil
Copy link
Owner

Ah yes, see https://github.com/haskell/haskell-ide-engine#nix-cabal-helper-no-such-file-or-directory (which I've just PR'd to HIE recently)

@freuk
Copy link
Author

freuk commented Jun 3, 2019

I had tried both these approaches, but no dice unfortunately. Removing the dist-newstyle directory makes cabal-helper-wrapper change its behavior to targeting <project-root>/dist/build Instead. it then proceeds to complain about not finding the Cabal package, even when I add it to the nix-shell environment:

$ ghci
GHCi, version 8.6.4: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /nix/store/28pflzflbs4qdhj79drkhq8b1rqid2mx-ghci.cfg
Prelude
λ> import Distribution.Compiler
Prelude Distribution.Compiler
/nix/store/3g820cq05i62kj0vdlwfqv47apiwysw2-cabal-helper-0.9.0.0/bin/cabal-helper-wrapper --with-ghc=ghc --with-ghc-pkg=ghc-pkg --with-cabal=cabal v1-style /home/fre/workspace/dhrun /home/fre/workspace/dhrun/dist/
cabal-helper-wrapper: Installing a private copy of Cabal because we couldn't
find the right version in your global/user package-db, this might take a
while but will only happen once per Cabal version you're using.

If anything goes horribly wrong just delete this directory and try again:
    /home/fre/.cache/cabal-helper

If you want to avoid this automatic installation altogether install
version 2.4.1.0 of Cabal manually (into your user or global package-db):
    $ cabal install Cabal --constraint "Cabal == 2.4.1.0"

Installing Cabal 2.4.1.0 ...
Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.
cabal: There is no package named 'Cabal'.
You may need to run 'cabal update' to get the latest list of available
packages.

cabal-helper-wrapper: Installing Cabal version 2.4.1.0 failed.

You have the following choices to fix this:

- The easiest way to try and fix this is just reconfigure the project and try
  again:
        $ cabal clean && cabal configure

- If that fails you can try to install the version of Cabal mentioned above
  into your global/user package-db somehow, you'll probably have to fix
  something otherwise it wouldn't have failed above:
        $ cabal install Cabal --constraint 'Cabal == 2.4.1.0'

- If you're using `Build-Type: Simple`:
  - You can see if you can reinstall your cabal-install executable while
    having it linked to a version of Cabal that's available in you
    package-dbs or can be built automatically:
        $ ghc-pkg list | grep Cabal  # find an available Cabal version
            Cabal-W.X.Y.Z
        $ cabal install cabal-install --constraint 'Cabal == W.X.*'
    Afterwards you'll have to reconfigure your project:
        $ cabal clean && cabal configure

- If you're using `Build-Type: Custom`:
  - Have cabal-install rebuild your Setup.hs executable with a version of the
    Cabal library that you have available in your global/user package-db:
        $ cabal clean && cabal configure
    You might also have to install some version of the Cabal to do this:
        $ cabal install Cabal

This seems to be due to the fact that cabal-helper does not seem aware that there is a Nix-provided cabal package database somewhere, as far as I can tell. But I'm not familiar with the tooling enough to conclude or even understand the logic. Ideally, should cabal-helper operate with a different cabal database than the project? What does HIE use it for?

@freuk
Copy link
Author

freuk commented Jun 3, 2019

@chuwy , have you been able to make a pure Nix project work? It would be great to see that code, if you'd be able and willing to share it. :) Thanks again to you both.

@infinisil
Copy link
Owner

@freuk The cabal wrapper indeed does not use Nix's versions of cabal & co., which is I think also the reason why removing the "cabal-helper" caches is sometimes needed.

Did you try a cabal update as the error suggests? I've had to run it too occasionally, even with Nix.

I think haskell/haskell-ide-engine#1126 will eventually be used, which should remove the need for this cabal wrapper helper thing completely.

@freuk
Copy link
Author

freuk commented Jun 3, 2019

I got HIE working by running cabal update && cabal configure && cabal build && rm -rf ~/.cache/cabal-helper on a nix+hie skeleton repository from @cah6 (https://github.com/cah6/haskell-nix-skeleton) . Thanks for that trick @infinisil ! :) For reference, hie sometimes doesn't start responding to json payloads before 10/20 seconds after being started.

@infinisil
Copy link
Owner

Yeah it sometimes takes a bit until it starts, glad you got it working :)

I think we can close this issue: The original error is solved with removing the cabal helper caches as mentioned in the HIE readme, the next problem was solved with cabal update mentioned in the error itself. And that the project should build without any errors to start HIE is always a good idea.

@masaeedu
Copy link

masaeedu commented Aug 31, 2019

I still can't get this to work. I recently switched to cabal 3, since the only way I could get cabal v2 and hie to play together nicely was to keep using the old deprecated cabal build etc. commands (thus avoiding creation of a dist-newstyle folder).

Now that the dist-newstyle folder is used by default, cabal-helper-wrapper gets confused and starts trying to download a private copy of cabal 3. Shouldn't it not be trying to do this if I already have cabal installed and available on the path via my Nix config?

@masaeedu
Copy link

Here is the output that gets dumped when I try to start up VS Code in the folder:

Output
2019-08-31 00:55:09.163796563 [ThreadId 4] - run entered for hie-wrapper(hie-wrapper) Version 0.12.0.0 x86_64 ghc-8.6.5
2019-08-31 00:55:09.165134763 [ThreadId 4] - Current directory:/tmp/tmpfoo
2019-08-31 00:55:09.166440268 [ThreadId 4] - Operating system:linux
2019-08-31 00:55:09.474090811 [ThreadId 4] - Cradle directory:/tmp/tmpfoo
2019-08-31 00:55:09.475353557 [ThreadId 4] - Using plain GHC version
2019-08-31 00:55:09.511016171 [ThreadId 4] - Project GHC version:8.6.5
2019-08-31 00:55:09.51124014 [ThreadId 4] - hie exe candidates :["hie-8.6.5","hie-8.6","hie"]
2019-08-31 00:55:09.512630243 [ThreadId 4] - found hie exe at:/nix/store/xvs0j26jwx1i4p735cjxpjn0z6pq463p-ghc-8.6.5-with-packages/bin/hie-8.6.5
2019-08-31 00:55:09.512978806 [ThreadId 4] - args:[]
2019-08-31 00:55:09.513128901 [ThreadId 4] - launching ....



2019-08-31 00:55:09.852475012 [ThreadId 4] - Using plain GHC version
2019-08-31 00:55:09.885862719 [ThreadId 4] - Run entered for HIE(hie-8.6.5) Version 0.12.0.0 x86_64 ghc-8.6.5
2019-08-31 00:55:09.886402304 [ThreadId 4] - Current directory:/tmp/tmpfoo
2019-08-31 00:55:09.9041044 [ThreadId 10] - Using plain GHC version
Using hie version: Version 0.12.0.0 x86_64 ghc-8.6.5
cabal-helper-wrapper: Installing a private copy of Cabal because we couldn't
find the right version in your global/user package-db, this might take a
while but will only happen once per Cabal version you're using.

If anything goes horribly wrong just delete this directory and try again:
    /home/ankh/.cache/cabal-helper

If you want to avoid this automatic installation altogether install
version 3.0.0.0 of Cabal manually (into your user or global package-db):
    $ cabal install Cabal --constraint "Cabal == 3.0.0.0"

Installing Cabal 3.0.0.0 ...
Unpacking to Cabal-3.0.0.0/
cabal: Invalid package ID: /tmp/cabal-helper-Cabal-source10652/Cabal-3.0.0.0

cabal-helper-wrapper: Installing Cabal version 3.0.0.0 failed.

You have the following choices to fix this:

- The easiest way to try and fix this is just reconfigure the project and try
  again:
        $ cabal clean && cabal configure

- If that fails you can try to install the version of Cabal mentioned above
  into your global/user package-db somehow, you'll probably have to fix
  something otherwise it wouldn't have failed above:
        $ cabal install Cabal --constraint 'Cabal == 3.0.0.0'

- If you're using `Build-Type: Simple`:
  - You can see if you can reinstall your cabal-install executable while
    having it linked to a version of Cabal that's available in you
    package-dbs or can be built automatically:
        $ ghc-pkg list | grep Cabal  # find an available Cabal version
            Cabal-W.X.Y.Z
        $ cabal install cabal-install --constraint 'Cabal == W.X.*'
    Afterwards you'll have to reconfigure your project:
        $ cabal clean && cabal configure

- If you're using `Build-Type: Custom`:
  - Have cabal-install rebuild your Setup.hs executable with a version of the
    Cabal library that you have available in your global/user package-db:
        $ cabal clean && cabal configure
    You might also have to install some version of the Cabal to do this:
        $ cabal install Cabal

@infinisil
Copy link
Owner

Probably not all-hies specific: haskell/haskell-ide-engine#1373

@masaeedu
Copy link

This is something I was a little confused about. Is cabal-helper-wrapper a part of hie or of all-hies?

@masaeedu
Copy link

Ah, maybe it's not cabal-helper-wrapper itself, but whatever is passing it arguments? I've opened a separate issue with the exact problem I'm running into, any help figuring out what I'm doing wrong would be appreciated.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants