···
519
+
<section xml:id="sec-emacs">
521
+
<title>Emacs</title>
523
+
<section xml:id="sec-emacs-config">
525
+
<title>Configuring Emacs</title>
528
+
The Emacs package comes with some extra helpers to make it easier to
529
+
configure. <varname>emacsWithPackages</varname> allows you to manage
530
+
packages from ELPA. This means that you will not have to install
531
+
that packages from within Emacs. For instance, if you wanted to use
532
+
<literal>company</literal>, <literal>counsel</literal>,
533
+
<literal>flycheck</literal>, <literal>ivy</literal>,
534
+
<literal>magit</literal>, <literal>projectile</literal>, and
535
+
<literal>use-package</literal> you could use this as a
536
+
<filename>~/.config/nixpkgs/config.nix</filename> override:
541
+
packageOverrides = pkgs: with pkgs; {
542
+
myEmacs = emacsWithPackages (epkgs: (with epkgs.melpaStablePackages; [
556
+
You can install it like any other packages via <command>nix-env -iA
557
+
myEmacs</command>. However, this will only install those packages.
558
+
It will not <literal>configure</literal> them for us. To do this, we
559
+
need to provide a configuration file. Luckily, it is possible to do
560
+
this from within Nix! By modifying the above example, we can make
561
+
Emacs load a custom config file. The key is to create a package that
562
+
provide a <filename>default.el</filename> file in
563
+
<filename>/share/emacs/site-start/</filename>. Emacs knows to load
564
+
this file automatically when it starts.
569
+
packageOverrides = pkgs: with pkgs; rec {
570
+
myEmacsConfig = writeText "default.el" ''
571
+
;; initialize package
574
+
(package-initialize 'noactivate)
576
+
(require 'use-package))
578
+
;; load some packages
580
+
(use-package company
581
+
:bind ("<C-tab>" . company-complete)
582
+
:diminish company-mode
583
+
:commands (company-mode global-company-mode)
586
+
(global-company-mode))
588
+
(use-package counsel
589
+
:commands (counsel-descbinds)
590
+
:bind (([remap execute-extended-command] . counsel-M-x)
591
+
("C-x C-f" . counsel-find-file)
592
+
("C-c g" . counsel-git)
593
+
("C-c j" . counsel-git-grep)
594
+
("C-c k" . counsel-ag)
595
+
("C-x l" . counsel-locate)
596
+
("M-y" . counsel-yank-pop)))
598
+
(use-package flycheck
600
+
:config (global-flycheck-mode))
604
+
:bind (("C-c C-r" . ivy-resume)
605
+
("C-x C-b" . ivy-switch-buffer)
606
+
:map ivy-minibuffer-map
607
+
("C-j" . ivy-call))
615
+
:if (executable-find "git")
616
+
:bind (("C-x g" . magit-status)
617
+
("C-x G" . magit-dispatch-popup))
619
+
(setq magit-completing-read-function 'ivy-completing-read))
621
+
(use-package projectile
622
+
:commands projectile-mode
623
+
:bind-keymap ("C-c p" . projectile-command-map)
626
+
(projectile-global-mode))
628
+
myEmacs = emacsWithPackages (epkgs: (with epkgs.melpaStablePackages; [
629
+
(runCommand "default.el" {} ''
630
+
mkdir -p $out/share/emacs/site-lisp
631
+
cp ${myEmacsConfig} $out/share/emacs/site-lisp/default.el
646
+
This provides a fairly full Emacs start file. It will load in
647
+
addition to the user's presonal config. You can always disable it by
648
+
passing <command>-q</command> to the Emacs command.