Emacs: Difference between revisions
Warn about double-listing emacs-pgtk. |
→Configuration: provide a clearer list of possible ways to configure emacs |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 30: | Line 30: | ||
To install Emacs system-wide, making it available to all users, add the following to your configuration: | To install Emacs system-wide, making it available to all users, add the following to your configuration: | ||
{{file|/etc/nixos/configuration.nix|nix| | |||
<nowiki> | |||
environment.systemPackages = [ | environment.systemPackages = [ | ||
pkgs.emacs | pkgs.emacs | ||
]; | ]; | ||
</nowiki> | |||
}} | |||
Alternatively, Emacs can be installed specific to a user via [[Home Manager]]: | |||
{{file|home.nix|nix|<nowiki> | |||
home.packages = [ | home.packages = [ | ||
pkgs.emacs | pkgs.emacs | ||
]; | ]; | ||
</ | </nowiki> | ||
}} | |||
After rebuilding your system with <code>nixos-rebuild switch</code> or <code>home-manager switch</code>, Emacs will be installed and accessible. | After rebuilding your system with <code>nixos-rebuild switch</code> or <code>home-manager switch</code>, Emacs will be installed and accessible. | ||
== Configuration == | == Configuration == | ||
==== | ==== NixOS System Configuration ==== | ||
< | |||
System wide configuration of Emacs is limited to only the [https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html Emacs daemon]. To enable Emacs daemon user services system-wide and set as default editor: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
services.emacs = { | |||
enable = true; | enable = true; | ||
defaultEditor = true; | defaultEditor = true; | ||
}; | }; | ||
</ | </nowiki> | ||
}} | |||
==== | Use <code>emacsclient</code> to connect to the daemon. For a full list of module configuration options, see {{nixos:option|services.emacs}}. | ||
==== Home Manager ==== | |||
[[Home Manager]] provides a larger set of user-specific configuration options for Emacs. | |||
A minimal configuration that installs Emacs alongside <code>nix-mode</code> and <code>nixfmt</code> packages: | |||
{{file|home.nix|nix|<nowiki> | |||
programs.emacs = { | programs.emacs = { | ||
enable = true; | enable = true; | ||
package = pkgs.emacs; # replace with pkgs.emacs-gtk if desired | package = pkgs.emacs; # replace with pkgs.emacs-gtk if desired | ||
extraPackages = epkgs: [ | |||
epkgs.nix-mode | |||
epkgs.nixfmt | |||
]; | |||
extraConfig = '' | extraConfig = '' | ||
(setq standard-indent 2) | (setq standard-indent 2) | ||
''; | ''; | ||
}; | }; | ||
</ | </nowiki> | ||
}} | |||
{{note| An alternative option to setting the config inside a Nix string, you can load the config file by <code>extraConfig <nowiki>=</nowiki> builtins.readFile ./emacs_config.el</code>.}} | |||
To search for Emacs plugins within the package set, see {{nixos:package|emacsPackages.*}}. A full list of Home Manager configuration module options can be found [https://home-manager-options.extranix.com/?query=programs.emacs here]. | |||
Home Manager also provides a configuration module for enabling the Emacs daemon: | |||
{{file|home.nix|nix|<nowiki> | |||
# Emacs is running as a daemon here, accesible via the "emacsclient" command | |||
services.emacs = { | |||
enable = true; | |||
defaultEditor = true; | |||
}; | |||
</nowiki> | |||
}} | |||
See [https://home-manager-options.extranix.com/?query=services.emacs the module options] for <code>services.emacs</code> configurations options. | |||
== Tips and Tricks == | == Tips and Tricks == | ||
| Line 104: | Line 134: | ||
</syntaxhighlight>Note that if the expression <code>(emacsPackagesFor emacs-pgtk)</code> is present, <code>emacs-pgtk</code> need not be listed separately in the list <code>environment.systemPackages</code>. Indeed, if one does that, <code>nixos-rebuild</code> will warn about link collisions when the configuration is rebuilt. | </syntaxhighlight>Note that if the expression <code>(emacsPackagesFor emacs-pgtk)</code> is present, <code>emacs-pgtk</code> need not be listed separately in the list <code>environment.systemPackages</code>. Indeed, if one does that, <code>nixos-rebuild</code> will warn about link collisions when the configuration is rebuilt. | ||
====== Alternative way of installation to ensuring consistent package management for emacs and emacsclient ====== | |||
If you plan to use the same packages for both emacs and emacsclient, you can define a custom emacs like this: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
nixpkgs.config.packageOverrides = pkgs: rec { | |||
myEmacs = pkgs.emacs.pkgs.withPackages (epkgs: with epkgs; [ | |||
org | |||
nixmode | |||
... # list all your desired emacsPackages here | |||
]); | |||
}; | |||
</nowiki>}} | |||
You may then reference it twice: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
## if you want it per-user instead of system-wide use 'users.users.<name>.packages = with pkgs; [' instead | |||
environment.systemPackages = with pkgs; [ | |||
myEmacs | |||
]; | |||
## enabling emacsclient and making all the packages available | |||
services.emacs = { | |||
enable = true; | |||
package = pkgs.myEmacs; | |||
}; | |||
</nowiki>}} | |||
Using this approach, there is no need to keep two lists of emacsPackages in sync. | |||
==== Tree-sitter ==== | ==== Tree-sitter ==== | ||