Sure! In my .emacs, I have: > (defun nix-buffer-find-file-hook () > (when (not (file-remote-p (buffer-file-name))) > (nix-buffer))) > (add-hook 'find-file-hook 'nix-buffer-find-file-hook)
I have coq 8.5pl1 installed in my configuration.nix, but I have a coq project that requires 8.4pl6, so I have in that project's root directory dir-locals.nix: > let pkgs = import <nixpkgs> {}; in > pkgs.nixBufferBuilders.withPackages [ pkgs.coq ] (note that this relies on a recent nixpkgs commit[1]). Then whenever I open a .v file in the project, ProofGeneral uses coq 8.4 rather than 8.5. If I wanted, my dir-locals.nix could take a 'root' argument, which would point to the file I opened. ~Shea [1]: https://github.com/NixOS/nixpkgs/commit/05c132486d8cfae600bbfe8c9ac5d799b298afed Bas van Dijk <v.dijk....@gmail.com> writes: > Hi Shea, > > As a Nix and Emacs user this looks very interesting. I didn't know about > Buffer-Local Variables before. > > Can you share some applications of nix-buffer / how you are using it? > > Thanks! > > Bas > > On 5 September 2016 at 08:06, Shea Levy <s...@shealevy.com> wrote: > >> 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 >> >> _______________________________________________ >> nix-dev mailing list >> nix-dev@lists.science.uu.nl >> http://lists.science.uu.nl/mailman/listinfo/nix-dev >> >>
signature.asc
Description: PGP signature
_______________________________________________ nix-dev mailing list nix-dev@lists.science.uu.nl http://lists.science.uu.nl/mailman/listinfo/nix-dev