Home Explore Blog CI



nixpkgs

4th chunk of `nixos/modules/services/editors/emacs.md`
6a8d3dcab95a869416144959a26d2a3514be09153c694dce0000000100000850
    # I don't want emacs.desktop file because I only use
    # emacsclient.
    postInstall = (attrs.postInstall or "") + ''
      rm $out/share/applications/emacs.desktop
    '';
  });
in [ /* ... */ ]
```
:::

After building this file as shown in [](#ex-emacsNix), you
will get an GTK 3-based Emacs binary pre-loaded with your favorite packages.

## Running Emacs as a Service {#module-services-emacs-running}

NixOS provides an optional
{command}`systemd` service which launches
[Emacs daemon](https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html)
with the user's login session.

*Source:* {file}`modules/services/editors/emacs.nix`

### Enabling the Service {#module-services-emacs-enabling}

To install and enable the {command}`systemd` user service for Emacs
daemon, add the following to your {file}`configuration.nix`:
```nix
{
  services.emacs.enable = true;
}
```

The {var}`services.emacs.package` option allows a custom
derivation to be used, for example, one created by
`emacsWithPackages`.

Ensure that the Emacs server is enabled for your user's Emacs
configuration, either by customizing the {var}`server-mode`
variable, or by adding `(server-start)` to
{file}`~/.emacs.d/init.el`.

To start the daemon, execute the following:
```ShellSession
$ nixos-rebuild switch  # to activate the new configuration.nix
$ systemctl --user daemon-reload        # to force systemd reload
$ systemctl --user start emacs.service  # to start the Emacs daemon
```
The server should now be ready to serve Emacs clients.

### Starting the client {#module-services-emacs-starting-client}

Ensure that the Emacs server is enabled, either by customizing the
{var}`server-mode` variable, or by adding
`(server-start)` to {file}`~/.emacs`.

To connect to the Emacs daemon, run one of the following:
```
emacsclient FILENAME
emacsclient --create-frame  # opens a new frame (window)
emacsclient --create-frame --tty  # opens a new frame on the current terminal
```

### Configuring the {var}`EDITOR` variable {#module-services-emacs-editor-variable}

<!--<title>{command}`emacsclient` as the Default Editor</title>-->

Title: Running and Configuring Emacs as a Systemd Service on NixOS
Summary
This section describes how to run Emacs as a systemd service on NixOS, enabling the Emacs daemon for a user's login session. It explains how to enable the service in `configuration.nix`, start the daemon, and connect to it using `emacsclient`. It also mentions ensuring the Emacs server is enabled and provides commands to open new frames or connect via the terminal.