Emacs: Difference between revisions

From NixOS Wiki
imported>Tobias.bora
No edit summary
imported>Aarmn
mNo edit summary
Line 33: Line 33:


=== Emacs overlay ===
=== Emacs overlay ===
For installing one of the unstable branches of emacs, add the following lines to {{ic|/etc/nixos/configuration.nix}} (replace emacsPgtkGcc with the variant of your choice).
For installing one of the unstable branches of emacs, add the following lines to {{ic|/etc/nixos/configuration.nix}} (replace emacsPgtkNativeComp with the variant of your choice).
{{file|configuration.nix|nix|<nowiki>
{{file|configuration.nix|nix|<nowiki>
{
{
Line 47: Line 47:


   environment.systemPackages = with pkgs; [
   environment.systemPackages = with pkgs; [
     emacsPgtkGcc
     emacsPgtkNativeComp
   ];
   ];
}
}
Line 65: Line 65:


=== Packages ===
=== Packages ===
One can mix and match whether Emacs packages are installed by Nix or Emacs. This can be particularly useful for Emacs packages that need to be built, such as vterm. One way to install Emacs packages through Nix is by the following, replacing {{ic|emacsPgtkGcc}} with the variant in use:
One can mix and match whether Emacs packages are installed by Nix or Emacs. This can be particularly useful for Emacs packages that need to be built, such as vterm. One way to install Emacs packages through Nix is by the following, replacing {{ic|emacsPgtkNativeComp}} with the variant in use:


  environment.systemPackages = with pkgs;
  environment.systemPackages = with pkgs;
   [ ...
   [ ...
     ((emacsPackagesFor emacsPgtkGcc).emacsWithPackages (epkgs: [ epkgs.vterm ]))
     ((emacsPackagesFor emacsPgtkNativeComp).emacsWithPackages (epkgs: [ epkgs.vterm ]))
     ...
     ...
   ];
   ];


To make the packages available to {{ic|emacsclient}}, one can do the following:
To make the packages available to {{ic|emacsclient}}, one can do the following:
  services.emacs.package = with pkgs; ((emacsPackagesFor emacsPgtkGcc).emacsWithPackages (epkgs: [ epkgs.vterm ]));
  services.emacs.package = with pkgs; ((emacsPackagesFor emacsPgtkNativeComp).emacsWithPackages (epkgs: [ epkgs.vterm ]));


Note that some packages may have strange characters like <code>+</code> that would be considered as a syntax error by nix. To avoid that, make sure to write it in quotes and to prepend it with the package set that you want l (even if you used <code>with epkgs; …</code>) like <code>epkgs."ido-completing-read+"</code>.
Note that some packages may have strange characters like <code>+</code> that would be considered as a syntax error by nix. To avoid that, make sure to write it in quotes and to prepend it with the package set that you want l (even if you used <code>with epkgs; …</code>) like <code>epkgs."ido-completing-read+"</code>.

Revision as of 10:58, 23 October 2022

For reference use the emacs chapter in the nixos manual.

About

Emacs is an interactive graphical emacs lisp interpreter that comes with many applications, but is primarily used as a text and code editor. It has one of the largest repositories of packages of any similar code editor such as vim or its fork neovim.

Features

Emacs is often valued as a general purpose programming environment. Its power comes from its

  • Extensibility
  • Automatic self-documenting behaviour
  • Flexibility
  • Syntax awareness
  • language server protocol support
  • potential for reproducible portable literate configurations
Warning: Certain issues are possible, when mixing different versions of Emacs, in particular a configuration file tailored towards emacs with native compilation, may misbehave on non-native compiling versions, unless only the emacs lisp code is shared between them.

Emacs or emacs-gtk

Note that since 2022-09, the package called emacs is now installing the lucid toolkit instead of gtk. The reason is that emacs is less stable with gtk especially in daemon mode. However, the lucid flavor of emacs will not take into account the gtk theme (since it is not even gtk) and looks quite… ugly (see comparisons here). If you still prefer the gtk version of emacs, you can install instead emacs-gtk (before 2022-09 this package does not exist and emacs defaults to the gtk version)

Unstable branches

As of July 2021, the Nix community offers 7 variants of GNU Emacs as overlays: emacsGit, emacsNativeComp (formerly emacsGcc), emacsPgtk, emacsPgtkNativeComp (formerly emacsPgtkGcc), emacsUnstable, emacsGit-nox, and emacsUnstable-nox.

Pure GTK

Offers better integration with wayland compositors, in particular, there's better support for sharing the kill ring contents with the system clipboard.

GCC

Branches offer a means for automatic, asynchronous native compilation of emacs lisp into native code, that is then transparently used whenver the original versions of the functions are requested.

Installation

Emacs overlay

For installing one of the unstable branches of emacs, add the following lines to /etc/nixos/configuration.nix (replace emacsPgtkNativeComp with the variant of your choice).

configuration.nix
{
  services.emacs.package = pkgs.emacsPgtkGcc;

  nixpkgs.overlays = [
    (import (builtins.fetchGit {
      url = "https://github.com/nix-community/emacs-overlay.git";
      ref = "master";
      rev = "bfc8f6edcb7bcf3cf24e4a7199b3f6fed96aaecf"; # change the revision
    }))
  ];

  environment.systemPackages = with pkgs; [
    emacsPgtkNativeComp
  ];
}

Flakes

Using a system flake, one can specify the specific revision of the overlay as a flake input, for example:

inputs.emacs-overlay.url = "github:nix-community/emacs-overlay/da2f552d133497abd434006e0cae996c0a282394";

This can then be used in the system configuration by using the self argument:

nixpkgs.overlays = [ (import self.inputs.emacs-overlay) ];

Doom Emacs

The Doom Emacs project provides a framework with a better default configuration and modules for different programming languages. Since it uses pinning in its configuration for dependencies, it is possible to package Doom Emacs with nix (see nix-doom-emacs)

Packages

One can mix and match whether Emacs packages are installed by Nix or Emacs. This can be particularly useful for Emacs packages that need to be built, such as vterm. One way to install Emacs packages through Nix is by the following, replacing emacsPgtkNativeComp with the variant in use:

environment.systemPackages = with pkgs;
  [ ...
    ((emacsPackagesFor emacsPgtkNativeComp).emacsWithPackages (epkgs: [ epkgs.vterm ]))
    ...
  ];

To make the packages available to emacsclient, one can do the following:

services.emacs.package = with pkgs; ((emacsPackagesFor emacsPgtkNativeComp).emacsWithPackages (epkgs: [ epkgs.vterm ]));

Note that some packages may have strange characters like + that would be considered as a syntax error by nix. To avoid that, make sure to write it in quotes and to prepend it with the package set that you want l (even if you used with epkgs; …) like epkgs."ido-completing-read+".