Skip to content
Snippets Groups Projects
Commit f085f2f2 authored by Julien Girard-Satabin's avatar Julien Girard-Satabin
Browse files

Merge branch 'build/nix' into 'master'

Nix support

Closes #30

See merge request laiser/caisar!82
parents c0648aa9 c5de1f5c
No related branches found
No related tags found
No related merge requests found
variables:
CAISAR_VERSION: "0.2.0"
stages: stages:
- build
- test - test
- doc
- make_public - make_public
tests: build:
stage: test stage: build
script:
- nix --extra-experimental-features "nix-command flakes" build
- nix --extra-experimental-features "nix-command flakes" flake check
tags:
- nix-v2
when: always
interruptible: true
# Optional and manual full rebuild using a clean docker image
full_rebuild_and_test:
stage: build
image: ocaml/opam@sha256:013a26ccbaa8344b63274e335e2492c432cec1c3526b9ba888ab151abb2b4c25 image: ocaml/opam@sha256:013a26ccbaa8344b63274e335e2492c432cec1c3526b9ba888ab151abb2b4c25
cache: cache:
key: $CI_COMMIT_REF_SLUG key: $CI_COMMIT_REF_SLUG
...@@ -23,22 +39,30 @@ tests: ...@@ -23,22 +39,30 @@ tests:
- make test-ci - make test-ci
tags: tags:
- docker - docker
when: manual
interruptible: true
test:
stage: test
script:
- nix --extra-experimental-features "nix-command flakes" flake check
tags:
- nix-v2
when: always when: always
interruptible: true interruptible: true
## Manual generation of the documentation ## Manual generation of the documentation
documentation: documentation:
stage: test stage: doc
image: sphinxdoc/sphinx-latexpdf@sha256:f80e48ac46a14736795e561e79a2fa43835a5aaa2cfa4bdc6021d85d329da5f2
script: script:
- make doc - nix --extra-experimental-features "nix-command flakes" build
artifacts: artifacts:
paths: paths:
- doc/_build/html/ - result/share/doc/ocaml4.14.1-caisar-${CAISAR_VERSION}/html
- doc/_build/latex/ - result/share/doc/ocaml4.14.1-caisar-${CAISAR_VERSION}/latex
tags: tags:
- docker - nix-v2
when: manual when: manual
interruptible: true interruptible: true
......
...@@ -49,9 +49,31 @@ To run the CAISAR [Docker](https://www.docker.com/) image, do the following: ...@@ -49,9 +49,31 @@ To run the CAISAR [Docker](https://www.docker.com/) image, do the following:
docker run -it laiser/caisar:pub sh 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 ### 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. v2.1 or higher, which is typically avaible in all major GNU/Linux distributions.
To build and install CAISAR, do the following: To build and install CAISAR, do the following:
......
...@@ -53,6 +53,54 @@ To run the CAISAR Docker image, do the following: ...@@ -53,6 +53,54 @@ To run the CAISAR Docker image, do the following:
$ docker run -it laiser/caisar:pub sh $ 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 Compile from source
------------------- -------------------
......
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nix-filter": {
"locked": {
"lastModified": 1694857738,
"narHash": "sha256-bxxNyLHjhu0N8T3REINXQ2ZkJco0ABFPn6PIe2QUfqo=",
"owner": "numtide",
"repo": "nix-filter",
"rev": "41fd48e00c22b4ced525af521ead8792402de0ea",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "nix-filter",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1694948089,
"narHash": "sha256-d2B282GmQ9o8klc22/Rbbbj6r99EnELQpOQjWMyv0rU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5148520bfab61f99fd25fb9ff7bfbb50dad3c9db",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5148520bfab61f99fd25fb9ff7bfbb50dad3c9db",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nix-filter": "nix-filter",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}
flake.nix 0 → 100644
{
description = "CAISAR Nix flake.";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nix-filter.url = "github:numtide/nix-filter";
nixpkgs.url = github:NixOS/nixpkgs/5148520bfab61f99fd25fb9ff7bfbb50dad3c9db;
};
outputs =
{ self
, flake-utils
, nixpkgs
, nix-filter
, ...
}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
ocamlPkgs = pkgs.ocaml-ng.ocamlPackages_4_14;
lib = pkgs.lib;
sources = {
ocaml = nix-filter.lib {
root = ./.;
include = [
".ocamlformat"
"dune-project"
"Makefile"
(nix-filter.lib.inDirectory "src")
(nix-filter.lib.inDirectory "lib")
(nix-filter.lib.inDirectory "test")
(nix-filter.lib.inDirectory "doc")
];
};
};
in
rec {
packages = rec {
default = self.packages.${system}.caisar;
# CAISAR package; includes binary and documentation
caisar = ocamlPkgs.buildDunePackage
{
pname = "caisar";
version = "0.2.0";
duneVersion = "3";
minimalOCamlVersion = "4.13";
installTargets = "all doc";
src = sources.ocaml;
nativeBuildInputs = [
ocamlPkgs.ocaml-protoc-plugin
pkgs.protobuf
# For documentation
pkgs.sphinxHook
];
sphinxBuilders = [
"html"
"latex"
# TODO: generate pdf automatically
];
buildInputs = with ocamlPkgs;
[
csv
ocplib-endian
zarith
ocamlgraph
ppx_deriving
ppx_deriving_yojson
ppx_inline_test
ocaml-protoc-plugin
re
fpath
dune-site
fmt
logs
cmdliner
yaml
pkgs.why3
];
};
};
checks = {
default =
self.packages.${system}.default.overrideAttrs
(oldAttrs: {
name = "check-${oldAttrs.name}";
dontBuild = true;
dontInstall = true;
doCheck = true;
checkPhase = "make test-ci";
});
};
apps = rec {
default = {
type = "app";
program =
"${self.packages.${system}.default}/bin/caisar";
};
};
devShells = rec {
default = pkgs.mkShell {
name = "CAISAR development shell environment.";
inputsFrom = [ self.packages.${system}.caisar ];
packages = with ocamlPkgs; [ ocamlformat_0_25_1 ocaml-lsp ];
shellHook = ''
echo "Welcome in the development shell for CAISAR."
'';
};
};
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment