Doom Emacs isues

Noob here, making the switch from Arch to Nixos. I have only a very basic grasp of the Nix language. I have managed to install Nixos from scratch, with flakes, on my laptop, with an i3 window manager. Not doing things “the Nix way” (as I understand it) yet. That is, none of my configs are written in Nix. I have a problem with my doom-emacs setup in particular. At every login, I have to do a rebuild switch or rebuild test to start emacsclient. If I start it by running emacsclient --c -a ‘emacs’, or through the daemon, I get an error saying emacs is not in my path. But when I do a whereis, both the binary and the client are there, in the store. So I tried to set up a systemd service, using the (long!) path to emacs but no luck. Here is the snippet in home.nix:

programs.emacs = {
enable = true;
package = pkgs.emacs;
extraPackages = epkgs: [

And in configuration.nix:

# enable emacs daemon
services.emacs = {
 enable = true;
 defaultEditor = true;
 package = pkgs.emacs; 

I have home manager added as a module to Nixos in my flake which, aside from this and an sddm rice snippet, is very basic.

The system PATH is not picked up by systemd services, and if your scripts reset PATH to /usr/bin or try absolute paths this is the kind of thing you’ll run into.

What commands are you exactly running and what are the exact errors? What systemd service did you write?

This project might also be of interest to you: GitHub - vlaci/nix-doom-emacs: doom-emacs packaged for Nix

This what I am getting:

The program 'emacsclient' is not in your PATH. It is provided by several packages.
You can make it available in an ephemeral shell by typing one of the following:
  nix-shell -p emacs
  nix-shell -p emacs-gtk
  nix-shell -p emacs-nox
  nix-shell -p emacs28-gtk2
  nix-shell -p emacs29
  nix-shell -p emacs29-gtk3
  nix-shell -p emacs29-nox
  nix-shell -p emacs29-pgtk
- (line 1): 
function emacs --wraps emacsclient\ -c\ -a\ \'emacs\' --description alias\ emacs=emacsclient\ -c\ -a\ \'emacs\';  emacsclient -c -a 'emacs' $argv
in function 'emacs' with arguments '-c -a emacs'
╭─    ~/.local/bin ──────────────────────────
╰─❯ which emacs
which: no emacs in (/home/paul/.local/bin:/home/paul/Applications:/home/paul/.emacs.d/bin:/run/wrappers/bin:/home/paul/.nix-profile/bin:/nix/profile/bin:/home/paul/.local/state/nix/profile/bin:/etc/profiles/per-user/paul/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/nix/store/1iwpd4f9i1jmy2mzajfic0pl97qnx559-kitty-0.32.1/bin:/nix/store/27b7dji2svb4dfcram92zvr8dl9zfi0g-imagemagick-7.1.1-27/bin:/nix/store/69pv6agzxy6mn915cp1q0qvs88ffp4vd-ncurses-6.4-dev/bin)
╭─    ~/.local/bin ─────────────────────────────────────────────────────────────────────────────────────────────────────── 19:55:45 

╰─❯ which emacsclient
which: no emacsclient in (/home/paul/.local/bin:/home/paul/Applications:/home/paul/.emacs.d/bin:/run/wrappers/bin:/home/paul/.nix-profile/bin:/nix/profile/bin:/home/paul/.local/state/nix/profile/bin:/etc/profiles/per-user/paul/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/nix/store/1iwpd4f9i1jmy2mzajfic0pl97qnx559-kitty-0.32.1/bin:/nix/store/27b7dji2svb4dfcram92zvr8dl9zfi0g-imagemagick-7.1.1-27/bin:/nix/store/69pv6agzxy6mn915cp1q0qvs88ffp4vd-ncurses-6.4-dev/bin)
   ~/.local/bin ─────────────────────────────────────────────────────────────────────────────────────────────────────── 19:56:29 
╰─❯ whereis emacs
╭─    ~/.local/bin ─────────────────────────────────────────────────────────────────────────────────────────────────────── 19:56:34 
╰─❯ whereis emacsclient
╭─    ~/.local/bin ─

Now after a rebuild test:

─❯ which emacsclient
╭─    /etc/nixos ───────────────────────────────────────────────────────────────────────────────────────────────────────── 19:58:26 
╰─❯ which emacs
╰─❯ whereis emacsclient
emacsclient: /nix/store/54l9nyzr3v9h5dmm92pajg9l0z3lvws6-user-environment/bin/emacsclient /nix/store/57dhp765wamdzhfz9aidmwqqp3czb9pi-system-path/bin/emacsclient
╭─    /etc/nixos ─────────────────────────────────────────────────────────────────────────────────────────────────
──────── 19:59:02 
╰─❯ whereis emacs
emacs: /nix/store/54l9nyzr3v9h5dmm92pajg9l0z3lvws6-user-environment/bin/emacs /nix/store/57dhp765wamdzhfz9aidmwqqp3czb9pi-system-path/bin/emacs

I set up the service as follows:

Description=Emacs text editor 

The astersisks represent paths of the form above taken from the whereis command. Placed the service in

The problem seems to be with home-manager. I added zellij to configuration.nix, did a rebuild switch with no errors but zellij was not found in my path. When I added it to home manager, and repeated the rebuil switch, then it loaded. However, on reboot, I got the same errors as I did with emacs. Total noob observation as I am just getting started with Nix and Nixos, but since in theory the flake "controls"everything, should I be inputting something there about emacs and zellij?

Not 100% sure what’s going on here. My suspicion is that you override your $PATH in your shell init files or such, and that nixos-rebuild switch (or home-manager switch if you run that in standalone mode) re-inject the binaries into your path.

What is your $PATH before you switch?

Don’t do that. Every time you rebuild your configuration that path is supposed to change. You’re already setting up an emacs daemon service with:

So hand-writing a service should not at all be necessary.

I commented out the snippet in my home-manager when I created the service just for the reason you point out, My path is, after login and a rebuild test:

╰─❯ echo $PATH
/home/paul/.local/bin /home/paul/Applications /home/paul/.emacs.d/bin /run/wrappers/bin /home/paul/.nix-profile/bin /nix/profile/bin /home/paul/.local/state/nix/profile/bin /etc/profiles/per-user/paul/bin /nix/var/nix/profiles/default/bin /run/current-system/sw/bin /nix/store/1iwpd4f9i1jmy2mzajfic0pl97qnx559-kitty-0.32.1/bin /nix/store/27b7dji2svb4dfcram92zvr8dl9zfi0g-imagemagick-7.1.1-27/bin /nix/store/69pv6agzxy6mn915cp1q0qvs88ffp4vd-ncurses-6.4-dev/bin

Before the rebuild, I am getting

❯ echo $PATH

so it looks like your hunch is correct. Can you help with a fix?