Skip to content

Commit 5065b28

Browse files
committed
nix: devShell for oxcaml
We add 3 new dev shells for OxCaml: - bootstrap-ox: For testing the bootstrap process with OxCaml - ox-minimal: For building dune with OxCaml and running the OxCaml test-cases - ox: For attempting to build a dev shell with OxCaml In order to do this, we need to fetch the latest patches from the OxCaml opam repo, however not all of them can be applied to the package versions found in nixpkgs. Because of this we cannot build a full devShell, but we can get pretty close. The File nix/ox-patches.nix deals with the fetching and application of the patches. Signed-off-by: Ali Caglayan <[email protected]>
1 parent 94c1424 commit 5065b28

File tree

3 files changed

+288
-26
lines changed

3 files changed

+288
-26
lines changed

flake.lock

Lines changed: 95 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 117 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
url = "github:nix-ocaml/nix-overlays";
1111
inputs.nixpkgs.follows = "nixpkgs";
1212
};
13+
oxcaml = {
14+
url = "github:oxcaml/oxcaml";
15+
inputs.nixpkgs.follows = "nixpkgs";
16+
};
17+
oxcaml-opam-repository = {
18+
url = "github:oxcaml/opam-repository";
19+
flake = false;
20+
};
1321
};
1422
outputs =
1523
{
@@ -18,6 +26,8 @@
1826
nixpkgs,
1927
melange,
2028
ocaml-overlays,
29+
oxcaml,
30+
oxcaml-opam-repository,
2131
}:
2232
flake-utils.lib.eachDefaultSystem (
2333
system:
@@ -46,6 +56,13 @@
4656
});
4757
})
4858
];
59+
60+
applyOxcamlPatches = import ./nix/ox-patches.nix {
61+
inherit pkgs;
62+
lib = pkgs.lib;
63+
oxcamlOpamRepo = oxcaml-opam-repository;
64+
};
65+
4966
dune-static-overlay = self: super: {
5067
ocamlPackages = super.ocaml-ng.ocamlPackages_5_3.overrideScope (
5168
oself: osuper: {
@@ -174,10 +191,29 @@
174191
extraBuildInputs ? (pkgs: [ ]),
175192
meta ? null,
176193
duneFromScope ? false,
194+
includeTestDeps ? true,
195+
packageOverrides ? (oself: osuper: { }),
177196
}:
178197
let
198+
hasOcamlOverride = (packageOverrides { } { ocaml = null; }) ? ocaml;
199+
179200
pkgs' =
180-
if duneFromScope then
201+
if hasOcamlOverride then
202+
pkgs.extend (
203+
pself: psuper: {
204+
ocamlPackages = psuper.ocamlPackages.overrideScope (
205+
oself: osuper:
206+
(pkgs.lib.mapAttrs
207+
(name: pkg:
208+
if pkgs.lib.isDerivation pkg && pkg ? overrideAttrs
209+
then pkg.overrideAttrs (old: { doCheck = false; })
210+
else pkg)
211+
osuper)
212+
// (packageOverrides oself osuper)
213+
);
214+
}
215+
)
216+
else if duneFromScope then
181217
pkgs.extend (
182218
pself: psuper: {
183219
ocamlPackages = psuper.ocamlPackages.overrideScope (
@@ -196,39 +232,45 @@
196232
#!${stdenv.shell}
197233
"$DUNE_SOURCE_ROOT"/_boot/dune.exe $@
198234
'';
235+
236+
baseInputs = if includeTestDeps then (testNativeBuildInputs pkgs') ++ docInputs else [ ];
237+
238+
ocamlLibs = if includeTestDeps then
239+
(with pkgs'.ocamlPackages; [
240+
ctypes
241+
cinaps
242+
integers
243+
lwt
244+
mdx
245+
menhir
246+
merlin
247+
ocaml-index
248+
ocaml-lsp
249+
odoc
250+
patdiff
251+
ppx_expect
252+
re
253+
spawn
254+
uutf
255+
])
256+
else
257+
[ ];
199258
in
200259

201260
pkgs'.mkShell {
202261
shellHook = ''
203262
export DUNE_SOURCE_ROOT=$PWD
204263
'';
205264
inherit meta;
206-
nativeBuildInputs = (testNativeBuildInputs pkgs') ++ docInputs ++ [ duneScript ];
207-
inputsFrom = [ pkgs'.ocamlPackages.dune_3 ];
265+
nativeBuildInputs = baseInputs ++ [ duneScript ] ++ (if hasOcamlOverride then [ pkgs'.ocamlPackages.ocaml ] else [ ]);
266+
inputsFrom = if hasOcamlOverride then [ ] else [ pkgs'.ocamlPackages.dune_3 ];
208267
buildInputs =
209-
testBuildInputs
210-
++ (
211-
with pkgs'.ocamlPackages;
212-
[
213-
ctypes
214-
cinaps
215-
integers
216-
lwt
217-
mdx
218-
menhir
219-
merlin
220-
ocaml-index
221-
ocaml-lsp
222-
odoc
223-
patdiff
224-
ppx_expect
225-
re
226-
spawn
227-
uutf
228-
]
229-
++ (extraBuildInputs pkgs')
230-
);
268+
(if includeTestDeps then testBuildInputs else [ ])
269+
++ ocamlLibs
270+
++ (extraBuildInputs pkgs')
271+
++ (if hasOcamlOverride then [ pkgs'.ocamlPackages.findlib ] else [ ]);
231272
inherit INSIDE_NIX;
273+
dontDetectOcamlConflicts = hasOcamlOverride;
232274
};
233275
in
234276
{
@@ -333,6 +375,56 @@
333375
'';
334376
};
335377

378+
bootstrap-ox = pkgs.mkShell {
379+
inherit INSIDE_NIX;
380+
buildInputs = [
381+
pkgs.gnumake
382+
oxcaml.packages.${system}.default
383+
];
384+
meta.description = ''
385+
Provides a minimal shell environment with OxCaml in order to
386+
test the bootstrapping script.
387+
'';
388+
};
389+
390+
ox-minimal = makeDuneDevShell {
391+
includeTestDeps = false;
392+
packageOverrides = oself: osuper:
393+
(applyOxcamlPatches oself osuper) // {
394+
# dune_3 = self.packages.${system}.default;
395+
ocaml = oxcaml.packages.${system}.default.overrideAttrs (old: {
396+
passthru = (old.passthru or { }) // pkgs.ocamlPackages.ocaml.passthru;
397+
meta = (old.meta or { }) // pkgs.ocamlPackages.ocaml.meta;
398+
});
399+
spawn = osuper.spawn.overrideAttrs (old: { doCheck = false; });
400+
};
401+
extraBuildInputs = pkgs: with pkgs.ocamlPackages; [
402+
re
403+
spawn
404+
uutf
405+
findlib
406+
];
407+
meta.description = ''
408+
Provides a minimal shell environment with OxCaml in order to
409+
run the OxCaml tests.
410+
'';
411+
};
412+
413+
ox = makeDuneDevShell {
414+
packageOverrides = oself: osuper:
415+
(applyOxcamlPatches oself osuper) // {
416+
dune_3 = self.packages.${system}.default;
417+
ocaml = oxcaml.packages.${system}.default.overrideAttrs (old: {
418+
passthru = (old.passthru or { }) // pkgs.ocamlPackages.ocaml.passthru;
419+
meta = (old.meta or { }) // pkgs.ocamlPackages.ocaml.meta;
420+
});
421+
};
422+
meta.description = ''
423+
Provides a full shell environment with the OxCaml compiler to
424+
develop with Dune. Warning: does not work.
425+
'';
426+
};
427+
336428
microbench = makeDuneDevShell {
337429
extraBuildInputs = pkgs: [
338430
pkgs.ocamlPackages.core_bench

0 commit comments

Comments
 (0)