summary refs log tree commit diff stats
path: root/emacs
diff options
context:
space:
mode:
authorAlan Pearce2017-06-06 11:42:30 +0200
committerAlan Pearce2017-06-06 11:47:04 +0200
commit8fc83608b84e7f7d36dcce00e4a43db20f9ca69e (patch)
tree8325d5947a2ec4f4a06ca4f4a45615377c481162 /emacs
parentae050e529e4b08bcf025e1c4e77a3da5a6c0ef80 (diff)
downloaddotfiles-8fc83608b84e7f7d36dcce00e4a43db20f9ca69e.tar.lz
dotfiles-8fc83608b84e7f7d36dcce00e4a43db20f9ca69e.tar.zst
dotfiles-8fc83608b84e7f7d36dcce00e4a43db20f9ca69e.zip
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.
Diffstat (limited to 'emacs')
-rw-r--r--emacs/.emacs.d/init.org45
1 files changed, 25 insertions, 20 deletions
diff --git a/emacs/.emacs.d/init.org b/emacs/.emacs.d/init.org
index 028efcd..0958b5b 100644
--- a/emacs/.emacs.d/init.org
+++ b/emacs/.emacs.d/init.org
@@ -58,28 +58,35 @@ the buffer to be empty.
 
 #+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 @@ the buffer to be empty.
   (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 @@ really seem to use it.
 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