Skip to content

Commit bcca365

Browse files
authored
Allow flake consumer to specify GHC version (#185)
Closes #178 Adds ability to install via nix flake, passing in GHC version. Also adds LSP instructions for the helix editor.
1 parent 406a515 commit bcca365

3 files changed

Lines changed: 128 additions & 43 deletions

File tree

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ If you want to use `static-ls` in your IDE then
2525
recommended alongside `-fdefer-type-errors flag` for better UX
2626
and the [ghc hiedb plugin](https://github.com/josephsumabat/hiedb-plugin) for re-indexing.
2727

28-
Currently only ghc 9.4.4 and 9.6.1 are explicitly supported but I'm happy to add support for other versions of ghc if desired
28+
Currently only ghc 9.4.4 and 9.6.1 are explicitly supported but I'm happy to add support for other versions of ghc if desired.
29+
30+
To install, it is recommended to build from source. It's important to build
31+
`static-ls` with the same version of GHC that your project uses.
32+
33+
If you use nix, you can checkout the section below to see how to install
34+
`static-ls` via nix flake.
2935

30-
(NOTE: The current version on hackage is out of date. Building from source is currently recommended.)
3136

3237
## Quick start
3338

@@ -154,6 +159,33 @@ static-ls includes a `ghcid` subcommand which passes the appropriate flags to us
154159
- Must be compiled on the same version of ghc as the project
155160
- You will need to re-index your hie files once you edit your project
156161
162+
## Install with Nix
163+
164+
**IMPORTANT:** You must build `static-ls` with the same GHC version as your project. Using a different GHC version will result in compatibility issues with HIE files.
165+
166+
Add `static-ls` as an input to your flake:
167+
168+
```nix
169+
# flake.nix
170+
{
171+
inputs = {
172+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
173+
static-ls = {
174+
url = "github:josephsumabat/static-ls";
175+
inputs.nixpkgs.follows = "nixpkgs"; # Use your nixpkgs version
176+
};
177+
};
178+
179+
outputs = { self, nixpkgs, static-ls, ... }: {
180+
packages.x86_64-linux.default = static-ls.lib.x86_64-linux.mkPackage {
181+
ghcVersion = "ghc963"; # Match your project's GHC version
182+
};
183+
};
184+
}
185+
```
186+
187+
Available GHC versions include: `ghc963`, `ghc981`, `ghc982`, `ghc945`, `ghc946`, etc. Check your nixpkgs for available versions.
188+
157189
## Editor setup
158190
Instructions for editor setup
159191

@@ -231,6 +263,27 @@ You can technically use any LSP compliant client - for a generic one we generall
231263
:language-id "haskell"))
232264
```
233265

266+
### Helix
267+
Modify your `languages.toml` config file to add the following:
268+
269+
```toml
270+
[[language]]
271+
name = "haskell"
272+
language-servers = ["haskell-static-ls"]
273+
274+
[language-server.haskell-static-ls]
275+
command = "static-ls"
276+
277+
```
278+
279+
You can verify that it's configured properly and that `static-ls` is discoverable
280+
by helix with `hx --health haskell`. You should see something like:
281+
282+
```sh
283+
Configured language servers:
284+
✓ haskell-static-ls: /path/to/static-ls
285+
```
286+
234287
## Troubleshooting
235288
### Slowdowns
236289
Some editors watch all folders in your project directory for changes and report those to the LSP server. This might cause significant slowdown when `.hiefiles` or `.hifiles` are tracked (documented in #175).

flake.nix

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,77 @@
99
flake-utils.url = "github:numtide/flake-utils";
1010
};
1111

12-
outputs = {
13-
self,
14-
nixpkgs,
15-
flake-utils,
16-
}:
17-
flake-utils.lib.eachDefaultSystem (system: let
18-
# pkgs = nixpkgs.legacyPackages.${system};
19-
pkgs = import nixpkgs {
20-
inherit system;
21-
overlays = [
22-
(import ./nix/overlays)
23-
];
24-
};
25-
26-
#haskellPackages = pkgs.haskell.packages.ghc963;
27-
haskellPackages = pkgs.haskellPackages;
28-
29-
jailbreakUnbreak = pkg:
30-
pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: {meta = {};}));
12+
outputs =
13+
{
14+
self,
15+
nixpkgs,
16+
flake-utils,
17+
}:
18+
let
19+
# Default GHC version used for the default package outputs
20+
defaultGhcVersion = "ghc963";
3121

22+
# Name of package
3223
packageName = "static-ls";
33-
in {
34-
packages.${packageName} = pkgs.haskell.lib.dontCheck (haskellPackages.callCabal2nix packageName self rec {
35-
# Dependency overrides go here
36-
});
37-
38-
packages.default = self.packages.${system}.${packageName};
39-
40-
devShells.default = pkgs.mkShell {
41-
buildInputs = with pkgs; [
42-
pkgs.haskell.packages.${pkgs.ghcVersion}.haskell-language-server # you must build it with your ghc to work
43-
haskellPackages.fourmolu
44-
haskellPackages.hiedb
45-
sqlite
46-
ghcid
47-
cabal-install
48-
alejandra
49-
];
50-
inputsFrom = [self.packages.${system}.${packageName}.env];
51-
shellHook = "PS1=\"[static-ls:\\w]$ \"";
52-
};
53-
});
24+
25+
# Function to create packages for a given GHC version
26+
mkNixPkgs =
27+
{
28+
system,
29+
ghcVersion,
30+
}:
31+
import nixpkgs {
32+
inherit system;
33+
overlays = [
34+
(import ./nix/overlays ghcVersion)
35+
];
36+
};
37+
38+
# Given a pkg set, build static-ls
39+
mkPackage =
40+
pkgs:
41+
pkgs.haskell.lib.dontCheck (
42+
pkgs.haskellPackages.callCabal2nix packageName self rec {
43+
# Dependency overrides go here
44+
}
45+
);
46+
47+
in
48+
flake-utils.lib.eachDefaultSystem (
49+
system:
50+
let
51+
pkgs = mkNixPkgs {
52+
inherit system;
53+
ghcVersion = defaultGhcVersion;
54+
};
55+
package = mkPackage pkgs;
56+
in
57+
{
58+
packages.${packageName} = package;
59+
packages.default = package;
60+
61+
devShells.default = pkgs.mkShell {
62+
buildInputs = with pkgs; [
63+
pkgs.haskell.packages.${pkgs.ghcVersion}.haskell-language-server # you must build it with your ghc to work
64+
haskellPackages.fourmolu
65+
haskellPackages.hiedb
66+
sqlite
67+
ghcid
68+
cabal-install
69+
alejandra
70+
];
71+
inputsFrom = [ package.env ];
72+
shellHook = "PS1=\"[static-ls:\\w]$ \"";
73+
};
74+
75+
# Expose a function that consumers can use to build with their desired
76+
# GHC version
77+
lib.mkPackage =
78+
{ ghcVersion }:
79+
(mkPackage (mkNixPkgs {
80+
inherit system ghcVersion;
81+
}));
82+
83+
}
84+
);
5485
}

nix/overlays/default.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ let
88
};
99

1010
in
11+
ghcVersion:
1112
self: super: {
12-
ghcVersion = "ghc963";
13+
ghcVersion = ghcVersion;
1314

1415
all-cabal-hashes =
1516
# Update revision to match required hackage

0 commit comments

Comments
 (0)