Emacs can't run magit commands, cannot run ssh: no such file or directory

I’ve got emacs installed quite nicely. I’m using a flake with the emacs-overlay specifically the emacsPgtkNativeComp one with only vterm and pdf-tools through nixos.

I instead am using my older emacs config with straight.el to declaratively manage packages through that since I’d be able to still use another OS if I needed to.

However, I get the problem coming up in my setup when running a push or pull in magit.

  1 git … pull origin master
error: cannot run ssh: No such file or directory
fatal: unable to fork

Then I also seem to have a problem when using helpful to show a command or variable in emacs.

Error while executing "gzip -c -q -d < /nix/store/gwxh4kiprfn4awg1shy7rf18wmdp8bs5-emacs-pgtk-native-comp-20220506.0/share/emacs/29.0.50/lisp/files.el.gz"

/run/current-system/sw/bin/sh: line 1: gzip: command not found

On top of this Tramp just doesn’t seem to work and I don’t understand that… :man_shrugging:

I thought it was the environment not getting setup right, but within eshell I can run git, ssh, and gzip just fine.

Anyone have any ideas? I’ll post the relevant parts of my config as well…

  services.emacs.package = with pkgs; ((emacsPackagesFor emacsPgtkNativeComp).emacsWithPackages (epkgs: [ epkgs.vterm epkgs.pdf-tools ]));
  nixpkgs.overlays = [

    (import (builtins.fetchTarball {
      url = https://github.com/nix-community/emacs-overlay/archive/master.tar.gz;
      sha256 = "1pd14gigm5bznzd8k88dq9scicw1zqknm87bnqmd0z556g9ir60f";
  services.emacs.enable = true;

Check your exec-path. Nix makes applications available by providing a pretty bespoke one - just look at $PATH in your shell, you can use eshell to look at the environment emacs gets.

Emacs doesn’t by default set up its exec-path to match $PATH exactly, you’ll probably need something like dotfiles/init.el at ba2512ac8858dbc04991cfbe17870a09ca96d22f · TLATER/dotfiles · GitHub.

Besides that, since you’re using the daemon, your systemd service’s path likely won’t match your user’s path, so if you have user-specific applications or path config (very common in the nix world) the system-wide service may need some tweaking. Or use that exact package, it resolves that issue too :slight_smile:

Keep this in mind if you use LSP-mode, by the way, some languages (like rust) make use of build caches, and those often take env variables into account. If your emacs and terminal envs mismatch that can cause rebuilds (so stick to building inside emacs with compile).

Ah, heh, skimmed past that. Yeah, eshell does some shell init. Maybe check the environment variables directly then? I forget what the emacs variable for that was…

Tramp really relies on SSH/sudo/whatever being around, which probably breaks if exec-path isn’t set up correctly.


I think it was that I forgot some variables in exec-path.

I added these lines to fix the issue.

(add-to-list 'exec-path "/home/chris/.nix-profile/bin")
(add-to-list 'exec-path "/etc/profiles/per-user/chris/bin")
(add-to-list 'exec-path "/run/current-system/sw/bin")

In hind sight, I thought I was doing this, but I forgot later in my config, I was overriding that with something else and clearly forgot that was there. Suppose that means I should organize things better so that I don’t forget where to look for that kind of config. Thank you very much!

1 Like