summary refs log tree commit diff
path: root/doc
diff options
context:
space:
mode:
authorGuillaume Girol <symphorien@users.noreply.github.com>2021-11-16 16:49:17 +0000
committerGitHub <noreply@github.com>2021-11-16 16:49:17 +0000
commitdbfd26724defe3f8a63431e0fe1bf6955cc2f44f (patch)
tree68b76cb1acd8978cf21e76db49d8a5399923931a /doc
parentdf7a1fb7f22e2c71fbb66ad59352db0ecc1908cd (diff)
downloadnixpkgs-dbfd26724defe3f8a63431e0fe1bf6955cc2f44f.tar
nixpkgs-dbfd26724defe3f8a63431e0fe1bf6955cc2f44f.tar.gz
nixpkgs-dbfd26724defe3f8a63431e0fe1bf6955cc2f44f.tar.bz2
nixpkgs-dbfd26724defe3f8a63431e0fe1bf6955cc2f44f.tar.lz
nixpkgs-dbfd26724defe3f8a63431e0fe1bf6955cc2f44f.tar.xz
nixpkgs-dbfd26724defe3f8a63431e0fe1bf6955cc2f44f.tar.zst
nixpkgs-dbfd26724defe3f8a63431e0fe1bf6955cc2f44f.zip
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>
Diffstat (limited to 'doc')
-rw-r--r--doc/languages-frameworks/ocaml.section.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/doc/languages-frameworks/ocaml.section.md b/doc/languages-frameworks/ocaml.section.md
index 5ffc23173d6..d266a032268 100644
--- a/doc/languages-frameworks/ocaml.section.md
+++ b/doc/languages-frameworks/ocaml.section.md
@@ -1,5 +1,31 @@
 # OCaml {#sec-language-ocaml}
 
+## User guide {#sec-language-ocaml-user-guide}
+
+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`.
+
+If you don't care about the exact compiler version, `ocamlPackages` is a top-level alias pointing to a recent version of OCaml.
+
+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`.
+
+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.
+For example:
+```nix
+let
+ pkgs = import <nixpkgs> {};
+ # choose the ocaml version you want to use
+ ocamlPackages = pkgs.ocaml-ng.ocamlPackages_4_12;
+in
+pkgs.mkShell {
+  # build tools
+  nativeBuildInputs = with ocamlPackages; [ ocaml findlib dune_2 ocaml-lsp ];
+  # dependencies
+  buildInputs = with ocamlPackages; [ ocamlgraph ];
+}
+```
+
+## Packaging guide {#sec-language-ocaml-packaging}
+
 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`.
 
 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`.