all repos — nixfiles @ 8fc83608b84e7f7d36dcce00e4a43db20f9ca69e

System and user configuration, managed by nix and home-manager

Emacs: Run with pure packages if installed via nix

This is not a perfect method of detection, but if I install emacs via
nix I'm almost certainly going to use my custom derivation.  Checking
the equality of system-name and emacs-build-system makes it more
likely to be correct, as a normal nix emacs build would probably
installed from a pre-built hydra package.
Alan Pearce alan@alanpearce.eu
Tue, 06 Jun 2017 11:42:30 +0200
commit

8fc83608b84e7f7d36dcce00e4a43db20f9ca69e

parent

ae050e529e4b08bcf025e1c4e77a3da5a6c0ef80

1 files changed, 25 insertions(+), 20 deletions(-)

jump to
M emacs/.emacs.d/init.orgemacs/.emacs.d/init.org
@@ -58,28 +58,35 @@ ** Use-package 
 #+BEGIN_SRC emacs-lisp
 (eval-and-compile
+  (defvar nix-emacs (and (string-match "^/nix/store" invocation-directory)
+                         (string-equal emacs-build-system system-name)))
+
   (setq tls-checktrust t
         gnutls-verify-error t
-        package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
-                           ("melpa-stable" . "https://stable.melpa.org/packages/")
-                           ("melpa" . "https://melpa.org/packages/"))
-        package-user-dir (concat "~/.emacs.d/packages/" emacs-version "/elpa")
-        package-pinned-packages '(("use-package" . melpa-stable)
-                                  ("diminish" . melpa-stable)
-                                  ("bind-key" . melpa-stable))
-        package-archive-priorities '(("melpa" . 10)
-                                     ("gnu" . 10)
-                                     ("melpa-stable" . 5)
-                                     ("marmalade" . 0))
         package-menu-async t
+        package-user-dir (concat "~/.emacs.d/packages/" emacs-version "/elpa")
         package-menu-hide-low-priority t)
+  (if nix-emacs
+      (progn (setq package-archives nil)
+             (package-initialize))
+    (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
+                             ("melpa-stable" . "https://stable.melpa.org/packages/")
+                             ("melpa" . "https://melpa.org/packages/"))
+          package-pinned-packages '(("use-package" . melpa-stable)
+                                    ("diminish" . melpa-stable)
+                                    ("bind-key" . melpa-stable))
+          package-archive-priorities '(("melpa" . 10)
+                                       ("gnu" . 10)
+                                       ("melpa-stable" . 5)
+                                       ("marmalade" . 0))))
   (when (eq system-type 'darwin)
     (with-eval-after-load "gnutls"
       (add-to-list 'gnutls-trustfiles "/etc/ssl/cert.pem")))
-  (package-initialize)
-  (unless (package-installed-p 'use-package)
-    (package-refresh-contents)
-    (package-install 'use-package)))
+  (unless nix-emacs
+    (package-initialize)
+    (unless (package-installed-p 'use-package)
+      (package-refresh-contents)
+      (package-install 'use-package))))
 (eval-when-compile (require 'use-package))
 (unless (featurep 'use-package)
   (require 'diminish)
@@ -87,7 +94,7 @@ (require 'bind-key)   (use-package use-package
     :commands (use-package-autoload-keymap)
     :defer 5))
-(setq use-package-always-ensure t
+(setq use-package-always-ensure (not nix-emacs)
       package-enable-at-startup nil)
 #+END_SRC
 
@@ -2077,15 +2084,13 @@ Let’s try using Scala.
 
 #+BEGIN_SRC emacs-lisp
-(use-package scala-mode
-  :pin melpa-stable)
+(use-package scala-mode)
 #+END_SRC
 
 And add ensime, an IDE-style environment.
 
 #+BEGIN_SRC emacs-lisp
-(use-package ensime
-  :pin melpa-stable)
+(use-package ensime)
 #+END_SRC
 
 ** Web development