diff options
Diffstat (limited to 'pkgs/applications/science/logic/coq')
-rw-r--r-- | pkgs/applications/science/logic/coq/default.nix | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/pkgs/applications/science/logic/coq/default.nix b/pkgs/applications/science/logic/coq/default.nix index bc9ba049cd2..fd3655ce9e9 100644 --- a/pkgs/applications/science/logic/coq/default.nix +++ b/pkgs/applications/science/logic/coq/default.nix @@ -26,9 +26,7 @@ let substituteInPlace plugins/micromega/sos.ml --replace "; csdp" "; ${csdp}/bin/csdp" substituteInPlace plugins/micromega/coq_micromega.ml --replace "System.is_in_system_path \"csdp\"" "true" '' else ""; -in - -stdenv.mkDerivation { +self = stdenv.mkDerivation { name = "coq-${version}"; inherit coq-version; @@ -36,6 +34,50 @@ stdenv.mkDerivation { inherit (ocamlPackages) ocaml; passthru = { inherit (ocamlPackages) findlib; + emacsBufferSetup = pkgs: '' + ; Propagate coq paths to children + (inherit-local-permanent coq-prog-name "${self}/bin/coqtop") + (inherit-local-permanent coq-dependency-analyzer "${self}/bin/coqdep") + (inherit-local-permanent coq-compiler "${self}/bin/coqc") + ; If the coq-library path was already set, re-set it based on our current coq + (when (fboundp 'get-coq-library-directory) + (inherit-local-permanent coq-library-directory (get-coq-library-directory)) + (coq-prog-args)) + (mapc (lambda (arg) + (when (file-directory-p (concat arg "/lib/coq/${coq-version}/user-contrib")) + (setenv "COQPATH" (concat (getenv "COQPATH") ":" arg "/lib/coq/${coq-version}/user-contrib")))) '(${stdenv.lib.concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)})) + ; TODO Abstract this pattern from here and nixBufferBuilders.withPackages! + (defvar nixpkgs--coq-buffer-count 0) + (when (eq nixpkgs--coq-buffer-count 0) + (make-variable-buffer-local 'nixpkgs--is-nixpkgs-coq-buffer) + (defun nixpkgs--coq-inherit (buf) + (inherit-local-inherit-child buf) + (with-current-buffer buf + (setq nixpkgs--coq-buffer-count (1+ nixpkgs--coq-buffer-count)) + (add-hook 'kill-buffer-hook 'nixpkgs--decrement-coq-buffer-count nil t)) + buf) + ; When generating a scomint buffer, do inherit-local inheritance and make it a nixpkgs-coq buffer + (defun nixpkgs--around-scomint-make (orig &rest r) + (if nixpkgs--is-nixpkgs-coq-buffer + (progn + (advice-add 'get-buffer-create :filter-return #'nixpkgs--coq-inherit) + (apply orig r) + (advice-remove 'get-buffer-create #'nixpkgs--coq-inherit)) + (apply orig r))) + (advice-add 'scomint-make :around #'nixpkgs--around-scomint-make) + ; When we have no more coq buffers, tear down the buffer handling + (defun nixpkgs--decrement-coq-buffer-count () + (setq nixpkgs--coq-buffer-count (1- nixpkgs--coq-buffer-count)) + (when (eq nixpkgs--coq-buffer-count 0) + (advice-remove 'scomint-make #'nixpkgs--around-scomint-make) + (fmakunbound 'nixpkgs--around-scomint-make) + (fmakunbound 'nixpkgs--coq-inherit) + (fmakunbound 'nixpkgs--decrement-coq-buffer-count)))) + (setq nixpkgs--coq-buffer-count (1+ nixpkgs--coq-buffer-count)) + (add-hook 'kill-buffer-hook 'nixpkgs--decrement-coq-buffer-count nil t) + (setq nixpkgs--is-nixpkgs-coq-buffer t) + (inherit-local 'nixpkgs--is-nixpkgs-coq-buffer) + ''; }; src = fetchurl { @@ -93,4 +135,4 @@ stdenv.mkDerivation { maintainers = with maintainers; [ roconnor thoughtpolice vbgl ]; platforms = platforms.unix; }; -} +}; in self |