Ocaml and Nixos

Hello I’m noob on both Nixos and Ocaml. I tried to import a module and run the code simply with ocaml.

open Re

I have this flake.nix inspired from a template.

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let pkgs = nixpkgs.legacyPackages.${system};
      in {
        packages.hello = pkgs.openRe;

        devShell = pkgs.mkShell { buildInputs = [
            pkgs.dune_3
            pkgs.ocamlPackages.re
            pkgs.ocaml
          ]; };
      });
}

What is missing to make the .ml code working please ?
I want to favor the simplest solution first. Like in C language that only needs a option in the command to include a header. The tools such findlib or Dune should be used if there is no alternative.
Sorry for the very noob question, I learn better with minimal working examples.

You need to bring in at least findlib.

buildInputs = [
  pkgs.ocaml
  pkgs.ocamlPackages.findlib
  ...
]

If you don’t want to use dune for now, then ocamlfind ocamlc should do the job. I forget how to use those commands though.

See if this flake helps:

1 Like