-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathflake.nix
More file actions
296 lines (288 loc) · 9.05 KB
/
Copy pathflake.nix
File metadata and controls
296 lines (288 loc) · 9.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs";
ocaml-overlays = {
url = "github:nix-ocaml/nix-overlays";
inputs.nixpkgs.follows = "nixpkgs";
};
merlin = {
url = "github:ocaml/merlin";
flake = false;
};
};
outputs =
{
self,
flake-utils,
nixpkgs,
...
}@inputs:
let
package = "ocaml-lsp-server";
ocamlformat = pkgs: pkgs.ocamlformat_0_29_0;
basePackage = {
duneVersion = "3";
version = "n/a";
src = ./.;
doCheck = true;
};
overlay = merlin: final: prev: {
ocaml-lsp = prev.ocaml-lsp.overrideAttrs (_: {
# Do not add share/nix-support, so that dependencies from
# the scope don't leak into dependent derivations
doNixSupport = false;
});
dune-release = prev.dune-release.overrideAttrs (_: {
doCheck = false;
});
ocamlPackages = prev.ocamlPackages.overrideScope (
oself: osuper:
let
fixPreBuild = o: {
propagatedBuildInputs = o.propagatedBuildInputs ++ [ oself.pp ];
preBuild = ''
rm -rf vendor/csexp vendor/pp
'';
};
in
{
# TODO remove these hacks eventually
dyn = osuper.dyn.overrideAttrs fixPreBuild;
dune-private-libs = osuper.dune-private-libs.overrideAttrs fixPreBuild;
dune-glob = osuper.dune-glob.overrideAttrs fixPreBuild;
dune-action-plugin = osuper.dune-action-plugin.overrideAttrs fixPreBuild;
dune-rpc = osuper.dune-rpc.overrideAttrs fixPreBuild;
stdune = osuper.stdune.overrideAttrs fixPreBuild;
merlin-lib = osuper.merlin-lib.overrideAttrs (o: {
src = merlin;
});
}
);
};
makeLocalPackages =
pkgs:
let
buildDunePackage = pkgs.ocamlPackages.buildDunePackage;
in
rec {
jsonrpc = buildDunePackage (
basePackage
// {
pname = "jsonrpc";
doCheck = false;
propagatedBuildInputs = with pkgs.ocamlPackages; [ yojson ];
}
);
lsp = buildDunePackage (
basePackage
// {
pname = "lsp";
doCheck = false;
propagatedBuildInputs = with pkgs.ocamlPackages; [
jsonrpc
yojson
ppx_yojson_conv_lib
uutf
];
checkInputs =
let
p = pkgs.ocamlPackages;
in
[
p.stdune
p.cinaps
p.base_quickcheck
p.ppx_expect
p.ppx_sexp_conv
p.ppx_yojson_conv
p.top-closure
(ocamlformat pkgs)
];
}
);
ocp-indent-rpc =
with pkgs.ocamlPackages;
buildDunePackage (
basePackage
// {
pname = "ocp-indent-rpc";
doCheck = false;
checkInputs = [ ppx_expect ];
propagatedBuildInputs = [
csexp
ocp-indent
];
}
);
ocaml-lsp =
with pkgs.ocamlPackages;
buildDunePackage (
basePackage
// {
pname = package;
doCheck = false;
checkInputs =
let
p = pkgs.ocamlPackages;
in
[
p.base_quickcheck
p.ppx_expect
p.ppx_sexp_conv
p.ppx_yojson_conv
p.ocp-indent
ocaml-index
ocp-indent-rpc
(ocamlformat pkgs)
];
buildInputs = [
jsonrpc
lsp
ocamlc-loc
astring
camlp-streams
dune-build-info
re
dune-rpc
chrome-trace
dyn
fiber
fs-io
xdg
ordering
spawn
csexp
ocamlformat-rpc-lib
stdune
yojson
ppx_yojson_conv_lib
merlin-lib
base
];
propagatedBuildInputs = [ ];
buildPhase = ''
runHook preBuild
dune build ${package}.install --release ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
runHook postBuild
'';
meta = {
mainProgram = "ocamllsp";
};
}
);
};
in
{
overlays.default = (
final: prev: {
ocamlPackages = prev.ocamlPackages.overrideScope (oself: osuper: makeLocalPackages final);
}
);
}
// (flake-utils.lib.eachDefaultSystem (
system:
let
pkgsWithoutOverlays = import nixpkgs {
inherit system;
overlays = [ inputs.ocaml-overlays.overlays.default ];
};
# The project uses Dune language 3.24, which is newer than the Dune in
# the current Nixpkgs snapshot.
# 3.24.1 ships an inverted RPC registry mtime skip (ocaml/dune#15630).
# ocaml/dune#15634 fixes Poll.poll so clients that race the first
# registry write still discover the Dune instance. Pin that fix until
# a release includes it. applyPatches so dune-rpc/stdune inherit it too
# (overrideAttrs patches only affect the dune package build).
duneSrc = pkgsWithoutOverlays.applyPatches {
name = "dune-3.24.1+15634-src";
src = pkgsWithoutOverlays.fetchurl {
url = "https://github.com/ocaml/dune/releases/download/3.24.1/dune-3.24.1.tbz";
hash = "sha256-Co6qYt/LlFgCvK+abyAmylIoMz7jkaG97dPnCj8m6iw=";
};
patches = [ ./patches/dune-rpc-registry-mtime-15634.patch ];
};
duneLatest = pkgsWithoutOverlays.dune_3.overrideAttrs (_: {
version = "3.24.1+15634";
src = duneSrc;
});
ocamlVersionOverlay = ocaml: _final: prev: {
ocamlPackages = prev.ocaml-ng.${ocaml}.overrideScope (
_: osuper: {
dune = duneLatest;
dune_3 = duneLatest;
# OUnit2's process signal test is flaky under GitHub Actions.
ounit2 = osuper.ounit2.overrideAttrs (_: {
doCheck = false;
});
# cppo's expected error paths differ under OCaml 5.5.
cppo = osuper.cppo.overrideAttrs (_: {
doCheck = false;
});
}
);
};
makeNixpkgs =
ocaml: merlin:
pkgsWithoutOverlays.appendOverlays [
(ocamlVersionOverlay ocaml)
(overlay merlin)
];
pkgs = makeNixpkgs "ocamlPackages_5_5" inputs.merlin;
localPackages = makeLocalPackages pkgs;
checkPkgs = pkgsWithoutOverlays.appendOverlays [
(ocamlVersionOverlay "ocamlPackages_5_5")
];
checkPackages = makeLocalPackages checkPkgs;
devShell =
localPackages: nixpkgs:
nixpkgs.mkShell {
buildInputs = [
nixpkgs.ocamlPackages.utop
nixpkgs.ocamlPackages.ocaml-index
];
inputsFrom = builtins.map (x: x.overrideAttrs (p: n: { doCheck = true; })) (
builtins.attrValues localPackages
);
};
in
{
packages = (
localPackages
// {
default = localPackages.ocaml-lsp;
}
);
devShells = {
default = devShell localPackages pkgs;
release = pkgsWithoutOverlays.mkShell {
buildInputs = [ pkgsWithoutOverlays.dune-release ];
};
fmt = pkgsWithoutOverlays.mkShell {
buildInputs = [
# TODO: get rid of ocaml once dune get format without ocaml being
# present
pkgsWithoutOverlays.ocaml
(ocamlformat pkgsWithoutOverlays)
duneLatest
];
};
check = checkPkgs.mkShell {
inputsFrom = builtins.attrValues checkPackages;
buildInputs = with checkPkgs.ocamlPackages; [
dune_3
base_quickcheck
ppx_expect
ppx_sexp_conv
ocaml-index
(ocamlformat checkPkgs)
];
# Keep Dune RPC Unix socket paths below the platform limit.
shellHook = ''
export TMPDIR=/tmp
'';
};
};
}
));
}