summary refs log tree commit diff
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2016-10-07 10:31:37 -0400
committerShea Levy <shea@shealevy.com>2016-10-07 10:31:37 -0400
commiteca0f17ad20e9604a60efa57c7fa717ee2c8f1b7 (patch)
tree870caa66f96c5b8da71e271b4e6a1bfa893fa38b
parentdaf4e57577d0e67c9f4e92d172d3cc83b8c6b82d (diff)
downloadnixpkgs-eca0f17ad20e9604a60efa57c7fa717ee2c8f1b7.tar
nixpkgs-eca0f17ad20e9604a60efa57c7fa717ee2c8f1b7.tar.gz
nixpkgs-eca0f17ad20e9604a60efa57c7fa717ee2c8f1b7.tar.bz2
nixpkgs-eca0f17ad20e9604a60efa57c7fa717ee2c8f1b7.tar.lz
nixpkgs-eca0f17ad20e9604a60efa57c7fa717ee2c8f1b7.tar.xz
nixpkgs-eca0f17ad20e9604a60efa57c7fa717ee2c8f1b7.tar.zst
nixpkgs-eca0f17ad20e9604a60efa57c7fa717ee2c8f1b7.zip
nix-buffer support improvements.
Use inherit-local, add per-package elisp hooks.
-rw-r--r--pkgs/applications/science/logic/coq/default.nix20
-rw-r--r--pkgs/build-support/cc-wrapper/default.nix15
-rw-r--r--pkgs/build-support/emacs/buffer.nix48
-rw-r--r--pkgs/top-level/all-packages.nix2
4 files changed, 69 insertions, 16 deletions
diff --git a/pkgs/applications/science/logic/coq/default.nix b/pkgs/applications/science/logic/coq/default.nix
index 38ba14e83cf..6c421117807 100644
--- a/pkgs/applications/science/logic/coq/default.nix
+++ b/pkgs/applications/science/logic/coq/default.nix
@@ -14,8 +14,8 @@ 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
 
