Skip to content

Commit 0db7167

Browse files
committed
flake: remove flake-utils dependency + some refactoring
By inlining the for loop from the utility library, downstream consumers do not need to pull in any additional dependencies & bloat their flake.lock files. Some additional reorganizing due to inlining as well —with the net effect of more lines deleted than added.
1 parent 922a726 commit 0db7167

File tree

3 files changed

+117
-168
lines changed

3 files changed

+117
-168
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
- Remove `flake-utils` Nix Flake dependency
4+
35
## Features
46

57
- Introduce a configuration option to control dune diagnostics. The option is

flake.lock

Lines changed: 0 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 115 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,84 @@
11
{
22
inputs = {
3-
flake-utils.url = "github:numtide/flake-utils";
43
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
54
};
65

7-
outputs = { self, flake-utils, nixpkgs, ... }@inputs:
6+
outputs = { self, nixpkgs, ... }@inputs:
87
let
98
package = "ocaml-lsp-server";
10-
overlay = final: prev: {
11-
${package} = prev.${package}.overrideAttrs (_: {
12-
# Do not add share/nix-support, so that dependencies from
13-
# the scope don't leak into dependent derivations
14-
doNixSupport = false;
15-
});
16-
dune-release = prev.dune-release.overrideAttrs (_: {
17-
doCheck = false;
18-
});
19-
ocamlPackages = prev.ocamlPackages.overrideScope' (oself: osuper:
20-
let
21-
fixPreBuild = o: {
22-
propagatedBuildInputs = o.propagatedBuildInputs ++ [ oself.pp ];
23-
preBuild = ''
24-
rm -r vendor/csexp vendor/pp
25-
'';
26-
};
27-
in
28-
{
29-
dyn = osuper.dyn.overrideAttrs fixPreBuild;
30-
dune-private-libs = osuper.dune-private-libs.overrideAttrs fixPreBuild;
31-
dune-glob = osuper.dune-glob.overrideAttrs fixPreBuild;
32-
dune-action-plugin = osuper.dune-action-plugin.overrideAttrs fixPreBuild;
33-
dune-rpc = osuper.dune-rpc.overrideAttrs fixPreBuild;
34-
stdune = osuper.stdune.overrideAttrs fixPreBuild;
35-
});
36-
};
37-
lspPackage = pkgs:
38-
with pkgs.ocamlPackages;
39-
buildDunePackage {
40-
pname = package;
41-
version = "n/a";
42-
src = ./.;
43-
duneVersion = "3";
44-
buildInputs = [
45-
ocamlc-loc
46-
astring
47-
camlp-streams
48-
dune-build-info
49-
re
50-
dune-rpc
51-
chrome-trace
52-
dyn
53-
fiber
54-
xdg
55-
ordering
56-
spawn
57-
pp
58-
csexp
59-
ocamlformat-rpc-lib
60-
stdune
61-
yojson
62-
ppx_yojson_conv_lib
63-
uutf
64-
merlin-lib
65-
];
66-
propagatedBuildInputs = [ ];
67-
doCheck = false;
68-
buildPhase = ''
69-
runHook preBuild
70-
dune build ${package}.install --release ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
71-
runHook postBuild
72-
'';
73-
meta = {
74-
mainProgram = "ocamllsp";
75-
};
76-
};
77-
in
78-
{
79-
overlays.default = (final: prev: {
80-
ocamlPackages = prev.ocamlPackages.overrideScope (oself: osuper:
81-
with oself;
829

83-
{
84-
ocaml-lsp = lspPackage final;
85-
}
86-
);
10+
supportedSystems = [
11+
"aarch64-darwin"
12+
"aarch64-linux"
13+
"x86_64-darwin"
14+
"x86_64-linux"
15+
];
16+
17+
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
18+
19+
nixpkgsFor = forAllSystems (system: import nixpkgs {
20+
inherit system;
21+
overlays = builtins.attrValues self.overlays;
8722
});
88-
} // (flake-utils.lib.eachDefaultSystem (system:
89-
let
90-
pkgs = import nixpkgs { overlays = [ overlay ]; inherit system; };
91-
inherit (pkgs.ocamlPackages) buildDunePackage;
92-
fast = rec {
23+
in
24+
{
25+
overlays = {
26+
default = final: prev: {
27+
${package} = prev.${package}.overrideAttrs (_: {
28+
# Do not add share/nix-support, so that dependencies from
29+
# the scope don't leak into dependent derivations
30+
doNixSupport = false;
31+
});
9332

94-
jsonrpc = buildDunePackage {
95-
pname = "jsonrpc";
96-
version = "n/a";
97-
src = ./.;
98-
duneVersion = "3";
99-
propagatedBuildInputs = with pkgs.ocamlPackages; [ ];
33+
dune-release = prev.dune-release.overrideAttrs (_: {
10034
doCheck = false;
101-
};
35+
});
10236

103-
lsp = buildDunePackage {
104-
pname = "lsp";
105-
version = "n/a";
106-
src = ./.;
107-
duneVersion = "3";
108-
propagatedBuildInputs = with pkgs.ocamlPackages; [
109-
jsonrpc
110-
yojson
111-
stdune
112-
ppx_yojson_conv_lib
113-
uutf
114-
];
115-
checkInputs = with pkgs.ocamlPackages; [ cinaps ppx_expect ];
116-
doCheck = false;
117-
};
37+
ocamlPackages = prev.ocamlPackages.overrideScope' (oself: osuper:
38+
let
39+
fixPreBuild = o: {
40+
propagatedBuildInputs = o.propagatedBuildInputs ++ [ oself.pp ];
41+
preBuild = ''
42+
rm -r vendor/csexp vendor/pp
43+
'';
44+
};
45+
in
46+
{
47+
dyn = osuper.dyn.overrideAttrs fixPreBuild;
48+
dune-private-libs = osuper.dune-private-libs.overrideAttrs fixPreBuild;
49+
dune-glob = osuper.dune-glob.overrideAttrs fixPreBuild;
50+
dune-action-plugin = osuper.dune-action-plugin.overrideAttrs fixPreBuild;
51+
dune-rpc = osuper.dune-rpc.overrideAttrs fixPreBuild;
52+
stdune = osuper.stdune.overrideAttrs fixPreBuild;
53+
ocaml-lsp = self.packages.${prev.system}.ocaml-lsp;
54+
});
55+
};
56+
57+
ocaml-lsp-only = final: prev: {
58+
ocamlPackages = prev.ocamlPackages.overrideScope' (_: _: {
59+
ocaml-lsp = self.packages.${prev.system}.ocaml-lsp;
60+
});
61+
};
62+
};
63+
64+
packages = forAllSystems (system:
65+
let
66+
pkgs = nixpkgsFor.${system};
67+
inherit (pkgs.ocamlPackages) buildDunePackage;
68+
in
69+
{
70+
# we have a package without opam2nix for easy consumption for nix users
71+
default = self.packages.${system}.ocaml-lsp;
11872

11973
ocaml-lsp = buildDunePackage {
120-
pname = "ocaml-lsp";
74+
pname = package;
12175
version = "n/a";
12276
src = ./.;
12377
duneVersion = "3";
124-
checkInputs = with pkgs.ocamlPackages; [ ppx_expect ];
125-
propagatedBuildInputs = with pkgs.ocamlPackages; [
78+
buildInputs = with pkgs.ocamlPackages; [
12679
ocamlc-loc
127-
octavius
80+
astring
81+
camlp-streams
12882
dune-build-info
12983
re
13084
dune-rpc
@@ -141,43 +95,70 @@
14195
yojson
14296
ppx_yojson_conv_lib
14397
uutf
144-
lsp
145-
astring
146-
camlp-streams
14798
merlin-lib
99+
] ++ [
100+
self.packages.${system}.lsp
148101
];
102+
propagatedBuildInputs = [ ];
103+
doCheck = false;
104+
buildPhase = ''
105+
runHook preBuild
106+
dune build ${package}.install --release ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
107+
runHook postBuild
108+
'';
109+
meta = {
110+
mainProgram = "ocamllsp";
111+
};
112+
};
113+
114+
# stub builds
115+
jsonrpc = buildDunePackage {
116+
pname = "jsonrpc";
117+
version = "n/a";
118+
src = ./.;
119+
duneVersion = "3";
120+
propagatedBuildInputs = with pkgs.ocamlPackages; [ ];
149121
doCheck = false;
150122
};
151-
};
152-
in
153-
{
154-
packages =
155-
rec {
156-
# we have a package without opam2nix for easy consumption for nix users
157-
default = lspPackage pkgs;
158123

159-
ocaml-lsp = fast.ocaml-lsp;
124+
lsp = buildDunePackage {
125+
pname = "lsp";
126+
version = "n/a";
127+
src = ./.;
128+
duneVersion = "3";
129+
propagatedBuildInputs = with pkgs.ocamlPackages; [
130+
yojson
131+
stdune
132+
ppx_yojson_conv_lib
133+
uutf
134+
] ++ [
135+
self.packages.${system}.jsonrpc
136+
];
137+
checkInputs = with pkgs.ocamlPackages; [ cinaps ppx_expect ];
138+
doCheck = false;
160139
};
140+
});
161141

162-
devShells = {
142+
devShells = forAllSystems (system:
143+
let pkgs = nixpkgsFor.${system}; in {
163144
default = pkgs.mkShell {
164-
buildInputs = (with pkgs;
165-
[
166-
# dev tools
167-
ocamlformat_0_26_1
168-
yarn
145+
name = package;
146+
inputsFrom = builtins.attrValues self.packages.${system};
147+
buildInputs = with pkgs; [
148+
# dev tools
149+
ocamlformat_0_26_1
150+
yarn
169151

170-
ocamlPackages.ppx_expect
171-
ocamlPackages.utop
172-
ocamlPackages.cinaps
173-
ocamlPackages.ppx_yojson_conv
174-
]);
175-
inputsFrom = [ fast.ocaml-lsp fast.jsonrpc fast.lsp ];
152+
ocamlPackages.ppx_expect
153+
ocamlPackages.utop
154+
ocamlPackages.cinaps
155+
ocamlPackages.ppx_yojson_conv
156+
];
176157
};
177158

178159
release = pkgs.mkShell {
179160
buildInputs = [ pkgs.dune-release ];
180161
};
181-
};
182-
}));
162+
});
163+
};
183164
}

0 commit comments

Comments
 (0)