Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLS is broken on 9.4 with a recent stack; passing flags while configuring tools #1816

Closed
abarbu opened this issue Dec 15, 2022 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@abarbu
Copy link

abarbu commented Dec 15, 2022

HLS has build problems because of a version bump in some without coordination with dependent-sum: haskell/haskell-language-server#2969

This results in a build failure with the latest stackage nightly on GHC 9.4.

To reproduce:
Init a new repo nix flake init --template templates#haskell-nix --impure

Replace flake.nix with the file below

{
  description = "A very basic flake";
  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.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system:
    let
      overlays = [ haskellNix.overlay
        (final: prev: {
          helloProject =
            final.haskell-nix.project' {
              src = ./.;
              compiler-nix-name = "ghc943";
              projectFileName = "stack.yaml";
              shell.tools = {
                cabal = {};
                hlint = {};
                haskell-language-server = {};
              };
              shell.buildInputs = with pkgs; [
                nixpkgs-fmt
                pkgs.zlib
              ];
            };
        })
      ];
      pkgs = import nixpkgs { inherit system overlays; inherit (haskellNix) config; };
      flake = pkgs.helloProject.flake {
      };
    in flake // {
      defaultPackage = flake.packages."hello:exe:hello";
    });
}

Add stack.yaml

resolver: nightly-2022-12-09

nix:
  enable: true

allow-newer: true

I can see 3 solutions but I can't seem to get any of them to work:

  1. Override some to the older some-1.0.3 instead of some-1.0.4.1. I tried to do this but stack.yaml doesn't seem to affect the tools.
  2. Pass -allow-newer when building HLS. Doesn't seem like anything I try ends up affecting the configureFlags while building HLS.
  3. Change the snapshot used. Even if I set the resolver to one where some-1.0.3 is available, like nightly-2022-11-11, this doesn't seem to affect how HLS is built.

How can I build HLS against 9.4? Preferably with option 1?

@abarbu abarbu added the bug Something isn't working label Dec 15, 2022
@abarbu
Copy link
Author

abarbu commented Dec 15, 2022

Just for reference this is what the problem looks like when you run nix develop

Error: cabal: Could not resolve dependencies:
[__0] trying: haskell-language-server-1.8.0.0 (user goal)
[__1] trying: lsp-types-1.6.0.0 (dependency of haskell-language-server)
[__2] trying: some-1.0.4.1 (dependency of lsp-types)
[__3] trying: hls-plugin-api-1.5.0.0 (dependency of haskell-language-server)
[__4] next goal: dependent-sum (dependency of hls-plugin-api)
[__4] rejecting: dependent-sum-0.7.1.1 (conflict: some==1.0.4.1, dependent-sum
=> some>=1.0.1 && <1.0.3)
[__4] skipping: dependent-sum-0.7.1.0, dependent-sum-0.7.0.0 (has the same
characteristics that caused the previous version to fail: excludes 'some'
version 1.0.4.1)
[__4] rejecting: dependent-sum-0.6.2.0, dependent-sum-0.5, dependent-sum-0.4,
dependent-sum-0.3.2.2, dependent-sum-0.3.2.1, dependent-sum-0.3.2.0,
dependent-sum-0.3.1.0, dependent-sum-0.2.1.0, dependent-sum-0.2.0.2,
dependent-sum-0.2.0.1, dependent-sum-0.2, dependent-sum-0.1,
dependent-sum-0.6.2.2, dependent-sum-0.6.1, dependent-sum-0.6 (constraint from
project config /build/tmp.N5BGsK03ju/cabal.project requires >=0.7.1.0)
[__4] fail (backjumping, conflict set: dependent-sum, hls-plugin-api, some)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: base, dependent-sum,
haskell-language-server, some, hls-plugin-api, lsp-types
Try running with --minimize-conflict-set to improve the error message.

@abarbu abarbu changed the title HLS is broken on 9.4 with a recent stack; passing flags to tools HLS is broken on 9.4 with a recent stack; passing flags while configuring tools Dec 15, 2022
@sekunho
Copy link

sekunho commented Jan 5, 2023

I have a similar looking error with HLS 1.9 for GHC 9.2.5

