Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save idontgetoutmuch/1c647e7b207dd5166155775d1213db88 to your computer and use it in GitHub Desktop.

Select an option

Save idontgetoutmuch/1c647e7b207dd5166155775d1213db88 to your computer and use it in GitHub Desktop.
/nix/store/43r2rms3j5y9qclwd4kipbvribkjbr4d-dir-locals.el
(require 'inherit-local "/nix/store/5pgm72fjmkzi09qncvffx18dr9957lds-emacs-inherit-local-1.1.1/share/emacs/site-lisp/elpa/inherit-local-1.1.1/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)
(make-variable-buffer-local 'nixpkgs--is-nixpkgs-buffer)
; 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 (and nixpkgs--is-nixpkgs-buffer (eq (aref name 0) ?\s))
(let ((buf (funcall orig name)))
(progn
(inherit-local-inherit-child buf)
(with-current-buffer buf
(setq nixpkgs--buffer-count (1+ nixpkgs--buffer-count))
(add-hook 'kill-buffer-hook 'nixpkgs--decrement-buffer-count nil t)))
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))
(add-hook 'kill-buffer-hook 'nixpkgs--decrement-buffer-count nil t)
; Add packages to PATH and exec-path
(make-local-variable 'process-environment)
(put 'process-environment 'permanent-local t)
(inherit-local 'process-environment)
; setenv modifies in place, so copy the environment first
(setq process-environment (copy-tree process-environment))
(setenv "PATH" (concat "/nix/store/cz79yxnzsi2262i972pbfgvd93lf9y5k-R-3.4.3/bin:" (getenv "PATH")))
(inherit-local-permanent exec-path (append '("/nix/store/cz79yxnzsi2262i972pbfgvd93lf9y5k-R-3.4.3/bin") exec-path))
(setq nixpkgs--is-nixpkgs-buffer t)
(inherit-local 'nixpkgs--is-nixpkgs-buffer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment