From 834cffac952e50750bffcbbe1058d8c679393bc9 Mon Sep 17 00:00:00 2001
From: Julien Girard <julien.girard2@cea.fr>
Date: Mon, 18 Sep 2023 17:45:53 +0200
Subject: [PATCH] [doc] Documented Nix build.

---
 README.md            | 24 +++++++++++++++++++++-
 doc/installation.rst | 48 ++++++++++++++++++++++++++++++++++++++++++++
 flake.nix            |  3 +--
 3 files changed, 72 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 4754783..4b7c5fc 100644
--- a/README.md
+++ b/README.md
@@ -49,9 +49,31 @@ To run the CAISAR [Docker](https://www.docker.com/) image, do the following:
 docker run -it laiser/caisar:pub sh
 ```
 
+### Nix flake
+A CAISAR Nix flake allow for reproducible build, and setting up a development
+environment. It requires Nix version 2.15 or higher as well as enabling flakes.
+Please refer to the official Nix [documentation](https://nixos.wiki/wiki/Flakes#Temporary) to enable Nix flakes.
+
+Assuming you have Nix installed and are at the CAISAR repository root, you can
+build CAISAR using the following command:
+
+```
+nix build
+```
+
+You can setup a development environment with all CAISAR dependencies
+included using [nix develop](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-develop.html).
+It will contain the ocaml toolchain already setup and installed,
+and the ocaml language server and formatter. You can thus compile and test
+CAISAR in an isolated shell using the following command:
+
+```
+nix develop
+```
+
 ### From source code
 
-**Please note:** CAISAR requires the OCaml package manager [opam](https://opam.ocaml.org/),
+**Please note:** building CAISAR from source requires the OCaml package manager [opam](https://opam.ocaml.org/),
 v2.1 or higher, which is typically avaible in all major GNU/Linux distributions.
 
 To build and install CAISAR, do the following:
diff --git a/doc/installation.rst b/doc/installation.rst
index b5df738..62199f9 100644
--- a/doc/installation.rst
+++ b/doc/installation.rst
@@ -53,6 +53,54 @@ To run the CAISAR Docker image, do the following:
 
    $ docker run -it laiser/caisar:pub sh
 
+Install through Nix
+-------------------
+
+This method requires Nix (version 2.15 or above) to be installed on your system.
+
+From Nixpkgs
+************
+
+CAISAR is currently not directly available on Nixpkgs. This should change for
+the future release.
+
+Using Nix flake
+***************
+
+A CAISAR `flake <https://nixos.wiki/wiki/Flakes>`_ is available at the root of
+CAISAR directory. At the time of writing, flakes are still considered
+experimental by NixOS. Hence, to use it, you will need to enable them following
+the official Nix `instructions <https://nixos.wiki/wiki/Flakes#Temporary>`_.
+
+Assuming you have Nix installed and are at the CAISAR repository root, you can
+build CAISAR using the following command:
+
+.. code-block:: console
+
+   $ nix build
+
+.. warning ::
+   This command will fetch the Nixpkg registry for all build dependencies.
+   This will result in several megabytes download. Make sure you have
+   a stable network connexion before attempting building through Nix.
+
+The CAISAR binary will reside in ``result/bin/caisar``. The manual will be under ``result/share/doc/ocaml4.14.1-caisar-0.2.0/``.
+
+You can run the CAISAR test suite using the following command:
+
+.. code-block:: console
+
+   $ nix flake check
+
+You can setup a development environment with all CAISAR dependencies included using
+`nix develop
+<https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-develop.html>`_.
+It will contain the ocaml toolchain already setup and installed, and the ocaml language server and formatter. You can thus compile and test CAISAR in an isolated shell.
+
+.. code-block :: console
+
+   $ nix develop
+
 Compile from source
 -------------------
 
diff --git a/flake.nix b/flake.nix
index 653336b..6e53abe 100644
--- a/flake.nix
+++ b/flake.nix
@@ -34,8 +34,7 @@
     in
     rec {
       packages = rec {
-        <<<<<<< HEAD
-          default = self.packages.${system}.caisar;
+        default = self.packages.${system}.caisar;
         # CAISAR package; includes binary and documentation
         caisar = ocamlPkgs.buildDunePackage
           {
-- 
GitLab