Emacs: Difference between revisions

Pigs (talk | contribs)
m Advanced: defaultEditor is only an option for services.emacs, not programs.emacs
Pigs (talk | contribs)
Configuration: provide a clearer list of possible ways to configure emacs
 
(One intermediate revision by the same user 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:
<syntaxhighlight lang="nix">
 
# Example for /etc/nixos/configuration.nix
{{file|/etc/nixos/configuration.nix|nix|
<nowiki>
environment.systemPackages = [
environment.systemPackages = [
   pkgs.emacs
   pkgs.emacs
];
];
</nowiki>
}}


# User-specific installation (in ~/.config/nixpkgs/home.nix)
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
];
];
</syntaxhighlight>
</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 ==
{{Note|Currently, configuring Emacs is possible by using Home Manager. A workaround for a global configuration is highlighted in the advanced section.}}


==== Basic ====
==== NixOS System Configuration ====
<syntaxhighlight lang="nix">
 
programs.emacs = {
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;
};
};
</syntaxhighlight>
</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.


==== Advanced ====
A minimal configuration that installs Emacs alongside <code>nix-mode</code> and <code>nixfmt</code> packages:
<syntaxhighlight lang="nix">
# Global Configuration
# Emacs is running as a daemon here, accesible via the "emacsclient" command
services.emacs = {
  enable = true;
  package = pkgs.emacs;
};


# Home Configuration
{{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)
   '';
   '';
};
};
</syntaxhighlight>
</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 ==