Skip to content

Commit 8df94c3

Browse files
committed
nix: add support for ghc 9.0.1
1 parent 77af21e commit 8df94c3

File tree

2 files changed

+136
-25
lines changed

2 files changed

+136
-25
lines changed

configuration-ghc-901.nix

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# nix version of cabal-ghc901.project
2+
{ pkgs }:
3+
4+
let
5+
removePluginPackages = hpkgs:
6+
removeAttrs hpkgs [
7+
"hls-tactics-plugin"
8+
"hls-brittany-plugin"
9+
"hls-stylish-haskell-plugin"
10+
"hls-fourmolu-plugin"
11+
"hls-splice-plugin"
12+
"hls-ormolu-plugin"
13+
];
14+
hpkgsOverride = hself: hsuper:
15+
with pkgs.haskell.lib;
16+
let
17+
lsp-src = pkgs.fetchFromGitHub {
18+
owner = "anka-213";
19+
repo = "lsp";
20+
rev = "tag-ghc-9.0.1-without-pr-326";
21+
sha256 = "lW/EdBnvKPLE2+CGE/grIekOu+U/Wh6zMCN4xhJDtPY=";
22+
};
23+
24+
dependent-sum-src = pkgs.fetchFromGitHub {
25+
owner = "anka-213";
26+
repo = "dependent-sum";
27+
rev = "8cf4c7fbc3bfa2be475a17bb7c94a1e1e9a830b5";
28+
sha256 = "WtxTB6ufTZC6SxOtGSfhlO4mY0y9eWejMSa0yUJ7dHQ=";
29+
};
30+
hlint_3_3_1-src = builtins.fetchTarball {
31+
url =
32+
"https://hackage.haskell.org/package/hlint-3.3.1/hlint-3.3.1.tar.gz";
33+
sha256 = "03vb4s4w8k5vp5cjzg7m2bsinbjz1j2aqx4q06syq4r5vb3ai5yq";
34+
};
35+
in {
36+
blaze-textual = hself.callCabal2nix "blaze-textual"
37+
(pkgs.fetchFromGitHub {
38+
owner = "jwaldmann";
39+
repo = "blaze-textual";
40+
rev = "d8ee6cf80e27f9619d621c936bb4bda4b99a183f";
41+
sha256 = "C0dIzf64fBaY8mlhMm1kCQC5Jc1wKBtNO2Y24k7YPUw=";
42+
}) { };
43+
44+
czipwith = hself.callCabal2nix "czipwith" (pkgs.fetchFromGitHub {
45+
owner = "mithrandi";
46+
repo = "czipwith";
47+
rev = "b6245884ae83e00dd2b5261762549b37390179f8";
48+
sha256 = "2uSoGyrxT/OstRcpx55kwP4JwjPbWLxD72LajeyQV0E=";
49+
}) { };
50+
51+
hie-bios = hself.callCabal2nix "hie-bios" (pkgs.fetchFromGitHub {
52+
owner = "jneira";
53+
repo = "hie-bios";
54+
rev = "9b1445ab5efcabfad54043fc9b8e50e9d8c5bbf3";
55+
sha256 = "8ct7t3xIxIAoC+f8VO5e5+QKrd5L5Zu1eButSaE+1Uk=";
56+
}) { };
57+
58+
ghc-api-compat = hself.callCabal2nix "ghc-api-compat"
59+
(pkgs.fetchFromGitHub {
60+
owner = "hsyl20";
61+
repo = "ghc-api-compat";
62+
rev = "8fee87eac97a538dbe81ff1ab18cff10f2f9fa15";
63+
sha256 = "byehvdxQxhNk5ZQUXeFHjAZpAze4Ct9261ro4c5acZk=";
64+
}) { };
65+
66+
th-extras = hself.callCabal2nix "th-extras" (pkgs.fetchFromGitHub {
67+
owner = "anka-213";
68+
repo = "th-extras";
69+
rev = "57a97b4df128eb7b360e8ab9c5759392de8d1659";
70+
sha256 = "Qtha1ge/C0L+uFcV2dZ5xpG59DCxQT7LuK/OYfiM4Pk=";
71+
}) { };
72+
73+
lsp = hself.callCabal2nix "lsp" "${lsp-src}/lsp" { };
74+
lsp-types = hself.callCabal2nix "lsp-types" "${lsp-src}/lsp-types" { };
75+
lsp-test = hself.callCabal2nix "lsp-test" "${lsp-src}/lsp-test" { };
76+
77+
dependent-sum =
78+
hself.callCabal2nix "dependent-sum" "${dependent-sum-src}/dependent-sum"
79+
{ };
80+
81+
# Copied from https://github.com/NixOS/nixpkgs/blob/2e672ed71afb9d0cea962b694ddb4e63a9ee00eb/pkgs/development/haskell-modules/configuration-ghc-9.0.x.nix#L109
82+
hlint = (hself.callCabal2nix "hlint" hlint_3_3_1-src { }).overrideScope
83+
(self: super: {
84+
ghc-lib-parser = overrideCabal self.ghc-lib-parser_9_0_1_20210324 {
85+
doHaddock = false;
86+
};
87+
ghc-lib-parser-ex = self.ghc-lib-parser-ex_9_0_0_4;
88+
});
89+
90+
# Disable plugins
91+
haskell-language-server =
92+
appendConfigureFlags hsuper.haskell-language-server [
93+
"-brittany"
94+
"-eval"
95+
"-fourmolu"
96+
"-ormolu"
97+
"-splice"
98+
"-stylishhaskell"
99+
"-tactic"
100+
"-refineImports"
101+
];
102+
};
103+
in { tweakHpkgs = hpkgs: (removePluginPackages hpkgs).extend hpkgsOverride; }

