Onboarding experience for haskell + stack + hls

Hello,

I’m a haskell newbie and tried to get a quick development environment on NixOS in order to play around. I’m using NixOS unstable (6313551cd05425cd5b3e63fe47dbc324eabb15e4) with Flakes enabled and channels disabled.

Due to my lack of knowledge of haskell tooling, I’m unsure whether the problem I’m describing
is NixOS-specific at all.

My requirements are to have a working IDE (for which I’m using vscode and pkgs.vscode-extensions.haskell.haskell) and to be able to spin up a project quickly - for which I used stack new

My initial attempt at this was

nix-shell -p stack haskell-language-server
code .

Alas, haskell-language-server complains that the ghc version it finds is newer than what it was built with.
I think at the time of writing, stack ghc will use ghc-9.8.4, IIUC by virtue of defaulting to a resolver lts-23.10.

One way to resolve this was

nix-shell -p stack 'pkgs.haskell-language-server.override { supportedGhcVersions = [ "98" ]; }'
code .

This works but it needs to build HLS locally, might get evicted by GC and have to be rebuilt, and will need fiddling every time the used GHC changes by virtue of nixpkgs update or stack resolvers. I found it unsatisfactory.

I’m okay with using an older GHC version if it means my IDE will work out of the box. I went to .stack/global-project/stack.yaml and set snapshot: lts-22.43

Now I can see, globally

stack ghc -- --version
The Glorious Glasgow Haskell Compilation System, version 9.6.6

Unfortunately, when I issue stack new foo, I see

Selecting the best among 13 snapshots...


Note: Matches https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/23/10.yaml
      
Selected the snapshot https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/23/10.yaml.

I have no idea where that’s coming from.

Therefore I go and edit the project’s stack.yaml file

snapshot:
  url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/43.yaml

and now (after also providing a hie.yaml file) my new project works in the IDE.

This feels better than having to build hls yourself, but is still a lot of friction, and it took me a long time to figure out.

I’m posting a report here in case people know how I could have achieved my goal better, or how / where this onboarding experience could be improved.

As far as I was able to see, the fundamental issue is that stack tries hard to default to a ghc version which disagrees with the default HLS ghc version in nixpkgs, and the default ghc version in nixpkgs (those appear to match).

I’m new to haskell and had this exact situation.
Try the following (specifically forcing to use system ghc):

But otherwise I basically had the same process to resolving it (I don’t know what hie.yaml is so I did not provide that).