[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Combining Guix, direnv and Emacs for environment customisation
From: |
Christopher Baines |
Subject: |
Combining Guix, direnv and Emacs for environment customisation |
Date: |
Sat, 27 May 2017 12:31:13 +0100 |
Hey,
In summary, using direnv provides a convinient way to manage different
environments created from Guix. There is now support for using direnv
directly from Emacs.
So for a while now I've been using direnv and Guix, but thanks to
recent improvements with the Emacs integration, its now become even
more useful.
direnv [1] is an environment switcher for shells, for example, you want
to have a specific environment variable set when working on a particular
project, you drop a .envrc file in to the relevant directory and
providing direnv is hooked in to your shell, it will get loaded and
unloaded as you move in and out of that directory.
1: https://direnv.net/
While direnv is useful for simple environment variables, guix
environment can output environment variables with the --shell-paths
option. Using guix environment in a .envrc file would look something
like:
eval "$(guix environment --ad-hoc guile --search-paths)"
There is a use_guix helper function in the direnv stdlib [2] that helps
with this, so you can just do:
use guix --ad-hoc guile
2: https://github.com/direnv/direnv/blob/master/stdlib.sh#L574-L586
I've been using direnv and Guix for a while now, but to use both with
Emacs, I've been starting a shell outside of Emacs, navigating to the
relevant directory so that direnv sets up the environment, and then
starting Emacs from the shell such that running programs (e.g. linters,
ruby, ...) from Emacs works within the environment setup through Guix
and direnv.
I've recently become aware of emacs-direnv [3], which provides access
to the functionality of direnv from Emacs. When the global minor mode
is active, this means that moving around between buffers in Emacs can
completely change the environment within Emacs. This had made my
workflow simpler, as I now just open Emacs, and navigate to the
relevant directory, and direnv just works behind the scenes.
3: https://github.com/wbolster/emacs-direnv
One issue with this is that running guix environment from direnv will
slow down switching buffers. To make it a bit more useable, I found
some bash code that caches the results of running commands, and wrapped
that around guix environment when invoked from direnv. This helps speed
things up, but I don't think its useful in the long term.
For this particular use case, it would help if guix environment was
faster, perhaps by doing caching internally? On my system, running guix
environment --ad-hoc guile --search-paths repeatedly takes ~2 seconds,
I haven't looked at what the breakdown of this is yet.
I'd be interested in hearing if anyone does something similar for using
Guix, or if anyone does something different, but to the same effect?
Thanks,
Chris
pgpqPQBYy7Fku.pgp
Description: OpenPGP digital signature
- Combining Guix, direnv and Emacs for environment customisation,
Christopher Baines <=