flake.nix

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,22 @@
3030
overlay = final: prev:
3131
with prev;
3232
let
33-
haskellOverrides = {
34-
overrides = hself: hsuper: {
35-
# we override mkDerivation here to apply the following
36-
# tweak to each haskell package:
37-
# if the package is broken, then we disable its check and relax the cabal bounds;
38-
# otherwise, we leave it unchanged.
39-
# hopefully, this could fix packages marked as broken by nix due to check failures
40-
# or the build failure because of tight cabal bounds
41-
mkDerivation = args:
42-
let
43-
broken = args.broken or false;
44-
check = args.doCheck or true;
45-
jailbreak = args.jailbreak or false;
46-
in hsuper.mkDerivation (args // {
47-
jailbreak = if broken then true else jailbreak;
48-
doCheck = if broken then false else check;
49-
});
50-
};
33+
haskellOverrides = hself: hsuper: {
34+
# we override mkDerivation here to apply the following
35+
# tweak to each haskell package:
36+
# if the package is broken, then we disable its check and relax the cabal bounds;
37+
# otherwise, we leave it unchanged.
38+
# hopefully, this could fix packages marked as broken by nix due to check failures
39+
# or the build failure because of tight cabal bounds
40+
mkDerivation = args:
41+
let
42+
broken = args.broken or false;
43+
check = args.doCheck or true;
44+
jailbreak = args.jailbreak or false;
45+
in hsuper.mkDerivation (args // {
46+
jailbreak = if broken then true else jailbreak;
47+
doCheck = if broken then false else check;
48+
});
5149
};
5250
gitignoreSource = (import gitignore { inherit lib; }).gitignoreSource;
5351

@@ -91,7 +89,10 @@
9189
builtins.mapAttrs (_: dir: gitignoreSource dir) sourceDirs;
9290

9391
extended = hpkgs:
94-
(hpkgs.override haskellOverrides).extend (hself: hsuper:
92+
(hpkgs.override (old: {
93+
overrides = lib.composeExtensions (old.overrides or (_: _: { }))
94+
haskellOverrides;
95+
})).extend (hself: hsuper:
9596
# disable all checks for our packages
9697
builtins.mapAttrs (_: drv: haskell.lib.dontCheck drv)
9798
(lib.composeExtensions
@@ -135,7 +136,7 @@
135136
hooks = {
136137
stylish-haskell.enable = true;
137138
# use stylish-haskell with our target ghc
138-
stylish-haskell.entry = "${hpkgs.stylish-haskell}/bin/stylish-haskell --inplace";
139+
stylish-haskell.entry = pkgs.lib.mkForce "${hpkgs.stylish-haskell}/bin/stylish-haskell --inplace";
139140
stylish-haskell.excludes = [
140141
# Ignored files
141142
"^Setup.hs$"
@@ -156,14 +157,16 @@
156157
};
157158
};
158159

160+
ghc901Config = (import ./configuration-ghc-901.nix) { inherit pkgs; };
161+
159162
# GHC versions
160163
ghcDefault = pkgs.hlsHpkgs ("ghc"
161164
+ pkgs.lib.replaceStrings [ "." ] [ "" ]
162165
pkgs.haskellPackages.ghc.version);
163166
ghc884 = pkgs.hlsHpkgs "ghc884";
164167
ghc8104 = pkgs.hlsHpkgs "ghc8104";
165168
ghc8105 = pkgs.hlsHpkgs "ghc8105";
166-
ghc901 = pkgs.hlsHpkgs "ghc901";
169+
ghc901 = ghc901Config.tweakHpkgs (pkgs.hlsHpkgs "ghc901");
167170

168171
# Create a development shell of hls project
169172
# See https://github.com/NixOS/nixpkgs/blob/5d4a430472cafada97888cc80672fab255231f57/pkgs/development/haskell-modules/make-package-set.nix#L319
@@ -172,8 +175,13 @@
172175
hpkgs.shellFor {
173176
doBenchmark = true;
174177
packages = p:
175-
with builtins;
176-
map (name: p.${name}) (attrNames hlsSources);
178+
with lib;
179+
# we can remove sources attrs from hpkgs to exclude HLS plugins,
180+
# so hpkgs may not be the superset of hlsSources
181+
pipe (attrNames hlsSources) [
182+
(xs: map (name: p.${name} or null) xs)
183+
(xs: remove null xs)
184+
];
177185
buildInputs = [ gmp zlib ncurses capstone tracy (gen-hls-changelogs hpkgs) ]
178186
++ (with hpkgs; [
179187
cabal-install
@@ -213,14 +221,14 @@
213221
haskell-language-server-884-dev = mkDevShell ghc884;
214222
haskell-language-server-8104-dev = mkDevShell ghc8104;
215223
haskell-language-server-8105-dev = mkDevShell ghc8105;
216-
haskell-language-server-901-dev = builtins.throw "Nix expression for developing HLS in GHC 9.0.1 is not yet available"; # mkDevShell ghc901;
224+
haskell-language-server-901-dev = mkDevShell ghc901;
217225

218226
# hls package
219227
haskell-language-server = mkExe ghcDefault;
220228
haskell-language-server-884 = mkExe ghc884;
221229
haskell-language-server-8104 = mkExe ghc8104;
222230
haskell-language-server-8105 = mkExe ghc8105;
223-
haskell-language-server-901 = builtins.throw "Nix expression for building HLS in GHC 9.0.1 is not yet available"; # mkExe ghc901;
231+
haskell-language-server-901 = mkExe ghc901;
224232
};
225233

226234
defaultPackage = packages.haskell-language-server;

0 commit comments

Comments
 (0)