forked from ocaml/ocaml-lsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
221 lines (213 loc) · 6.51 KB
/
flake.nix
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
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
opam-nix = {
url = "github:tweag/opam-nix";
inputs.opam-repository.follows = "opam-repository";
};
opam-repository = {
url = "github:ocaml/opam-repository";
flake = false;
};
};
outputs = { self, flake-utils, opam-nix, opam-repository, nixpkgs, ... }@inputs:
let
package = "ocaml-lsp-server";
overlay = final: prev: {
${package} = prev.${package}.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 -r vendor/csexp vendor/pp
'';
};
in
{
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;
});
};
in
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { overlays = [ overlay ]; inherit system; };
inherit (pkgs.ocamlPackages) buildDunePackage;
fast = rec {
# these packages do not use opam2nix
jsonrpc = buildDunePackage {
pname = "jsonrpc";
version = "n/a";
src = ./.;
duneVersion = "3";
propagatedBuildInputs = with pkgs.ocamlPackages; [ ];
doCheck = false;
};
lsp = buildDunePackage {
pname = "lsp";
version = "n/a";
src = ./.;
duneVersion = "3";
propagatedBuildInputs = with pkgs.ocamlPackages; [
jsonrpc
yojson
stdune
ppx_yojson_conv_lib
uutf
];
checkInputs = with pkgs.ocamlPackages; [ cinaps ppx_expect ];
doCheck = false;
};
ocaml-lsp = buildDunePackage {
pname = "ocaml-lsp";
version = "n/a";
src = ./.;
duneVersion = "3";
checkInputs = with pkgs.ocamlPackages; [ ppx_expect ];
propagatedBuildInputs = with pkgs.ocamlPackages; [
ocamlc-loc
octavius
dune-build-info
re
dune-rpc
chrome-trace
dyn
fiber
xdg
ordering
spawn
pp
csexp
ocamlformat-rpc-lib
stdune
yojson
ppx_yojson_conv_lib
uutf
lsp
odoc-parser
merlin-lib
];
doCheck = false;
};
};
on = opam-nix.lib.${system};
localPackages = {
jsonrpc = "*";
lsp = "*";
ocaml-lsp-server = "*";
};
devPackages = {
menhir = "*";
ppx_yojson_conv = "*";
cinaps = "*";
ppx_expect = "*";
ocamlfind = "1.9.2";
};
packagesFromNames = set:
(builtins.map (s: builtins.getAttr s scope)
(builtins.attrNames set));
allPackages = localPackages // devPackages;
scope =
(
let
scope =
on.buildOpamProject
{
repos = [ opam-repository ];
inherit pkgs;
resolveArgs = { with-test = true; };
}
package
./.
(allPackages);
in
scope.overrideScope' overlay
);
opam2nixPackages = nixpkgs.lib.filterAttrs (name: value: builtins.hasAttr name localPackages) scope;
in
{
packages =
opam2nixPackages //
rec {
# we have a package without opam2nix for easy consumption for nix users
default = pkgs.ocamlPackages.buildDunePackage {
pname = package;
version = "n/a";
src = ./.;
duneVersion = "3";
buildInputs = with pkgs.ocamlPackages; [
ocamlc-loc
odoc-parser
dune-build-info
re
dune-rpc
chrome-trace
dyn
fiber
xdg
ordering
spawn
pp
csexp
ocamlformat-rpc-lib
stdune
yojson
ppx_yojson_conv_lib
uutf
lsp
merlin-lib
];
propagatedBuildInputs = [ ];
doCheck = false;
buildPhase = ''
runHook preBuild
dune build ${package}.install --release ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
runHook postBuild
'';
meta = {
mainProgram = "ocamllsp";
};
};
ocaml-lsp = fast.ocaml-lsp;
};
devShells = {
opam2nix = pkgs.mkShell {
buildInputs = (with pkgs;
[
# dev tools
ocamlformat_0_24_1
yarn
dune-release
]) ++ packagesFromNames devPackages;
inputsFrom = packagesFromNames opam2nixPackages;
};
default = pkgs.mkShell {
buildInputs = (with pkgs;
[
# dev tools
ocamlformat_0_24_1
yarn
dune-release
ocamlPackages.ppx_expect
ocamlPackages.utop
ocamlPackages.cinaps
ocamlPackages.ppx_yojson_conv
]);
inputsFrom = [ fast.ocaml-lsp fast.jsonrpc fast.lsp ];
};
};
});
}