nix-doom-emacs
nix-doom-emacs copied to clipboard
Support doom literate module
Copied from https://github.com/vlaci/nix-doom-emacs/issues/9
If user has literate doom module enabled, support not having config.el and first tangling config.org.
So.. I already take this approach in my private config but it's a bad solution since it needs to build Doom twice and the literate module automatically tangles config.org to config.el when saving so this is not really a problem. Or, if that module is broken, upstream's problem to fix.
The thing that most bothers me about this is that I now have to commit both config.org and config.el to my NixOS repo.
IMO your hack would be worth including in nix-doom-emacs. I'll probably borrow it :)
Since doomPrivateDir can be set to a Nix derivation, i solved this by creating a derivation that tangles my config.org, and use that in my home.nix.
In my doom.d folder, there is a default.nix with the following contents:
{ version ? "dev", lib, stdenv, emacs }:
stdenv.mkDerivation {
pname = "emacs-config";
inherit version;
src = lib.sourceByRegex ./. [ "config.org" "init.el" ];
buildInputs = [emacs];
buildPhase = ''
cp $src/* .
# Tangle org files
emacs --batch -Q \
-l org \
config.org \
-f org-babel-tangle
'';
dontUnpack = true;
installPhase = ''
install -D -t $out *.el
'';
}
nix-doom-emacs gets called like this:
doom-emacs = pkgs.callPackage (builtins.fetchTarball {
url =
"https://github.com/nix-community/nix-doom-emacs/archive/master.tar.gz";
}) {
doomPrivateDir = pkgs.callPackage ./doom.d {};
};
Doom gets build only once, and config.org remains the single source of truth.
Note that literate module of doom tangles all code blocks by default, while standard Org-babel will only tangle those with :tangle yes set. This can be solved by adding
#+PROPERTY: header-args:emacs-lisp :tangle yes
to the header of your config
Since
doomPrivateDircan be set to a Nix derivation, i solved this by creating a derivation that tangles myconfig.org, and use that in myhome.nix. In mydoom.dfolder, there is adefault.nixwith the following contents:{ version ? "dev", lib, stdenv, emacs }: stdenv.mkDerivation { pname = "emacs-config"; inherit version; src = lib.sourceByRegex ./. [ "config.org" "init.el" ]; buildInputs = [emacs]; buildPhase = '' cp $src/* . # Tangle org files emacs --batch -Q \ -l org \ config.org \ -f org-babel-tangle ''; dontUnpack = true; installPhase = '' install -D -t $out *.el ''; }
nix-doom-emacsgets called like this:doom-emacs = pkgs.callPackage (builtins.fetchTarball { url = "https://github.com/nix-community/nix-doom-emacs/archive/master.tar.gz"; }) { doomPrivateDir = pkgs.callPackage ./doom.d {}; };Doom gets build only once, and
config.orgremains the single source of truth.Note that
literatemodule of doom tangles all code blocks by default, while standard Org-babel will only tangle those with:tangle yesset. This can be solved by adding#+PROPERTY: header-args:emacs-lisp :tangle yesto the header of your config
Works really well. Thanks