Using index-state 2023-01-05T00:00:00Z
Warning: The package list for 'hackage.haskell.org-at-2023-01-05T000000Z' is
19362 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
Error: cabal: Could not resolve dependencies:
[__0] trying: haskell-language-server-1.9.0.0 (user goal)
[__1] trying: haskell-language-server:+callhierarchy
[__2] trying: hls-call-hierarchy-plugin-1.1.0.0 (dependency of
haskell-language-server +callhierarchy)
[__3] next goal: hls-plugin-api (dependency of haskell-language-server)
[__3] rejecting: hls-plugin-api-1.6.0.0 (conflict: hls-call-hierarchy-plugin
=> hls-plugin-api^>=1.5)
[__3] rejecting: hls-plugin-api-1.5.0.0 (conflict: haskell-language-server =>
hls-plugin-api^>=1.6)
[__3] skipping: hls-plugin-api-1.4.0.0, hls-plugin-api-1.3.0.0,
hls-plugin-api-1.2.0.2, hls-plugin-api-1.2.0.1, hls-plugin-api-1.2.0.0,
hls-plugin-api-1.1.0.2, hls-plugin-api-1.1.0.1, hls-plugin-api-1.1.0.0,
hls-plugin-api-1.0.0.0, hls-plugin-api-0.7.1.0, hls-plugin-api-0.7.0.0,
hls-plugin-api-0.6.0.0, hls-plugin-api-0.5.0.1, hls-plugin-api-0.5.0.0,
hls-plugin-api-0.4.1.0, hls-plugin-api-0.4.0.0 (has the same characteristics
that caused the previous version to fail: excluded by constraint '^>=1.6' from
'haskell-language-server')
[__3] fail (backjumping, conflict set: haskell-language-server,
hls-call-hierarchy-plugin, hls-plugin-api)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: haskell-language-server,
hls-plugin-api, hls-call-hierarchy-plugin,
haskell-language-server:callhierarchy
Try running with --minimize-conflict-set to improve the error message.
• Updated input 'haskellNix':
    'github:input-output-hk/haskell.nix/2f3ec7bbf2e790122ca276a4ab038bf2749c6c93' (2022-12-22)
  → 'github:input-output-hk/haskell.nix/895435f1893db0ff3666f25ed7d6c92c78673322' (2023-01-05)
• Updated input 'haskellNix/hackage':
    'github:input-output-hk/hackage.nix/2f24c038122b94e1d1dcf24c0eee11f05bdcb414' (2022-12-22)
  → 'github:input-output-hk/hackage.nix/d07ba13b6bf6197ec96c7e912cb1184eaf005928' (2023-01-05)
• Updated input 'haskellNix/stackage':
    'github:input-output-hk/stackage.nix/b482b18e4e619ce7a7e5db3f96865b6b1d25ee41' (2022-12-22)
  → 'github:input-output-hk/stackage.nix/5c1a68f2f6642fe7419c5c1c5f4d6668786f8bf7' (2023-01-04)

@michaelpj
Copy link
Collaborator

Upstream issue, recently resolved: haskell/haskell-language-server#3427

@abarbu
Copy link
Author

abarbu commented Jan 5, 2023

This specific issue was, but the problem of how to pass flags to tools hasn't been resolved.

The old solution of doing:

                shell = {
                  tools = {
                    cabal = {};
                    hlint = {};
                    haskell-language-server = {
                      version = "latest";
                      compiler-nix-name = "ghc943";
                      modules = [{
                        packages.haskell-language-server.flags.callHierarchy = false;

No longer works. The flag is ignored now.

@sekunho This works for me now

                shell = {
                  tools = {
                    cabal = {};
                    hlint = {};
                    haskell-language-server = {
                      version = "latest";
                      cabalProject = ''
                        packages: .
                        package haskell-language-server
                           flags: -callHierarchy
                      '';
                      compiler-nix-name = "ghc943";
                      modules = [{
                        packages.haskell-language-server.flags.callHierarchy = false;

Although note that you will want to add reinstallableLibGhc and nonReinstallablePkgs to the tools modules and modules for your project as in #1809 After that HLS works with 9.4.

@hamishmack
Copy link
Collaborator

For now we have given up on making HLS compile from hackage. Instead we are now building it from the GitHub repo. To help with this we have added a pin for the current version to haskell-nix.sources. You can use it like this:

tools.haskell-language-server = { src = pkgs.haskell-nix.sources."hls-1.10"; };

It works better because there is a cabal.project in the GitHub repo with workarounds that would be difficult to add to hackage.

It should be in cache.zw3rk.com for the most recent GHC releases (8.10.7, 9.0.2, 9.2.8, 9.4.5). The code that includes it in the cache is

haskell.nix/build.nix

Lines 58 to 63 in 4835f2b

} // pkgs.lib.optionalAttrs (__compareVersions haskell.compiler.${compiler-nix-name}.version "9.6" < 0) {
hls-latest = tool compiler-nix-name "haskell-language-server" {
inherit evalPackages;
src = pkgs.haskell-nix.sources."hls-1.10";
};
})

@dhess
Copy link
Contributor

dhess commented Jun 1, 2023

We've had to do the same, so it's nice to see that we can replace our hacky version with yours. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants