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.

Add flake.nix to the project

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

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

    The flake.nix contains comments for adding an alternative build system such as GNU Make. If you are trying to build the project, add a required program to the development shell.

  2. Add .envrc:

    Terminal window
    use flake
  3. Allow direnv:

    Terminal window
    direnv allow

Developing

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