nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1# - The csdp program used for the Micromega tactic is statically referenced.
2# However, rocq can build without csdp by setting it to null.
3# In this case some Micromega tactics will search the user's path for the csdp program and will fail if it is not found.
4# - The exact version can be specified through the `version` argument to
5# the derivation; it defaults to the latest stable version.
6
7{
8 lib,
9 stdenv,
10 fetchzip,
11 fetchurl,
12 writeText,
13 pkg-config,
14 customOCamlPackages ? null,
15 ocamlPackages_4_14,
16 ncurses,
17 csdp ? null,
18 version,
19 rocq-version ? null,
20}@args:
21let
22 lib = import ../../../../build-support/rocq/extra-lib.nix { inherit (args) lib; };
23
24 release = {
25 "9.0.0".sha256 = "sha256-GRwYSvrJGiPD+I82gLOgotb+8Ra5xHZUJGcNwxWqZkU=";
26 "9.1+rc1".sha256 = "sha256-GShKHQ9EdvyNe9WlkzF6KLYybc5dPeVrh4bpkVy6pY4=";
27 };
28 releaseRev = v: "V${v}";
29 fetched =
30 import ../../../../build-support/coq/meta-fetch/default.nix
31 {
32 inherit
33 lib
34 stdenv
35 fetchzip
36 fetchurl
37 ;
38 }
39 {
40 inherit release releaseRev;
41 location = {
42 owner = "coq";
43 repo = "coq";
44 };
45 }
46 args.version;
47 version = fetched.version;
48 rocq-version =
49 args.rocq-version or (if version != "dev" then lib.versions.majorMinor version else "dev");
50 csdpPatch = lib.optionalString (csdp != null) ''
51 substituteInPlace plugins/micromega/sos.ml --replace-warn "; csdp" "; ${csdp}/bin/csdp"
52 substituteInPlace plugins/micromega/coq_micromega.ml --replace-warn "System.is_in_system_path \"csdp\"" "true"
53 '';
54 ocamlPackages = if customOCamlPackages != null then customOCamlPackages else ocamlPackages_4_14;
55 ocamlNativeBuildInputs = [
56 ocamlPackages.ocaml
57 ocamlPackages.findlib
58 ocamlPackages.dune_3
59 ];
60 ocamlPropagatedBuildInputs = [ ocamlPackages.zarith ];
61 self = stdenv.mkDerivation {
62 pname = "rocq";
63 inherit (fetched) version src;
64
65 passthru = {
66 inherit rocq-version;
67 inherit ocamlPackages ocamlNativeBuildInputs;
68 inherit ocamlPropagatedBuildInputs;
69 emacsBufferSetup = pkgs: ''
70 ; Propagate rocq paths to children
71 (inherit-local-permanent coq-prog-name "${self}/bin/rocq repl")
72 (inherit-local-permanent coq-dependency-analyzer "${self}/bin/rocq dep")
73 (inherit-local-permanent coq-compiler "${self}/bin/rocq c")
74 ; If the coq-library path was already set, re-set it based on our current rocq
75 (when (fboundp 'get-coq-library-directory)
76 (inherit-local-permanent coq-library-directory (get-coq-library-directory))
77 (coq-prog-args))
78 (mapc (lambda (arg)
79 (when (file-directory-p (concat arg "/lib/coq/${rocq-version}/user-contrib"))
80 (setenv "ROCQPATH" (concat (getenv "ROCQPATH") ":" arg "/lib/coq/${rocq-version}/user-contrib")))) '(${
81 lib.concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)
82 }))
83 ; TODO Abstract this pattern from here and nixBufferBuilders.withPackages!
84 (defvar nixpkgs--rocq-buffer-count 0)
85 (when (eq nixpkgs--rocq-buffer-count 0)
86 (make-variable-buffer-local 'nixpkgs--is-nixpkgs-rocq-buffer)
87 (defun nixpkgs--rocq-inherit (buf)
88 (inherit-local-inherit-child buf)
89 (with-current-buffer buf
90 (setq nixpkgs--rocq-buffer-count (1+ nixpkgs--rocq-buffer-count))
91 (add-hook 'kill-buffer-hook 'nixpkgs--decrement-rocq-buffer-count nil t))
92 buf)
93 ; When generating a scomint buffer, do inherit-local inheritance and make it a nixpkgs-rocq buffer
94 (defun nixpkgs--around-scomint-make (orig &rest r)
95 (if nixpkgs--is-nixpkgs-rocq-buffer
96 (progn
97 (advice-add 'get-buffer-create :filter-return #'nixpkgs--rocq-inherit)
98 (apply orig r)
99 (advice-remove 'get-buffer-create #'nixpkgs--rocq-inherit))
100 (apply orig r)))
101 (advice-add 'scomint-make :around #'nixpkgs--around-scomint-make)
102 ; When we have no more rocq buffers, tear down the buffer handling
103 (defun nixpkgs--decrement-rocq-buffer-count ()
104 (setq nixpkgs--rocq-buffer-count (1- nixpkgs--rocq-buffer-count))
105 (when (eq nixpkgs--rocq-buffer-count 0)
106 (advice-remove 'scomint-make #'nixpkgs--around-scomint-make)
107 (fmakunbound 'nixpkgs--around-scomint-make)
108 (fmakunbound 'nixpkgs--rocq-inherit)
109 (fmakunbound 'nixpkgs--decrement-rocq-buffer-count))))
110 (setq nixpkgs--rocq-buffer-count (1+ nixpkgs--rocq-buffer-count))
111 (add-hook 'kill-buffer-hook 'nixpkgs--decrement-rocq-buffer-count nil t)
112 (setq nixpkgs--is-nixpkgs-rocq-buffer t)
113 (inherit-local 'nixpkgs--is-nixpkgs-rocq-buffer)
114 '';
115 };
116
117 nativeBuildInputs = [ pkg-config ] ++ ocamlNativeBuildInputs;
118 buildInputs = [ ncurses ];
119
120 propagatedBuildInputs = ocamlPropagatedBuildInputs;
121
122 postPatch = ''
123 UNAME=$(type -tp uname)
124 RM=$(type -tp rm)
125 substituteInPlace tools/beautify-archive --replace-warn "/bin/rm" "$RM"
126 ${csdpPatch}
127 '';
128
129 setupHook = writeText "setupHook.sh" ''
130 addRocqPath () {
131 if test -d "''$1/lib/coq/${rocq-version}/user-contrib"; then
132 export ROCQPATH="''${ROCQPATH-}''${ROCQPATH:+:}''$1/lib/coq/${rocq-version}/user-contrib/"
133 fi
134 }
135
136 addEnvHooks "$targetOffset" addRocqPath
137 '';
138
139 preConfigure = ''
140 patchShebangs dev/tools/
141 '';
142
143 prefixKey = "-prefix ";
144
145 enableParallelBuilding = true;
146
147 createFindlibDestdir = true;
148
149 buildPhase = ''
150 runHook preBuild
151 make dunestrap
152 dune build -p rocq-runtime,rocq-core -j $NIX_BUILD_CORES
153 runHook postBuild
154 '';
155
156 installPhase = ''
157 runHook preInstall
158 dune install --prefix $out rocq-runtime rocq-core
159 ln -s $out/lib/rocq-runtime $OCAMLFIND_DESTDIR/rocq-runtime
160 ln -s $out/lib/rocq-core $OCAMLFIND_DESTDIR/rocq-core
161 runHook postInstall
162 '';
163
164 meta = with lib; {
165 description = "Rocq Prover";
166 longDescription = ''
167 The Rocq Prover is an interactive theorem prover, or proof assistant. It provides
168 a formal language to write mathematical definitions, executable
169 algorithms and theorems together with an environment for
170 semi-interactive development of machine-checked proofs.
171 '';
172 homepage = "https://rocq-prover.org";
173 license = licenses.lgpl21;
174 branch = rocq-version;
175 maintainers = with maintainers; [
176 proux01
177 roconnor
178 vbgl
179 Zimmi48
180 ];
181 platforms = platforms.unix;
182 mainProgram = "rocq";
183 };
184 };
185in
186self