nix-doom-emacs icon indicating copy to clipboard operation
nix-doom-emacs copied to clipboard

Support doom literate module

Open znewman01 opened this issue 3 years ago • 4 comments

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.

znewman01 avatar Feb 12 '22 17:02 znewman01

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.

ckiee avatar Feb 13 '22 02:02 ckiee

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 :)

znewman01 avatar Feb 14 '22 16:02 znewman01

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

RRvW avatar Mar 30 '22 21:03 RRvW

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

Works really well. Thanks

anexpn avatar Apr 30 '22 09:04 anexpn