Installing Emacs with Nix

marker Published Jan 14, 2024 Revision: 1

I am trying out emacs once again. This time in earnest, in the past I used Doom Emacs however I used emacs as if it was vim. This time around I want to learn about the emacs ecosystem, write my own config (still using evil mode), and try to build an email workflow in emacs.

Installing

To install Emacs, I found the wiki and manual pages using Kagi:

With Home-Manager

{ pkgs, ... }:
{
  programs.emacs = {
    enable = true;
    package = pkgs.emacs;
  };
}

Without Home-Manager

{ pkgs, ... }:
{
  environment.systemPackages = with pkgs [
    emacs;
  ];
}

Daemon

The Daemon is available for Linux and Darwin. You can also set emacs as your defaultEditor here, but I am keeping mine as nvim for now.

{ pkgs, ... }:
{
  services.emacs = {
    enable = true;
    defaultEditor = true;
  };
}

Emacs Variants

From here there is some nix-inflicted complexity: package can be one of multiple options:

  • emacs
    • Documentation notes this package moved from GTK to Lucid for UI elements for stability and performance.
  • emacs-gtk
    • Provides GTK UI that was previously in normal emacs package.
  • emacs-nox
    • "No X" this package has no GUI
  • emacs-pgtk
    • "Pure GTK" this package renders through GTK instead of X11, good for Wayland users
  • emacsMacport
    • Includes "Mac port" patches for more native MacOS UI

I ended up using Home-Manager to install emacs on Darwin and emacs-pgtk on Linux where I am using Niri at the moment:

{ pkgs, ... }:
{
  programs.emacs = {
    enable = true;
    package = if pkgs.stdenv.hostPlatform.isDarwin then
                pkgs.emacs
              else pkgs.emacs-pgtk;
  };

  services.emacs
}