While the github repo for the jane street version of the ocaml compiler is a pretyy straight forward process we all know using nixos can be a little bit different when it comes to getting some things working. There isn’t really anything too significant that I did to get it working, but I did run into some issues and Hopefully I can help cover some of them which will ease the process of getting it running.
You can view the jane street repo here and have a look at the process. We mostly follow it with a few extra steps for nixos.
System setup
My setup is as follows:
- Running NixOS 25.05beta712559.4633a7c72337 (Warbler) x86_64
- using home-manager to manage my dotfiles. You can read this to get started.
- I use fish as my shell and we will see that in home.nix
Installation process
The first thing we need to do to get the jane street switch is to install some of the ocaml tooling. We are going to want opam, dune_3, ocaml. We install this now because we need to add the opam repository for jane street in the next step.
home.packages = with pkgs; [
opam
ocaml
dune_3
....
];
Run home-manager switch and then make sure everything instalsl correctly. We will need to add the jane street repository with extensions now from the github link linked at the top of this page or you can just copy and paste from the code snippet below.
$ opam repo add with-extensions https://github.com/janestreet/opam-repository.git#with-extensions
$ opam repository list
[NOTE] These are the repositories in use by the current switch. Use '--all' to see all configured
repositories.
<><> Repository configuration for switch 5.2.0+flambda2 <><><><><><><><><><><><>
1 with-extensions git+https://github.com/janestreet/opam-repository.git#with-extensions
2 default https://opam.ocaml.org
$ opam update
You should see a repository named with-extensions. This is the part that took a lot of troubleshooting and trial and error. I run with the most minimal stuff I can so you may have some of these installed. we will need all these packages installed for the next command. So Open your home.nix file and add these (you need them accessible so it doesn’t have to be your home.nix).
home.packages = with pkgs; [
opam
ocaml
dune_3
autoconf
gnused
coreutils
gnumake
gcc
gnugrep
gawk
bash
diffutils
which
findutils
rsync
bubblewrap
];
You will need all the above packages when it comes to creating the switch and building the Jane street libraries. i did install bash in system packages, but during this setup I did a no no and had to do a which bash and then ln -s /bin/bash <path to your local bash> because ppxlib calls /bin/bash for a cleanup.sh script and doesn’t use the env bash, but directly calls /bin/bash. Now this part will take a bit, but run the following to create the switch for the jst version:
$ opam switch create 5.2.0+flambda2 --repos with-extensions,default
Hopefully you don’t have any errors and it completes! Then Follow up with:
eval $(opam env --switch 5.2.0+flambda2)
One thing you will want to do is add your init and switch to your interactiveshellinit in home.nix, I run fish as my shell but in home-manager I have interactiveshellinit defined as below
interactiveShellInit = ''
starship init fish | source
set fish_greeting # Disable greeting
if test ! -d ~/.opam
opam init --bare -n
opam repository add with-extensions https://github.com/janestreet/opam-repository.git#with-extensions
opam switch create 5.2.0+flambda2 --repos with-extensions,default
end
eval (opam env --switch 5.2.0+flambda2 --set-switch)
'';
now opening a new shell you should be able to do a version for ocamlc:
❯ ocamlc --version
5.2.0+jst
~
❯
You can now follow the rest of the process on their github to get core, base and all the other jst libraries added! The first ones to add from their github would be some dev tooling
$ opam install ocamlformat.0.26.2+jst merlin.5.2.1-502+jst ocaml-lsp-server.1.19.0+jst utop.2.14.0+jst
That will take a while to complete but afterwards open up utop and you can try something simple or run their example from the github link here
utop # let f : local_ 'a -> 'a = fun x -> x;;
Error: This value escapes its region.
resources
here is a great playlist by richard eisenberg from jane street. Introduction below: