summary refs log tree commit diff
path: root/pkgs/applications/science
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2017-05-22 00:45:54 -0400
committerShea Levy <shea@shealevy.com>2017-05-22 00:45:54 -0400
commitb1b61d0988a458e7b0bbb75cac4fd12a246a83e1 (patch)
treecb8851b1dc25e0bddb373fba3f08decec288c8c4 /pkgs/applications/science
parentabe0da425bb887df59c6b29aacf1a664b7cd646c (diff)
downloadnixpkgs-b1b61d0988a458e7b0bbb75cac4fd12a246a83e1.tar
nixpkgs-b1b61d0988a458e7b0bbb75cac4fd12a246a83e1.tar.gz
nixpkgs-b1b61d0988a458e7b0bbb75cac4fd12a246a83e1.tar.bz2
nixpkgs-b1b61d0988a458e7b0bbb75cac4fd12a246a83e1.tar.lz
nixpkgs-b1b61d0988a458e7b0bbb75cac4fd12a246a83e1.tar.xz
nixpkgs-b1b61d0988a458e7b0bbb75cac4fd12a246a83e1.tar.zst
nixpkgs-b1b61d0988a458e7b0bbb75cac4fd12a246a83e1.zip
coq: nix-buffer: Inherit variables to PG shell
Diffstat (limited to 'pkgs/applications/science')
-rw-r--r--pkgs/applications/science/logic/coq/default.nix31
1 files changed, 31 insertions, 0 deletions
diff --git a/pkgs/applications/science/logic/coq/default.nix b/pkgs/applications/science/logic/coq/default.nix
index 9faa9d8feb8..fd3655ce9e9 100644
--- a/pkgs/applications/science/logic/coq/default.nix
+++ b/pkgs/applications/science/logic/coq/default.nix
@@ -46,6 +46,37 @@ self = stdenv.mkDerivation {
       (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)
     '';
   };