[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Combining Guix, direnv and Emacs for environment customisation
From: |
Ludovic Courtès |
Subject: |
Re: Combining Guix, direnv and Emacs for environment customisation |
Date: |
Tue, 30 May 2017 17:03:26 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) |
Hi Christopher!
Christopher Baines <address@hidden> skribis:
> 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
This is pretty cool!
However, using ‘guix environment --search-paths’ is kinda unsafe: the
items mentioned in its output are not protected from GC. This is why
‘guix environment’ normally spawns a shell or some other process while
keep its guix-daemon session open.
> 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
I think it’d be great Emacs-Guix could do something similar, i.e.,
associate a ‘guix environment’ to a buffer. :-)
> 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 agree that we could do a lot more things with a faster ‘guix
environment’. My guess is that it won’t be easy to go optimize, and
very hard to go below 1 second. We should profile that and see what can
be done.
Cheers,
Ludo’.