Skip to content

Adding a Nix-based environment for OCaml

In this tutorial, you will learn how to set up a basic development environment for OCaml. Unlike the ocaml-dune template, this approach is designed to help you explore an existing OCaml codebase. In this setup, ocaml-lsp provides useful hints on type information and navigation. It is easier to set up than the other template, and it should work whether or not the project uses dune.

  1. Initialize the template from the root directory of the project:

    Terminal window
    nix flake init github:akirak/flake-templates#ocaml-basic

    Open flake.nix and review the packages under the default development shell. It contains comments for optional dependencies such as ocamlbuild, GNU Make, and gdb. Depending on the project, you might want to enable some of them.

  2. Add .envrc:

    Terminal window
    use flake
  3. Allow direnv:

    Terminal window
    direnv allow

The template is basic and intended for existing projects. For development, follow instructions specific to your project.