I’m hunting for my perfect web application language (sure to be a future post). So I’ve been exploring OCaml. I prefer Nix for configuring development environments. It keeps things self-contained and increases the chances that I won’t have painful setup issues when I revisit projects months or years later.
I created a flake.nix that configured OCaml and used ocaml-overlay to add Dream to my development environment:
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
| {
description = "Expiments in ocaml";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
ocaml-overlay = {
url = "github:nix-ocaml/nix-overlays";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs@{ self, nixpkgs, flake-parts, ocaml-overlay, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "aarch64-darwin" "x86_64-linux" "aarch64-linux" ];
perSystem = { pkgs, system, inputs', ... }: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
overlays = [
ocaml-overlay.overlays.default
];
};
packages = { };
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
ocaml
ocamlPackages.dune_3
ocamlPackages.findlib
ocamlPackages.ocamlformat
ocamlPackages.ocaml-lsp
ocamlPackages.utop
ocamlPackages.dream
ocamlPackages.dream-html
];
};
};
};
}
|
This got me up and running until I wanted to use the live reload functionality described in the published documentation. Unfortunately, this feature is only present on main not the 1.0.0.0-alpha5 release present in OPAM and ocaml-overlay.