Skip to content

Conversation

Patryk27
Copy link
Member

@Patryk27 Patryk27 commented Feb 10, 2025

This commit introduces an eshell-aware nix command that allows to run nix develop and nix shell that extend the current eshell session instead of spawning an external process.

Closes #164.

@nvimtor
Copy link

nvimtor commented Feb 11, 2025

Sweet, definitely trying this out.

@ayys
Copy link

ayys commented Feb 11, 2025

lovely, just what I needed. Will definitely try it out later today.

update: it works fine for me. I did not notice any obvious issues. I tried it on a couple of repositories, both medium sized (~500k loc each) and nix develop, nix shell both worked as expected.

I love it!

@nvimtor
Copy link

nvimtor commented Feb 11, 2025

Hi! I have an issue where the first nix shell command works, but every subsequent nix shell (or develop) command doesn't.

I am not really good at Elisp but I added a few debugs to try and figure out what is going on:

https://gist.github.com/nvimtor/2c9ef0a8fabd669385589956bb9ef2db

then I got these logs:

DEBUG: eshell/nix called with args: ("shell" "nixpkgs#just")
DEBUG: Running nix-command-eshell with args: ("shell" "nixpkgs#just")
DEBUG: Entering nix-command-eshell with args: ("shell" "nixpkgs#just")
DEBUG: Spawning nix process with args: ("shell" "nixpkgs#just")
DEBUG: Temporary file created: /var/folders/9b/xxz26xk12pj432cnfkvmh6_h0000gn/T/nixOeYWs3
DEBUG: Executing command: nix shell nixpkgs#just --command sh -c export > /var/folders/9b/xxz26xk12pj432cnfkvmh6_h0000gn/T/nixOeYWs3
DEBUG: Process sentinel triggered for process: nix with status: finished

DEBUG: Process nix has command: nil
DEBUG: Process nix is no longer live. Deleting temporary file: /var/folders/9b/xxz26xk12pj432cnfkvmh6_h0000gn/T/nixOeYWs3

it seems the cmd I get from (cmd (car (eshell-commands-for-process proc)) is nil and that causes the file not to be parsed.

Removing the check for cmd here

(when (and cmd (buffer-live-p buffer) (eq 0 (process-exit-status proc)))

makes it work flawlessly.

@Patryk27
Copy link
Member Author

but every subsequent nix shell (or develop) command doesn't.

Ah, you mean like running nix shell twice in a row?

@nvimtor
Copy link

nvimtor commented Feb 12, 2025

@Patryk27

not necessarily; if I exit the first shell and then try to spawn a new one, the same happens. I also realized that some eshell buffers work consistently, some don't work at all! But the "issue" is always the same: cmd being nil.

Curious, are you using direnv as well?

@Patryk27
Copy link
Member Author

I am, but I think I didn't actually test it in this case - I'll take a look, thanks for reporting 🙂

@knazarov
Copy link

knazarov commented Feb 14, 2025

Having this + eat will be great. It's the main thing that prevents me from using eshell, because we rely on Nix at my job to build projects, and nix develop is what I use to start an interactive session for a particular repo.

@nvimtor
Copy link

nvimtor commented Feb 14, 2025

@knazarov sure you know this but envrc-mode + use flake works amazingly well

@Patryk27
Copy link
Member Author

Status: I think I've found the culprit, should have the fixed version today; as an extra, I'm implementing support for nested shells (e.g. running nix shell twice and bringing both applications into scope, not just the last one).

@Patryk27
Copy link
Member Author

Patryk27 commented Feb 16, 2025

Okie, ready! Changes:

  • Added support for envrc,
  • Added support for eshell-syntax-highlighting (it will now correctly mark commands within Nix shell using a green font),
  • Added support for nested shells (nix shell 'nixpkgs#foo' followed by nix shell 'nixpkgs#bar' will bring both packages into scope),
  • exit will now cd into the directory where nix was run, simulating a nested shell better (can be customized via nix-command-eshell-exit-behavior).

(btw, this package is compatible with eat as well -- as in no eat-specific changes are needed, it just works.)

@knazarov
Copy link

@knazarov sure you know this but envrc-mode + use flake works amazingly well

From what I understand, envrc-related things don't properly work with shell aliases, but mostly with env variables. In projects I'm working on this leads to subtle bugs. The only solution that will work universally is to actually run the commands in the proper nix subshell (which I hope this pull request is about).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nix-eshell doesn't play well with flake.nix
4 participants