Set Emacs as default manager

Hello, new NixOS user here.

I’m trying to setup Emacs as my default editor also to be able to use it for quick changed in config files using sudoedit (which by default runs nano).

I’m using Flakes and Home Manager and what I currently have in my home.nix is this:

  # Set Emacs as default editor
  services.emacs = {
    enable = true;
    package = pkgs.emacs;
    client.enable = true;
    defaultEditor = true;
  };
  programs.emacs = {
    enable = true;
    package = pkgs.emacs;
  };

However, this install Emacs, but doesn’t set it as default editor:

~ echo $EDITOR
nano


~ echo $SUDO_EDITOR


Anyone know if I’m missing something or there is another way to override nano as default?

EDIT: For context, I think this documentation is outdated because programs.emacs.defaultEditor does not exist.

Looking at the sources, it looks like it does set an EDITOR session variable. If you cat your session vars is it present? You might need to logout/in to see the new vars.

What do you mean by cat my session variables?
I shared the output of echo and the session hasn’t changed, even after rebooting:

I think you can add this line to your configuration.nix
environment.variables.EDITOR = "emacs";
you’ll probably need to open a new terminal after rebuild.

Your config for emacs should work. Look at $HOME/.nix-profile/etc/profile.d/hm-session-vars.sh
EDITOR should be something like “/nix/store/<hash>-editor”, which is a wrapper script executing emacs-client.

I booted my laptop this morning and Emacs was the default editor. Not sure what I missed. I might have got confused rebuilds and forgot to reboot at some point so didn’t see any change.

Anyhow, it’s working now. Thank you for the help.

1 Like

It actually regressed after another reboot, no idea why, but your suggestion worked. Thank you! :smiley:

1 Like

Cool,
on may 15, someone made a commit to make it work services.emacs.defaultEditor = true
on Darwin. Maybe it’s related ?

1 Like

Oh, it might, thanks for sharing it.