Install Ocaml+flambda compiler

I’m currently trying to build a nix expression for a static analysis tool, infer, that has many opam dependencies relying on the ocaml 4.06.1+flambda compiler. Is there a way to install the ocaml+flambda compiler straight from nix rather than compiling it? Currently, I have:

buildInputs = [ ocaml opam_1_2 ... ];
postUnpack = ""
opam init
opam switch 4.06.1+flambda
"";

But manually calling opam switch to configure ocaml can be time-consuming while I’m trying to build.

To get OCaml with flambda enabled, you can call the ocaml package with the argument flambdaSupport = true. Then you can build the set of OCaml packages corresponding to this compiler (using ocaml-ng.mkOcamlPackages). Example:

let o = ocaml.override { flambdaSupport = true; }; in
let oP = ocaml-ng.mkOcamlPackages o (self: super: {}); in
oP.apron

Some dependencies of infer may be missing. Thanks for your contribution!

Update to your solution: See OCaml - NixOS Wiki (due to ocamlPackages: Use lib.makeScope by pukkamustard · Pull Request #53357 · NixOS/nixpkgs · GitHub).