Get a version of the Spacemacs / Emacs GUI to recognize the nix-shell environment

I do my development in the Nix shell (I create a default.nix file in my project root directory and run nix-shell . To give me a shell with access to the project dependencies).

Spacemacs is my main editor, but when I try to run the GUI version through emacs & , I do not have access to the programs in my nix shell (for example, if I was in a Ruby on Rails project and Ruby was declared as a dependency in my default.nix , I wouldn’t have syntax highlighting in Spacemacs, because the GUI version of Emacs does not see the dependency on the Nix shell). If I run :!which ruby , it cannot even find which command.

Now I run spacemacs through emacs -nw and just use it from the console, but I would really like to be able to use the GUI editor and get all the colors available, and not be limited to those that look beautiful in 256 color mode. It is also faster for me to switch between a terminal and an editor than between tmux panels or terminal separators to get to my CLI editor.

 with import <nixpkgs> {}; { cannyFreeRadicalEnv = stdenv.mkDerivation rec { name = "rails-project-env"; version = "0.1"; src = ./.; buildInputs = [ stdenv ruby_2_2_2 bundler zlib postgresql94 sqlite zsh git nodejs-0_12 ]; }; } 
+10
source share
3 answers

I was able to fix this problem by running emacs in daemon mode. https://www.emacswiki.org/emacs/EmacsAsDaemon

in the directory with the default.nix parameter: nix-shell . emacs --daemon emacsclient -c -a emacs nix-shell . emacs --daemon emacsclient -c -a emacs

+4
source

You can run your Emacs GUI as

 setsid nix-shell . --command "emacs" &> /dev/null 

Also see discussion of nix-shell integration before flycheck and ghc-mode .


Tip: you can use an alias for this in your .zshrc or .bashrc

 run-nix-emacs () { setsid nix-shell . --command "emacs" &> /dev/null } alias ne='run-nix-emacs' 
+4
source

I recommend this nix-shell.el . My fork of this provides some configuration examples. Although direnv integration with Emacs works, it is very slow. Not that it's faster, but it happens when you execute Mx nix-shell-activ and you control the delay time. This becomes an import if, for example, you have shell.nix in your org directory for org source blocks in a multilingual environment and you do not always want direnv delay when opening the org file. Mario nix-shell.el should be more widely known. This is where I found this.

0
source

All Articles