doc: add ocaml end user doc to nixpkgs manual (#145100)

doc: add ocaml end user doc to nixpkgs manual

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Co-authored-by: Dmitry Kalinkin <dmitry.kalinkin@gmail.com>

authored by Guillaume Girol Sandro Dmitry Kalinkin and committed by GitHub dbfd2672 df7a1fb7

+26
+26
doc/languages-frameworks/ocaml.section.md
··· 1 # OCaml {#sec-language-ocaml} 2 3 OCaml libraries should be installed in `$(out)/lib/ocaml/${ocaml.version}/site-lib/`. Such directories are automatically added to the `$OCAMLPATH` environment variable when building another package that depends on them or when opening a `nix-shell`. 4 5 Given that most of the OCaml ecosystem is now built with dune, nixpkgs includes a convenience build support function called `buildDunePackage` that will build an OCaml package using dune, OCaml and findlib and any additional dependencies provided as `buildInputs` or `propagatedBuildInputs`.
··· 1 # OCaml {#sec-language-ocaml} 2 3 + ## User guide {#sec-language-ocaml-user-guide} 4 + 5 + OCaml libraries are available in attribute sets of the form `ocaml-ng.ocamlPackages_X_XX` where X is to be replaced with the desired compiler version. For example, ocamlgraph compiled with OCaml 4.12 can be found in `ocaml-ng.ocamlPackages_4_12.ocamlgraph`. The compiler itself is also located in this set, under the name `ocaml`. 6 + 7 + If you don't care about the exact compiler version, `ocamlPackages` is a top-level alias pointing to a recent version of OCaml. 8 + 9 + OCaml applications are usually available top-level, and not inside `ocamlPackages`. Notable exceptions are build tools that must be built with the same compiler version as the compiler you intend to use like `dune` or `ocaml-lsp`. 10 + 11 + To open a shell able to build a typical OCaml project, put the dependencies in `buildInputs` and add `ocamlPackages.ocaml` and `ocamlPackages.findlib` to `nativeBuildInputs` at least. 12 + For example: 13 + ```nix 14 + let 15 + pkgs = import <nixpkgs> {}; 16 + # choose the ocaml version you want to use 17 + ocamlPackages = pkgs.ocaml-ng.ocamlPackages_4_12; 18 + in 19 + pkgs.mkShell { 20 + # build tools 21 + nativeBuildInputs = with ocamlPackages; [ ocaml findlib dune_2 ocaml-lsp ]; 22 + # dependencies 23 + buildInputs = with ocamlPackages; [ ocamlgraph ]; 24 + } 25 + ``` 26 + 27 + ## Packaging guide {#sec-language-ocaml-packaging} 28 + 29 OCaml libraries should be installed in `$(out)/lib/ocaml/${ocaml.version}/site-lib/`. Such directories are automatically added to the `$OCAMLPATH` environment variable when building another package that depends on them or when opening a `nix-shell`. 30 31 Given that most of the OCaml ecosystem is now built with dune, nixpkgs includes a convenience build support function called `buildDunePackage` that will build an OCaml package using dune, OCaml and findlib and any additional dependencies provided as `buildInputs` or `propagatedBuildInputs`.