haskell.nix icon indicating copy to clipboard operation
haskell.nix copied to clipboard

Document an example for stack + HLS

Open rmanne opened this issue 2 years ago • 2 comments

I followed the guide for getting started with flakes (https://input-output-hk.github.io/haskell.nix/tutorials/getting-started-flakes.html#scaffolding), and have a flake.nix:

{
  description = "haskell-reddit-image-browser's description";
  inputs.haskellNix.url = "github:input-output-hk/haskell.nix";
  inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  outputs = { self, nixpkgs, flake-utils, haskellNix }:
    flake-utils.lib.eachDefaultSystem (system:
    let
      dependencyOverlays = [
        (self: super: {
          # Overrides for ffmpeg-light
          libavutil = self.ffmpeg;
          libavformat = self.ffmpeg;
          libavcodec = self.ffmpeg;
          libswscale = self.ffmpeg;
          libavdevice = self.ffmpeg;
          libswresample = self.ffmpeg;
        })
      ];
      overlays = dependencyOverlays ++ [ haskellNix.overlay
        (final: prev: {
          haskell-reddit-image-browserProject =
            final.haskell-nix.project' {
              src = ./.;
              compiler-nix-name = "ghc8107";
              # This is used by `nix develop .` to open a shell for use with
              # `cabal`, `hlint` and `haskell-language-server`
              shell.tools = {
                #cabal = {};
                #stack = {};
                hlint = {};
                haskell-language-server = {};
              };
              # Non-Haskell shell tools go here
              shell.buildInputs = with pkgs; [ nixpkgs-fmt ];
            };
        })
      ];
      pkgs = import nixpkgs { inherit system overlays; inherit (haskellNix) config; };
      flake = pkgs.haskell-reddit-image-browserProject.flake { };
    in flake // { defaultPackage = flake.packages."haskell-reddit-image-browser:exe:rib"; });
}

However, HLS appears to see the cabal on the path, sees no .cabal file locally, and proceeds to complain about certain language extensions not being enabled while they actually are (in the package.yaml). nix build and nix develop has no problems, only HLS, which I assume is just unable to find the correct configuration. Attempt to uncomment the stack line instead results in the following error (where it looks like it is attempting to install stack with cabal instead of just using nix's version):

trace: ERROR: cabal configure failed with:
Warning: The package list for 'hackage.haskell.org-at-2021-12-19T000000Z' is
18980 days old.
Run 'cabal update' to get the latest list of available packages.
Warning: Requested index-state 2021-12-19T00:00:00Z is newer than
'hackage.haskell.org-at-2021-12-19T000000Z'! Falling back to older state
(2021-12-18T23:43:56Z).
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] next goal: stack (user goal)
[__0] rejecting: stack-2.7.3, stack-2.7.1, stack-2.5.1.1, stack-2.5.1,
stack-2.3.3, stack-2.3.1, stack-2.1.3.1, stack-2.1.3, stack-2.1.1.1,
stack-2.1.1, stack-1.9.3.1, stack-1.9.3, stack-1.9.1.1, stack-1.9.1,
stack-1.7.1, stack-1.6.5, stack-1.6.3.1, stack-1.6.3, stack-1.6.1.1,
stack-1.6.1, stack-1.5.1, stack-1.5.0, stack-1.4.0, stack-1.3.2, stack-1.3.0,
stack-1.2.0, stack-1.1.2, stack-1.1.0, stack-1.0.4.3, stack-1.0.4.2,
stack-1.0.4.1, stack-1.0.4, stack-1.0.2, stack-1.0.0, stack-0.1.10.1,
stack-0.1.10.0, stack-0.1.8.0, stack-0.1.6.0, stack-0.1.5.0, stack-0.1.4.1,
stack-0.1.4.0, stack-0.1.3.1, stack-0.1.3.0, stack-0.1.2.0, stack-0.1.1.0,
stack-0.1.0.0, stack-0.0.3, stack-0.0.2.1, stack-0.0.2, stack-0.0.1,
stack-0.0.0 (constraint from user target requires ==9.9.9)
[__0] trying: stack-9.9.9
[__1] next goal: base (dependency of stack)
[__1] rejecting: base-4.14.3.0/installed-4.14.3.0 (conflict: stack => base<0)
[__1] skipping: base-4.16.0.0, base-4.15.0.0, base-4.14.3.0, base-4.14.2.0,
base-4.14.1.0, base-4.14.0.0, base-4.13.0.0, base-4.12.0.0, base-4.11.1.0,
base-4.11.0.0, base-4.10.1.0, base-4.10.0.0, base-4.9.1.0, base-4.9.0.0,
base-4.8.2.0, base-4.8.1.0, base-4.8.0.0, base-4.7.0.2, base-4.7.0.1,
base-4.7.0.0, base-4.6.0.1, base-4.6.0.0, base-4.5.1.0, base-4.5.0.0,
base-4.4.1.0, base-4.4.0.0, base-4.3.1.0, base-4.3.0.0, base-4.2.0.2,
base-4.2.0.1, base-4.2.0.0, base-4.1.0.0, base-4.0.0.0, base-3.0.3.2,
base-3.0.3.1 (has the same characteristics that caused the previous version to
fail: excluded by constraint '<0' from 'stack')
[__1] fail (backjumping, conflict set: base, stack)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: stack, base



error: builder for '/nix/store/nnkb7swfgwijia31nm4cxw6n2ssrkv9n-cabal-configure-error.drv' failed with exit code 1;
       last 10 log lines:
       > base-4.7.0.0, base-4.6.0.1, base-4.6.0.0, base-4.5.1.0, base-4.5.0.0,
       > base-4.4.1.0, base-4.4.0.0, base-4.3.1.0, base-4.3.0.0, base-4.2.0.2,
       > base-4.2.0.1, base-4.2.0.0, base-4.1.0.0, base-4.0.0.0, base-3.0.3.2,
       > base-3.0.3.1 (has the same characteristics that caused the previous version to
       > fail: excluded by constraint '<0' from 'stack')
       > [__1] fail (backjumping, conflict set: base, stack)
       > After searching the rest of the dependency tree exhaustively, these were the
       > goals I've had most trouble fulfilling: stack, base
       >
       > Unable to find component stack:exe:stack due to the above cabal configuration error

Another thing I tried is just adding stack under shell.buildInputs instead of shell.tools, and this time, it built, and haskell-language-server even prints out all of the tools successfully:

> haskell-language-server --probe-tools
haskell-language-server version: 1.5.1.0 (GHC: 8.10.7) (PATH: /nix/store/6ixxyagla53ng5m0d331q3yk8ylyf07m-haskell-language-server-exe-haskell-language-server-1.5.1.0/bin/haskell-language-server)
Tool versions found on the $PATH
cabal:		3.6.2.0
stack:		2.7.3
ghc:		8.10.7

But fails to offer any auto-completion. No code actions are available, and even a simple task like finding the definition of something defined locally fails. I think my IDE isn't the problem because I created a different project using cabal instead and it had no problems. Maybe HLS itself is incompatible with stack 2.7.3, but also maybe it has something to do with the way it's set up by haskell.nix. I tried adding an explicit hie.yaml, but that didn't seem to make a difference either way. https://haskell-language-server.readthedocs.io/en/latest/configuration.html#configuring-your-project-build. HLS doesn't report any errors in its logs.

If someone has a working example, it would be very useful for it to be added to the getting started guide in haskell.nix because the existing set up doesn't work for stack.

rmanne avatar Dec 19 '21 22:12 rmanne

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 28 '22 16:09 stale[bot]

Attempt to uncomment the stack line instead results in the following error

This is caused by #1748. If you specify the version of stack like (replace stack = {}; with stack = "2.9.1";) it should work.

hamishmack avatar Oct 10 '22 13:10 hamishmack