Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I do my development in a Nix shell (create a default.nix file in my project root and then 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 via emacs & I don't have access to the programs in my nix-shell (if I were in a Ruby on Rails project for example, and Ruby was declared as a dependency in my default.nix, I would have no syntax highlighting in Spacemacs because the GUI version of Emacs doesn't see my Nix-shell dependencies). If I run :!which ruby, it can't even find the which command.

Right now, I'm running spacemacs via emacs -nw and just using it from the console, but I would really like to be able to use the GUI editor and get the full colorschemes available rather than being limited to the ones that look nice in 256 color mode. It's also quicker for me to switch between the terminal and the editor than between tmux panes or terminal splits 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
    ];
  };
}
like image 989
josiah Avatar asked Oct 17 '15 15:10

josiah


2 Answers

I recommend this nix-shell.el. My fork of it provides some configuration examples. While direnv integration to Emacs works, it is very slow. Not that this is faster, but it happens when you execute M-x nix-shell-activate and so you control when the latency happens. This becomes import if for instance you have a shell.nix in your org-directory for org source blocks in a multi-language environment and do not always want the direnv delay when you are opening an org file. Mario's nix-shell.el should be more widely known. Here is where I discovered it.

like image 79
Joe Avatar answered Oct 03 '22 13:10

Joe


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

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

like image 38
user514156 Avatar answered Oct 03 '22 13:10

user514156