+self =
 stdenv.mkDerivation {
   name = "coq-${version}";
 
@@ -62,6 +62,22 @@ stdenv.mkDerivation {
     envHooks=(''${envHooks[@]} addCoqPath)
   '';
 
+  passthru = {
+    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))
+      ; Pass proof-general's coq flags to flycheck command (pretty ugly, should probably be part of PG)
+      (inherit-local-permanent flycheck-command-wrapper-function (lambda (cmd)
+        (append (funcall (default-value 'flycheck-command-wrapper-function) cmd) (coq-coqtop-prog-args coq-load-path))))
+    '';
+  };
+
   meta = with stdenv.lib; {
     description = "Formal proof management system";
     longDescription = ''
@@ -76,4 +92,4 @@ stdenv.mkDerivation {
     maintainers = with maintainers; [ roconnor thoughtpolice vbgl ];
     platforms = platforms.unix;
   };
-}
+}; in self
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index 8a746ea016e..8a9bd3ecb4d 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -46,7 +46,20 @@ stdenv.mkDerivation {
   inherit cc shell libc_bin libc_dev libc_lib binutils_bin coreutils_bin;
   gnugrep_bin = if nativeTools then "" else gnugrep;
 
-  passthru = { inherit libc nativeTools nativeLibc nativePrefix isGNU isClang; };
+  passthru = {
+    inherit libc nativeTools nativeLibc nativePrefix isGNU isClang;
+
+    emacsBufferSetup = pkgs: ''
+      ; We should handle propagation here too
+      (mapc (lambda (arg)
+        (when (file-directory-p (concat arg "/include"))
+          (setenv "NIX_CFLAGS_COMPILE" (concat (getenv "NIX_CFLAGS_COMPILE") " -isystem " arg "/include")))
+        (when (file-directory-p (concat arg "/lib"))
+          (setenv "NIX_LDFLAGS" (concat (getenv "NIX_LDFLAGS") " -L" arg "/lib")))
+        (when (file-directory-p (concat arg "/lib64"))
+          (setenv "NIX_LDFLAGS" (concat (getenv "NIX_LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
+    '';
+  };
 
   buildCommand =
     ''
diff --git a/pkgs/build-support/emacs/buffer.nix b/pkgs/build-support/emacs/buffer.nix
index 5632eae944c..e366fd1f739 100644
--- a/pkgs/build-support/emacs/buffer.nix
+++ b/pkgs/build-support/emacs/buffer.nix
@@ -1,23 +1,47 @@
 # Functions to build elisp files to locally configure emcas buffers.
 # See https://github.com/shlevy/nix-buffer
 
-{ lib, writeText }:
+{ lib, writeText, inherit-local }:
 
 {
   withPackages = pkgs: let
-      coqs = builtins.filter (x: (builtins.parseDrvName x.name).name == "coq") pkgs;
-      coq = builtins.head coqs;
-      pg-setup = if builtins.length coqs == 0 then "" else ''
-        (setq-local coq-prog-name "${coq}/bin/coqtop")
-        (setq-local coq-dependency-analyzer "${coq}/bin/coqdep")
-        (setq-local coq-compiler "${coq}/bin/coqc")
-	(setq-local coq-library-directory (get-coq-library-directory))
-	(coq-prog-args)
-      '';
+      extras = map (x: x.emacsBufferSetup pkgs) (builtins.filter (builtins.hasAttr "emacsBufferSetup") pkgs);
     in writeText "dir-locals.el" ''
+      (require 'inherit-local "${inherit-local}/share/emacs/site-lisp/elpa/inherit-local-${inherit-local.version}/inherit-local.elc")
+
+      ; Only set up nixpkgs buffer handling when we have some buffers active
+      (defvar nixpkgs--buffer-count 0)
+      (when (eq nixpkgs--buffer-count 0)
+        ; When generating a new temporary buffer (one whose name starts with a space), do inherit-local inheritance and make it a nixpkgs buffer
+        (defun nixpkgs--around-generate (orig name)
+          (if (eq (aref name 0) ?\s)
+              (let ((buf (funcall orig name)))
+                (when (inherit-local-inherit-child buf)
+                  (with-current-buffer buf
+                    (make-local-variable 'kill-buffer-hook)
+                    (setq nixpkgs--buffer-count (1+ nixpkgs--buffer-count))
+                    (add-hook 'kill-buffer-hook 'nixpkgs--decrement-buffer-count)))
+                buf)
+            (funcall orig name)))
+        (advice-add 'generate-new-buffer :around #'nixpkgs--around-generate)
+        ; When we have no more nixpkgs buffers, tear down the buffer handling
+        (defun nixpkgs--decrement-buffer-count ()
+          (setq nixpkgs--buffer-count (1- nixpkgs--buffer-count))
+          (when (eq nixpkgs--buffer-count 0)
+            (advice-remove 'generate-new-buffer #'nixpkgs--around-generate)
+            (fmakunbound 'nixpkgs--around-generate)
+            (fmakunbound 'nixpkgs--decrement-buffer-count))))
+      (setq nixpkgs--buffer-count (1+ nixpkgs--buffer-count))
+      (make-local-variable 'kill-buffer-hook)
+      (add-hook 'kill-buffer-hook 'nixpkgs--decrement-buffer-count)
+
+      ; Add packages to PATH and exec-path
       (make-local-variable 'process-environment)
+      (put 'process-environment 'permanent-local t)
+      (inherit-local 'process-environment)
       (setenv "PATH" (concat "${lib.makeSearchPath "bin" pkgs}:" (getenv "PATH")))
-      (setq-local exec-path (append '(${builtins.concatStringsSep " " (map (p: "\"${p}/bin\"") pkgs)}) exec-path))
-      ${pg-setup}
+      (inherit-local-permanent exec-path (append '(${builtins.concatStringsSep " " (map (p: "\"${p}/bin\"") pkgs)}) exec-path))
+
+      ${lib.concatStringsSep "\n" extras}
     '';
 }
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 71fb0899a28..c96a10136af 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -287,7 +287,7 @@ in
       inherit kernel rootModules allowMissing;
     };
 
-  nixBufferBuilders = import ../build-support/emacs/buffer.nix { inherit (pkgs) lib writeText; };
+  nixBufferBuilders = import ../build-support/emacs/buffer.nix { inherit (pkgs) lib writeText; inherit (emacsPackagesNg) inherit-local; };
 
   pathsFromGraph = ../build-support/kernel/paths-from-graph.pl;