nix-community / nix-doom-emacs

doom-emacs packaged for Nix [maintainers=@thiagokokada]
MIT License
224 stars 43 forks source link

Support doom literate module #60

Open znewman01 opened 2 years ago

znewman01 commented 2 years ago

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.

ckiee commented 2 years ago

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.

znewman01 commented 2 years ago

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

RRvW commented 2 years ago

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

juxtaly commented 2 years ago

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