···
+
<section xml:id="sec-emacs">
+
<section xml:id="sec-emacs-config">
+
<title>Configuring Emacs</title>
+
The Emacs package comes with some extra helpers to make it easier to
+
configure. <varname>emacsWithPackages</varname> allows you to manage
+
packages from ELPA. This means that you will not have to install
+
that packages from within Emacs. For instance, if you wanted to use
+
<literal>company</literal>, <literal>counsel</literal>,
+
<literal>flycheck</literal>, <literal>ivy</literal>,
+
<literal>magit</literal>, <literal>projectile</literal>, and
+
<literal>use-package</literal> you could use this as a
+
<filename>~/.config/nixpkgs/config.nix</filename> override:
+
packageOverrides = pkgs: with pkgs; {
+
myEmacs = emacsWithPackages (epkgs: (with epkgs.melpaStablePackages; [
+
You can install it like any other packages via <command>nix-env -iA
+
myEmacs</command>. However, this will only install those packages.
+
It will not <literal>configure</literal> them for us. To do this, we
+
need to provide a configuration file. Luckily, it is possible to do
+
this from within Nix! By modifying the above example, we can make
+
Emacs load a custom config file. The key is to create a package that
+
provide a <filename>default.el</filename> file in
+
<filename>/share/emacs/site-start/</filename>. Emacs knows to load
+
this file automatically when it starts.
+
packageOverrides = pkgs: with pkgs; rec {
+
myEmacsConfig = writeText "default.el" ''
+
(package-initialize 'noactivate)
+
(require 'use-package))
+
:bind ("<C-tab>" . company-complete)
+
:commands (company-mode global-company-mode)
+
:commands (counsel-descbinds)
+
:bind (([remap execute-extended-command] . counsel-M-x)
+
("C-x C-f" . counsel-find-file)
+
("C-c g" . counsel-git)
+
("C-c j" . counsel-git-grep)
+
("C-x l" . counsel-locate)
+
("M-y" . counsel-yank-pop)))
+
:config (global-flycheck-mode))
+
:bind (("C-c C-r" . ivy-resume)
+
("C-x C-b" . ivy-switch-buffer)
+
:map ivy-minibuffer-map
+
:if (executable-find "git")
+
:bind (("C-x g" . magit-status)
+
("C-x G" . magit-dispatch-popup))
+
(setq magit-completing-read-function 'ivy-completing-read))
+
(use-package projectile
+
:commands projectile-mode
+
:bind-keymap ("C-c p" . projectile-command-map)
+
(projectile-global-mode))
+
myEmacs = emacsWithPackages (epkgs: (with epkgs.melpaStablePackages; [
+
(runCommand "default.el" {} ''
+
mkdir -p $out/share/emacs/site-lisp
+
cp ${myEmacsConfig} $out/share/emacs/site-lisp/default.el
+
This provides a fairly full Emacs start file. It will load in
+
addition to the user's presonal config. You can always disable it by
+
passing <command>-q</command> to the Emacs command.