Back

A Nix function for configuring Emacs

Posted on 2019-07-15

I used to use a small nix function for getting an emacs distribution given a configuration file. I stopped using it; and decided to put it on GitHub before I delete it from my system, hoping someone to find it useful.

let
pkgs = import <nixpkgs> {};
emacsWithConfig = pkgs.callPackage 
  (builtins.fetchTarball "https://github.com/utdemir/emacs-with-config/archive/master.tar.gz")
  {};
in
emacsWithConfig ''
  (require 'use-package)

  (use-package doom-themes
    :config
    (load-theme 'doom-molokai t))

  (use-package undo-tree
    :defer 2
    :init
    (setq undo-tree-visualizer-timestamps t)
    :config
    (global-undo-tree-mode))

  (use-package magit
    :bind
    ("C-x m" . magit-status))
''

The above code will:

  1. Parse the given script to find the use-package usages and collect the required packages.
  2. Use pkgs.emacsWithPackages to get an emacs distribution with the required packages.
  3. Bytecompile the script.
  4. Wrap pkgs.emacs to load given script by default.

It is not terribly useful, since it is just a shorthand syntax for pkgs.emacsWithPackages. But still it makes you not worry about keeping two package lists in sync.

As I said before, I am not using it anymore; so please feel free to fork or vendor it.

You can find the code on https://github.com/utdemir/emacs-with-config.

Back
Powered by Zola.
© Utku Demir, 2019