[Nix-dev] Announcing nix-buffer, nix-shell for emacs

Shea Levy shea at shealevy.com
Mon Sep 5 14:21:54 CEST 2016


Doubt anyone has managed to start using this yet, but FYI I've changed
the name of the command to just 'nix-buffer'. Will add to nixpkgs once
it's merged into melpa.

Shea Levy <shea at shealevy.com> writes:

> [ Unknown signature status ]
> Hi all,
>
> I've just pushed the initial version of nix-buffer[1], and opened a PR
> for adding it to melpa[2]. The description of the 'nix-buffer-enter'
> command this library defines:
>
>> Set up the buffer according to the directory-local nix expression.
>>
>> Looks for dir-locals.nix upward from the current directory.  If found,
>> builds the derivation defined there with the 'root' arg set to the
>> current buffer file name or directory and evaluates the resulting
>> elisp if safe to do so.
>>
>> Because in practice dir-locals.nix will always want to do things that
>> are unsafe in dir-locals.el (e.g. append to 'exec-path'), we don't
>> reuse that mechanism and instead just load the file as elisp.  Because
>> this allows arbitrary code execution, the first time we're asked to
>> load a particular store path we query the user to verify if it's safe
>> to load beforehand.
>>
>> The Lisp code generated by dir-locals.nix should limit itself to
>> modifying buffer-local variables, but there is no actual enforcement
>> of this.  'setq-local' is your friend.
>
> It may be useful to advise the 'normal-mode' function to call
> 'nix-buffer-enter' beforehand for local files, so that all visited files
> have their environments set up before modes are loaded.
>
> Note that this is my first elisp package, so feedback definitely
> welcome!
>
> In addition to the elisp work mentioned in the TODO[3], it would be
> useful to add some functions to nixpkgs to build elisp files,
> especially:
>
> * A function taking a derivation and building an elisp file that sets up
>   the buffer environment analogous to the build environment specified by
>   that derivation
> * A function taking a list of packages and building an elisp file that
>   sets up the buffer environment with all of those packages available
>   (in PATH, in the emacs load path, etc.).
>
> Happy hacking!
>
> ~Shea
>
> [1]: https://github.com/shlevy/nix-buffer/tree/v1.0
> [2]: https://github.com/melpa/melpa/pull/4204
> [3]: https://github.com/shlevy/nix-buffer/blob/v1.0/TODO.md
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.science.uu.nl/pipermail/nix-dev/attachments/20160905/5e15911a/attachment.sig>


More information about the nix-dev mailing list