Provide an eshell-aware `nix` command
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.
Sweet, definitely trying this out.
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!
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.
but every subsequent nix shell (or develop) command doesn't.
Ah, you mean like running nix shell twice in a row?
@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?
I am, but I think I didn't actually test it in this case - I'll take a look, thanks for reporting 🙂
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.
@knazarov sure you know this but envrc-mode + use flake works amazingly well
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).
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 bynix shell 'nixpkgs#bar'will bring both packages into scope), exitwill nowcdinto the directory wherenixwas run, simulating a nested shell better (can be customized vianix-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 sure you know this but envrc-mode +
use flakeworks 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).