Skip to content

Commit 27227d0

Browse files
committed
flake: remove flake-utils dependency
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 cb06208 commit 27227d0

File tree

3 files changed

+117
-131
lines changed

3 files changed

+117
-131
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 & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,108 @@
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;
9+
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;
22+
});
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+
});
32+
33+
dune-release = prev.dune-release.overrideAttrs (_: {
34+
doCheck = false;
3535
});
36+
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+
});
54+
};
3655
};
37-
in
38-
flake-utils.lib.eachDefaultSystem (system:
39-
let
40-
pkgs = import nixpkgs { overlays = [ overlay ]; inherit system; };
41-
inherit (pkgs.ocamlPackages) buildDunePackage;
42-
fast = rec {
4356

57+
packages = forAllSystems (system:
58+
let
59+
pkgs = nixpkgsFor.${system};
60+
inherit (pkgs.ocamlPackages) buildDunePackage;
61+
in
62+
{
63+
# we have a package without opam2nix for easy consumption for nix users
64+
default = buildDunePackage {
65+
pname = package;
66+
version = "n/a";
67+
src = ./.;
68+
duneVersion = "3";
69+
buildInputs = with pkgs.ocamlPackages; [
70+
ocamlc-loc
71+
astring
72+
camlp-streams
73+
dune-build-info
74+
re
75+
dune-rpc
76+
chrome-trace
77+
dyn
78+
fiber
79+
xdg
80+
ordering
81+
spawn
82+
pp
83+
csexp
84+
ocamlformat-rpc-lib
85+
stdune
86+
yojson
87+
ppx_yojson_conv_lib
88+
uutf
89+
merlin-lib
90+
] ++ [
91+
self.packages.${system}.lsp
92+
];
93+
propagatedBuildInputs = [ ];
94+
doCheck = false;
95+
buildPhase = ''
96+
runHook preBuild
97+
dune build ${package}.install --release ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
98+
runHook postBuild
99+
'';
100+
meta = {
101+
mainProgram = "ocamllsp";
102+
};
103+
};
104+
105+
# stub builds
44106
jsonrpc = buildDunePackage {
45107
pname = "jsonrpc";
46108
version = "n/a";
@@ -56,11 +118,12 @@
56118
src = ./.;
57119
duneVersion = "3";
58120
propagatedBuildInputs = with pkgs.ocamlPackages; [
59-
jsonrpc
60121
yojson
61122
stdune
62123
ppx_yojson_conv_lib
63124
uutf
125+
] ++ [
126+
self.packages.${system}.jsonrpc
64127
];
65128
checkInputs = with pkgs.ocamlPackages; [ cinaps ppx_expect ];
66129
doCheck = false;
@@ -91,81 +154,36 @@
91154
yojson
92155
ppx_yojson_conv_lib
93156
uutf
94-
lsp
95157
astring
96158
camlp-streams
97159
merlin-lib
160+
] ++ [
161+
self.packages.${system}.lsp
98162
];
99163
doCheck = false;
100164
};
101-
};
102-
in
103-
{
104-
packages =
105-
rec {
106-
# we have a package without opam2nix for easy consumption for nix users
107-
default = pkgs.ocamlPackages.buildDunePackage {
108-
pname = package;
109-
version = "n/a";
110-
src = ./.;
111-
duneVersion = "3";
112-
buildInputs = with pkgs.ocamlPackages; [
113-
ocamlc-loc
114-
astring
115-
camlp-streams
116-
dune-build-info
117-
re
118-
dune-rpc
119-
chrome-trace
120-
dyn
121-
fiber
122-
xdg
123-
ordering
124-
spawn
125-
pp
126-
csexp
127-
ocamlformat-rpc-lib
128-
stdune
129-
yojson
130-
ppx_yojson_conv_lib
131-
uutf
132-
lsp
133-
merlin-lib
134-
];
135-
propagatedBuildInputs = [ ];
136-
doCheck = false;
137-
buildPhase = ''
138-
runHook preBuild
139-
dune build ${package}.install --release ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
140-
runHook postBuild
141-
'';
142-
meta = {
143-
mainProgram = "ocamllsp";
144-
};
145-
};
146-
147-
ocaml-lsp = fast.ocaml-lsp;
148-
};
165+
});
149166

150-
devShells = {
167+
devShells = forAllSystems (system:
168+
let pkgs = nixpkgsFor.${system}; in {
151169
default = pkgs.mkShell {
152-
buildInputs = (with pkgs;
153-
[
154-
# dev tools
155-
ocamlformat_0_26_1
156-
yarn
170+
name = package;
171+
inputsFrom = builtins.attrValues self.packages.${system};
172+
buildInputs = with pkgs; [
173+
# dev tools
174+
ocamlformat_0_26_1
175+
yarn
157176

158-
ocamlPackages.ppx_expect
159-
ocamlPackages.utop
160-
ocamlPackages.cinaps
161-
ocamlPackages.ppx_yojson_conv
162-
]);
163-
inputsFrom = [ fast.ocaml-lsp fast.jsonrpc fast.lsp ];
177+
ocamlPackages.ppx_expect
178+
ocamlPackages.utop
179+
ocamlPackages.cinaps
180+
ocamlPackages.ppx_yojson_conv
181+
];
164182
};
165183

166184
release = pkgs.mkShell {
167185
buildInputs = [ pkgs.dune-release ];
168186
};
169-
};
170-
});
187+
});
188+
};
171189
}

0 commit comments

Comments
 (0)