Haskell shell broke itself?

VSCode config:

{
  "[haskell]": {
    "editor.defaultFormatter": "haskell.haskell"
  },
  "haskell.manageHLS": "PATH"
}

Project contains whatever default files are generated via stack init.

Both haskell.haskell and justusadam.language-haskell vscode extensions are installed (from nixpkgs).

2 weeks ago, the following flake.nix worked fine, including formatting:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };

  outputs =
    { self, nixpkgs }:
    {
      devShells.x86_64-linux.default =
        let
          p = nixpkgs.legacyPackages.x86_64-linux;
        in
        p.mkShell {
          packages = [
            (p.haskellPackages.ghcWithPackages (h: [
              h.implicit-hie
              h.regex-posix
              h.split
            ]))
            p.haskell-language-server
            p.stack
          ];
        };
    };
}

Suddenly today vscode spits out an error from the extension:

Failed to find a HLS version for GHC 9.8.4 Executable names we failed to find: haskell-language-server-9.8.4,haskell-language-server

So I switched to explicitly specifying ghc984:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };

  outputs =
    { self, nixpkgs }:
    {
      devShells.x86_64-linux.default =
        let
          p = nixpkgs.legacyPackages.x86_64-linux;
          h = p.haskell.packages.ghc984;
        in
        p.mkShell {
          packages = [
            (h.ghcWithPackages (h: [
              h.implicit-hie
              h.regex-posix
              h.split
            ]))
            h.haskell-language-server
            h.stack
          ];
        };
    };
}

However this wastes 20+ minutes on just compiling over 100 packages and downloading 600 more, and formatting was still broken until I restarted vscode about 6 times and it magically fixed itself.

I’d still like to not have to compile this much on my local machine, can I avoid this and just use whatever’s the default? Why did this error even appear?

Actually now that I played around with the flake.nix to get the errors for the repro, I now again get the error There is no formatter for 'haskell' files installed. This is really frustrating.

EDIT: and as I just typed up this post, the error disappeared. :woozy_face:

I’d like to figure out how to prevent these errors once and for all.

Based on https://gist.github.com/lsmor/bb632565cd96be9da589b6e91f80f9ba:

  1. Disallow stack from downloading its own ghc by adding system-ghc: true to the stack.yaml
  2. Explicitly select the stackage snapshot that corresponds with the desired ghc version (in this case, per https://www.stackage.org, LTS 22.43 matches ghc-9.6.6).

The resulting stack.yaml:

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

packages: []

system-ghc: true

Just in case, I also deleted ~/.stack.
Then ran stack update to update the lockfile.