use-package setup…
(require 'package)
(package-initialize 'noactivate)
(eval-when-compile
(require 'use-package))
Now the important packages
(use-package nix-sandbox)
(use-package direnv
:config (direnv-mode))
This is how you setup emacs with nix, but you can skip it.
{ pkgs ? import <nixpkgs> {} }:
let
myEmacsConfig = ./default.el;
emacsWithPackages = (pkgs.emacsPackagesNgGen pkgs.emacs).emacsWithPackages;
in
emacsWithPackages (epkgs: (with epkgs.melpaPackages; [
(pkgs.runCommand "default.el" {} ''
mkdir -p $out/share/emacs/site-lisp
cp ${myEmacsConfig} $out/share/emacs/site-lisp/default.el
'')
use-package
direnv
nix-sandbox
]))
Direnv .envrc
that enables per-dir automated environments
use_nix
shell.nix
env you put in project to predefine environment
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [ direnv hello ];
shellHook = ''
eval $(direnv hook bash)
direnv allow .
'';
}
Let’s make sample project file:
(progn
(let ((tmp-buffer (generate-new-buffer "sample")))
(switch-to-buffer tmp-buffer))
(message (concat "Sandbox: " (nix-current-sandbox)))
(message (concat "From sandbox: " (shell-command-to-string "hello")))
(switch-to-buffer-other-window "*Messages*"))
Now run the delivered emacs w/ config (making sure you’re running the right config) and open the file within the project’s sandbox:
nix run -c emacs -q -l default.el lorem-project/verify.el
This gets you the pre-configured Emacs you’ve seen above. Now execute the buffer and see the sandbox info with hello
package on it.
A statically linked nix can easily run the preconfigured setup anywhere:
curl https://matthewbauer.us/nix sh -s run --store $HOME/.cache/nix/store -f https://github.com/peel/emacs-nix-direnv-sample/archive/master.tar.gz -c emacs