nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 187 lines 14 kB view raw view rendered
1# Rocq and rocq packages {#sec-language-rocq} 2 3Note that "The Rocq Prover" (Rocq for short) is the new name of the 4proof assistant formerly known as Coq. The `coq` and `coqPackages` 5derivations currently remain for both older versions of Coq, but also 6some versions of Rocq during the renaming transition. In the latter 7case, the `coq` derivation encompasses the compatibility binaries 8(`coqtop`, `coqc`, etc.) in addition to the `rocq` binary. The packages 9only in `coqPackages` are the ones which currently still depend on these 10compatibility binaries. 11 12## Rocq derivation: `rocq-core` {#rocq-derivation-rocq} 13 14The Rocq derivation is overridable through the `rocq-core.override overrides`, where overrides is an attribute set which contains the arguments to override. We recommend overriding either of the following: 15 16* `version` (optional, defaults to the latest version of Rocq selected for nixpkgs, see `pkgs/top-level/rocq-packages` to witness this choice), which follows the conventions explained in the `rocqPackages` section below, 17* `customOCamlPackages` (optional, defaults to `null`, which lets Rocq choose a version automatically), which can be set to any of the ocaml packages attribute of `ocaml-ng` (such as `ocaml-ng.ocamlPackages_4_14` which is the default for Rocq 9.1 for example). 18* `rocq-version` (optional, defaults to the short version e.g. "9.1"), is a version number of the form "x.y" that indicates which Rocq's version build behavior to mimic when using a source which is not a release. E.g. `rocq-core.override { version = "40be8435e132aab2231a79091f011ebc3e64a753"; rocq-version = "9.1"; }`. 19 20## Creating custom Coq environments with `coq.withPackages` {#coq-withPackages} 21 22The `coq.withPackages` function provides a convenient way to create a Coq environment that includes additional Coq packages. This is similar to how `python.withPackages` works for Python environments. 23 24The function takes a function that receives the Coq package set and returns a list of packages. It returns a wrapped Coq environment where all Coq binaries (`coqtop`, `coqc`, `coqdep`, `coqchk`, `coqide`, etc.) are configured with the appropriate environment variables to find the packages. 25 26### Usage {#coq-withPackages-usage} 27 28Here is an example of creating a Coq environment with specific packages. 29 30```nix 31coq.withPackages ( 32 ps: with ps; [ 33 mathcomp 34 bignums 35 ] 36) 37``` 38 39## Rocq packages attribute sets: `rocqPackages` {#rocq-packages-attribute-sets-rocqpackages} 40 41The recommended way of defining a derivation for a Rocq library, is to use the `rocqPackages.mkRocqDerivation` function, which is essentially a specialization of `mkDerivation` taking into account most of the specifics of Rocq libraries. The following attributes are supported: 42 43* `pname` (required) is the name of the package, 44* `version` (optional, defaults to `null`), is the version to fetch and build, 45 this attribute is interpreted in several ways depending on its type and pattern: 46 * if it is a known released version string, i.e. from the `release` attribute below, the according release is picked, and the `version` attribute of the resulting derivation is set to this release string, 47 * if it is a majorMinor `"x.y"` prefix of a known released version (as defined above), then the latest `"x.y.z"` known released version is selected (for the ordering given by `versionAtLeast`), 48 * if it is a path or a string representing an absolute path (i.e. starting with `"/"`), the provided path is selected as a source, and the `version` attribute of the resulting derivation is set to `"dev"`, 49 * if it is a string of the form `owner:branch` then it tries to download the `branch` of owner `owner` for a project of the same name using the same vcs, and the `version` attribute of the resulting derivation is set to `"dev"`, additionally if the owner is not provided (i.e. if the `owner:` prefix is missing), it defaults to the original owner of the package (see below), 50 * if it is a string of the form `"#N"`, and the domain is github, then it tries to download the current head of the pull request `#N` from github, 51* `defaultVersion` (optional). Rocq libraries may be compatible with some specific versions of Rocq only. The `defaultVersion` attribute is used when no `version` is provided (or if `version = null`) to select the version of the library to use by default, depending on the context. This selection will mainly depend on a `rocq-core` version number but also possibly on other packages versions (e.g. `mathcomp`). If its value ends up to be `null`, the package is marked for removal in end-user `rocqPackages` attribute set. 52* `release` (optional, defaults to `{}`), lists all the known releases of the library and for each of them provides an attribute set with at least a `hash` attribute (you may put the empty string `""` in order to automatically insert a fake hash, this will trigger an error which will allow you to find the correct hash), each attribute set of the list of releases also takes optional overloading arguments for the fetcher as below (i.e.`domain`, `owner`, `repo`, `rev`, `artifact` assuming the default fetcher is used) and optional overrides for the result of the fetcher (i.e. `version` and `src`). 53* `fetcher` (optional, defaults to a generic fetching mechanism supporting github or gitlab based infrastructures), is a function that takes at least an `owner`, a `repo`, a `rev`, and a `hash` and returns an attribute set with a `version` and `src`. 54* `repo` (optional, defaults to the value of `pname`), 55* `owner` (optional, defaults to `"rocq-community"`). 56* `domain` (optional, defaults to `"github.com"`), domains including the strings `"github"` or `"gitlab"` in their names are automatically supported, otherwise, one must change the `fetcher` argument to support them (cf `pkgs/development/rocq-modules/bignums/default.nix` for an example), 57* `releaseRev` (optional, defaults to `(v: v)`), provides a default mapping from release names to revision hashes/branch names/tags, 58* `releaseArtifact` (optional, defaults to `(v: null)`), provides a default mapping from release names to artifact names (only works for github artifact for now), 59* `displayVersion` (optional), provides a way to alter the computation of `name` from `pname`, by explaining how to display version numbers, 60* `namePrefix` (optional, defaults to `[ "rocq-core" ]`), provides a way to alter the computation of `name` from `pname`, by explaining which dependencies must occur in `name`, 61* `nativeBuildInputs` (optional), is a list of executables that are required to build the current derivation, in addition to the default ones (namely `which`, `dune` and `ocaml` depending on whether `useDune`, `useDuneifVersion` and `mlPlugin` are set). 62* `extraNativeBuildInputs` (optional, deprecated), an additional list of derivation to add to `nativeBuildInputs`, 63* `overrideNativeBuildInputs` (optional) replaces the default list of derivation to which `nativeBuildInputs` and `extraNativeBuildInputs` adds extra elements, 64* `buildInputs` (optional), is a list of libraries and dependencies that are required to build and run the current derivation, in addition to the default one `[ rocq-core ]`, 65* `extraBuildInputs` (optional, deprecated), an additional list of derivation to add to `buildInputs`, 66* `overrideBuildInputs` (optional) replaces the default list of derivation to which `buildInputs` and `extraBuildInputs` adds extras elements, 67* `propagatedBuildInputs` (optional) is passed as is to `mkDerivation`, we recommend to use this for Rocq libraries and Rocq plugin dependencies, as this makes sure the paths of the compiled libraries and plugins will always be added to the build environments of subsequent derivation, which is necessary for Rocq packages to work correctly, 68* `mlPlugin` (optional, defaults to `false`). Some extensions (plugins) might require OCaml and sometimes other OCaml packages. Standard dependencies can be added by setting the current option to `true`. For a finer grain control, the `rocq-core.ocamlPackages` attribute can be used in `nativeBuildInputs`, `buildInputs`, and `propagatedBuildInputs` to depend on the same package set Rocq was built against. 69* `useDuneifVersion` (optional, default to `(x: false)` uses Dune to build the package if the provided predicate evaluates to true on the version, e.g. `useDuneifVersion = versions.isGe "1.1"` will use dune if the version of the package is greater or equal to `"1.1"`, 70* `useDune` (optional, defaults to `false`) uses Dune to build the package if set to true, the presence of this attribute overrides the behavior of the previous one. 71* `opam-name` (optional, defaults to concatenating with a dash separator the components of `namePrefix` and `pname`), name of the Dune package to build. 72* `enableParallelBuilding` (optional, defaults to `true`), since it is activated by default, we provide a way to disable it. 73* `extraInstallFlags` (optional), allows to extend `installFlags` which initializes the variables `COQLIBINSTALL` and `COQPLUGININSTALL` so as to install in the proper subdirectory. Indeed Rocq libraries should be installed in `$(out)/lib/coq/${rocq-core.rocq-version}/user-contrib/`. Such directories are automatically added to the `$ROCQPATH` environment variable by the hook defined in the Rocq derivation. 74* `setROCQBIN` (optional, defaults to `true`), by default, the environment variable `$ROCQBIN` is set to the current Rocq's binary, but one can disable this behavior by setting it to `false`, 75* `useMelquiondRemake` (optional, default to `null`) is an attribute set, which, if given, overloads the `preConfigurePhases`, `configureFlags`, `buildPhase`, and `installPhase` attributes of the derivation for a specific use in libraries using `remake` as set up by Guillaume Melquiond for `flocq`, `gappalib`, `interval`, and `coquelicot` (see the corresponding derivation for concrete examples of use of this option). For backward compatibility, the attribute `useMelquiondRemake.logpath` must be set to the logical root of the library (otherwise, one can pass `useMelquiondRemake = {}` to activate this without backward compatibility). 76* `dropAttrs`, `keepAttrs`, `dropDerivationAttrs` are all optional and allow to tune which attribute is added or removed from the final call to `mkDerivation`. 77 78It also takes other standard `mkDerivation` attributes, they are added as such, except for `meta` which extends an automatically computed `meta` (where the `platform` is the same as `rocq-core` and the homepage is automatically computed). 79 80Here is a simple package example. It is a pure Rocq library, thus it depends on Rocq. It builds on the Mathematical Components library, thus it also takes some `mathcomp` derivations as `extraBuildInputs`. 81 82```nix 83{ 84 lib, 85 mkRocqDerivation, 86 version ? null, 87 rocq-core, 88 mathcomp, 89 mathcomp-finmap, 90 mathcomp-bigenough, 91}: 92 93mkRocqDerivation { 94 # namePrefix leads to e.g. `name = rocq-core9.1-mathcomp2.5.0-multinomials-2.4.0` 95 namePrefix = [ 96 "rocq-core" 97 "mathcomp" 98 ]; 99 pname = "multinomials"; 100 owner = "math-comp"; 101 inherit version; 102 defaultVersion = 103 let 104 case = rocq: mc: out: { 105 cases = [ 106 rocq-core 107 mc 108 ]; 109 inherit out; 110 }; 111 in 112 with lib.versions; 113 lib.switch 114 [ rocq-core.rocq-version mathcomp.version ] 115 [ 116 (case (range "8.18" "9.1") (range "2.1.0" "2.5.0") "2.4.0") 117 (case (range "8.17" "9.0") (range "2.1.0" "2.3.0") "2.3.0") 118 ] 119 null; 120 release = { 121 "2.4.0".sha256 = "sha256-7zfIddRH+Sl4nhEPtS/lMZwRUZI45AVFpcC/UC8Z0Yo="; 122 "2.3.0".sha256 = "sha256-usIcxHOAuN+f/j3WjVbPrjz8Hl9ac8R6kYeAKi3CEts="; 123 }; 124 125 propagatedBuildInputs = [ 126 mathcomp.boot 127 mathcomp.algebra 128 mathcomp-finmap 129 mathcomp.fingroup 130 mathcomp-bigenough 131 ]; 132 133 meta = { 134 description = "Coq/SSReflect Library for Monoidal Rings and Multinomials"; 135 license = lib.licenses.cecill-c; 136 }; 137} 138``` 139 140## Three ways of overriding Rocq packages {#rocq-overriding-packages} 141 142There are three distinct ways of changing a Rocq package by overriding one of its values: `.override`, `overrideRocqDerivation`, and `.overrideAttrs`. This section explains what sort of values can be overridden with each of these methods. 143 144### `.override` {#rocq-override} 145 146`.override` lets you change arguments to a Rocq derivation. In the case of the `multinomials` package above, `.override` would let you override arguments like `mkRocqDerivation`, `version`, `rocq-core`, `mathcomp`, `mathcom-finmap`, etc. 147 148For example, assuming you have a special `mathcomp` dependency you want to use, here is how you could override the `mathcomp` dependency: 149 150```nix 151multinomials.override { mathcomp = my-special-mathcomp; } 152``` 153 154In Nixpkgs, all Rocq derivations take a `version` argument. This can be overridden in order to easily use a different version: 155 156```nix 157rocqPackages.multinomials.override { version = "1.5.1"; } 158``` 159 160Refer to [](#rocq-packages-attribute-sets-rocqpackages) for all the different formats that you can potentially pass to `version`, as well as the restrictions. 161 162### `overrideRocqDerivation` {#rocq-overrideRocqDerivation} 163 164The `overrideRocqDerivation` function lets you easily change arguments to `mkRocqDerivation`. These arguments are described in [](#rocq-packages-attribute-sets-rocqpackages). 165 166For example, here is how you could locally add a new release of the `multinomials` library, and set the `defaultVersion` to use this release: 167 168```nix 169rocqPackages.lib.overrideRocqDerivation { 170 defaultVersion = "2.0"; 171 release."2.0".hash = "sha256-czoP11rtrIM7+OLdMisv2EF7n/IbGuwFxHiPtg3qCNM="; 172} rocqPackages.multinomials 173``` 174 175### `.overrideAttrs` {#rocq-overrideAttrs} 176 177`.overrideAttrs` lets you override arguments to the underlying `stdenv.mkDerivation` call. Internally, `mkRocqDerivation` uses `stdenv.mkDerivation` to create derivations for Rocq libraries. You can override arguments to `stdenv.mkDerivation` with `.overrideAttrs`. 178 179For instance, here is how you could add some code to be performed in the derivation after installation is complete: 180 181```nix 182rocqPackages.multinomials.overrideAttrs (oldAttrs: { 183 postInstall = oldAttrs.postInstall or "" + '' 184 echo "you can do anything you want here" 185 ''; 186}) 187```