Bz01's blog

Map

Using recursive nix to manage emacs

Recently, i read about recursive nix, and was amazed by the amount of possible things i could do.

First of all lets discuss IFDs. IFDs and Recursive nix offer a similar approach to doing things, load nix at build time. However, one important thing to note is that nix is *lazy loaded. What this means is that for every dynamic derivation you import, nix will stop evaluating at point and first evaluate the newly generated derivation. This is incredibly bad as parallelization is essentially stopped in its tracks. Recursive Nix allows you to get a final derivation first, then build it. This allows for the parallelization of all input derivations’ builds.

Using this power, i am able to build emacs with the packages i want without specifying. I dynamically generate a nix expression from parser.lisp that scans my config files, and then installs the packages accordingly.

I still have some hacking left to do, as currently i can only install packages from melpa and elpa, and not from GitHub. Also, every-time i change the configuration, it rebuilds all the packages which is very time consuming.

You can take a look at my parser and nix configuration at: https://gitlab.com/binarydigitz01/dotfiles/-/tree/master/pkgs/binary-emacs to understand what I’m talking about.

Some trivial details to follow: your inner nix should be named after your outer drv. Let’s say my inner drv file is “hello.drv”, my outer package has to be named “hello”.

My parser.lisp generates a nix expression, which i call nix-instantiate.

Please read https://fzakaria.com/2025/03/10/an-early-look-at-nix-dynamic-derivations, this explains recursive nix and dynamic derivations very clearly. Since recursive nix allows nix to parallel’s jobs effectively, it is a far more powerful tool than IFDs.