git.iko.soy/typeable/nixpkgs
on master help sign in
nix-buffer support improvements.

Use inherit-local, add per-package elisp hooks.

commiteca0f17ad20e9604a60efa57c7fa717ee2c8f1b7 authorShea Levy <shea@shealevy.com> dateFri 7 Oct 2016, 10:31 (10 years ago) parentdaf4e57
4 files changed+69−16
pkgs/applications/science/logic/coq/default.nix+18−2 pkgs/build-support/cc-wrapper/default.nix+14−1 pkgs/build-support/emacs/buffer.nix+36−12 pkgs/top-level/all-packages.nix+1−1
pkgs/applications/science/logic/coq/default.nix+18−2
@@ -14,8 +14,8 @@ let
1414 substituteInPlace plugins/micromega/sos.ml --replace "; csdp" "; ${csdp}/bin/csdp"
1515 substituteInPlace plugins/micromega/coq_micromega.ml --replace "System.is_in_system_path \"csdp\"" "true"
1616 '' else "";
17−in
1817
18+self =
1919stdenv.mkDerivation {
2020 name = "coq-${version}";
2121
@@ -62,6 +62,22 @@ stdenv.mkDerivation {
6262 envHooks=(''${envHooks[@]} addCoqPath)
6363 '';
6464
65+ passthru = {
66+ emacsBufferSetup = pkgs: ''
67+ ; Propagate coq paths to children
68+ (inherit-local-permanent coq-prog-name "${self}/bin/coqtop")
69+ (inherit-local-permanent coq-dependency-analyzer "${self}/bin/coqdep")
70+ (inherit-local-permanent coq-compiler "${self}/bin/coqc")
71+ ; If the coq-library path was already set, re-set it based on our current coq
72+ (when (fboundp 'get-coq-library-directory)
73+ (inherit-local-permanent coq-library-directory (get-coq-library-directory))
74+ (coq-prog-args))
75+ ; Pass proof-general's coq flags to flycheck command (pretty ugly, should probably be part of PG)
76+ (inherit-local-permanent flycheck-command-wrapper-function (lambda (cmd)
77+ (append (funcall (default-value 'flycheck-command-wrapper-function) cmd) (coq-coqtop-prog-args coq-load-path))))
78+ '';
79+ };
80+
6581 meta = with stdenv.lib; {
6682 description = "Formal proof management system";
6783 longDescription = ''
@@ -76,4 +92,4 @@ stdenv.mkDerivation {
7692 maintainers = with maintainers; [ roconnor thoughtpolice vbgl ];
7793 platforms = platforms.unix;
7894 };
79−}
95+}; in self
pkgs/build-support/cc-wrapper/default.nix+14−1
@@ -46,7 +46,20 @@ stdenv.mkDerivation {
4646 inherit cc shell libc_bin libc_dev libc_lib binutils_bin coreutils_bin;
4747 gnugrep_bin = if nativeTools then "" else gnugrep;
4848
49− passthru = { inherit libc nativeTools nativeLibc nativePrefix isGNU isClang; };
49+ passthru = {
50+ inherit libc nativeTools nativeLibc nativePrefix isGNU isClang;
51+
52+ emacsBufferSetup = pkgs: ''
53+ ; We should handle propagation here too
54+ (mapc (lambda (arg)
55+ (when (file-directory-p (concat arg "/include"))
56+ (setenv "NIX_CFLAGS_COMPILE" (concat (getenv "NIX_CFLAGS_COMPILE") " -isystem " arg "/include")))
57+ (when (file-directory-p (concat arg "/lib"))
58+ (setenv "NIX_LDFLAGS" (concat (getenv "NIX_LDFLAGS") " -L" arg "/lib")))
59+ (when (file-directory-p (concat arg "/lib64"))
60+ (setenv "NIX_LDFLAGS" (concat (getenv "NIX_LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
61+ '';
62+ };
5063
5164 buildCommand =
5265 ''
pkgs/build-support/emacs/buffer.nix+36−12
@@ -1,23 +1,47 @@
11# Functions to build elisp files to locally configure emcas buffers.
22# See https://github.com/shlevy/nix-buffer
33
4−{ lib, writeText }:
4+{ lib, writeText, inherit-local }:
55
66{
77 withPackages = pkgs: let
8− coqs = builtins.filter (x: (builtins.parseDrvName x.name).name == "coq") pkgs;
9− coq = builtins.head coqs;
10− pg-setup = if builtins.length coqs == 0 then "" else ''
11− (setq-local coq-prog-name "${coq}/bin/coqtop")
12− (setq-local coq-dependency-analyzer "${coq}/bin/coqdep")
13− (setq-local coq-compiler "${coq}/bin/coqc")
14− (setq-local coq-library-directory (get-coq-library-directory))
15− (coq-prog-args)
16− '';
8+ extras = map (x: x.emacsBufferSetup pkgs) (builtins.filter (builtins.hasAttr "emacsBufferSetup") pkgs);
179 in writeText "dir-locals.el" ''
10+ (require 'inherit-local "${inherit-local}/share/emacs/site-lisp/elpa/inherit-local-${inherit-local.version}/inherit-local.elc")
11+
12+ ; Only set up nixpkgs buffer handling when we have some buffers active
13+ (defvar nixpkgs--buffer-count 0)
14+ (when (eq nixpkgs--buffer-count 0)
15+ ; When generating a new temporary buffer (one whose name starts with a space), do inherit-local inheritance and make it a nixpkgs buffer
16+ (defun nixpkgs--around-generate (orig name)
17+ (if (eq (aref name 0) ?\s)
18+ (let ((buf (funcall orig name)))
19+ (when (inherit-local-inherit-child buf)
20+ (with-current-buffer buf
21+ (make-local-variable 'kill-buffer-hook)
22+ (setq nixpkgs--buffer-count (1+ nixpkgs--buffer-count))
23+ (add-hook 'kill-buffer-hook 'nixpkgs--decrement-buffer-count)))
24+ buf)
25+ (funcall orig name)))
26+ (advice-add 'generate-new-buffer :around #'nixpkgs--around-generate)
27+ ; When we have no more nixpkgs buffers, tear down the buffer handling
28+ (defun nixpkgs--decrement-buffer-count ()
29+ (setq nixpkgs--buffer-count (1- nixpkgs--buffer-count))
30+ (when (eq nixpkgs--buffer-count 0)
31+ (advice-remove 'generate-new-buffer #'nixpkgs--around-generate)
32+ (fmakunbound 'nixpkgs--around-generate)
33+ (fmakunbound 'nixpkgs--decrement-buffer-count))))
34+ (setq nixpkgs--buffer-count (1+ nixpkgs--buffer-count))
35+ (make-local-variable 'kill-buffer-hook)
36+ (add-hook 'kill-buffer-hook 'nixpkgs--decrement-buffer-count)
37+
38+ ; Add packages to PATH and exec-path
1839 (make-local-variable 'process-environment)
40+ (put 'process-environment 'permanent-local t)
41+ (inherit-local 'process-environment)
1942 (setenv "PATH" (concat "${lib.makeSearchPath "bin" pkgs}:" (getenv "PATH")))
20− (setq-local exec-path (append '(${builtins.concatStringsSep " " (map (p: "\"${p}/bin\"") pkgs)}) exec-path))
21− ${pg-setup}
43+ (inherit-local-permanent exec-path (append '(${builtins.concatStringsSep " " (map (p: "\"${p}/bin\"") pkgs)}) exec-path))
44+
45+ ${lib.concatStringsSep "\n" extras}
2246 '';
2347}
pkgs/top-level/all-packages.nix+1−1
@@ -287,7 +287,7 @@ in
287287 inherit kernel rootModules allowMissing;
288288 };
289289
290− nixBufferBuilders = import ../build-support/emacs/buffer.nix { inherit (pkgs) lib writeText; };
290+ nixBufferBuilders = import ../build-support/emacs/buffer.nix { inherit (pkgs) lib writeText; inherit (emacsPackagesNg) inherit-local; };
291291
292292 pathsFromGraph = ../build-support/kernel/paths-from-graph.pl;
293293