How this website is built - Nix and ox-hugo

A few months ago [I announced that I'm now using ox-hugo]({{< relref "moving-site-org-mode" >}}) but didn't go through the whole setup. Now the time has come to show you how everything works here. It basically works around three main tools (that I assume you already know about):

I use GNU Emacs to edit a single Org file placed at content-org/content.org that contains all the contents of this website. There's also a file called .dir-locals.el that I use to activate the function org-hugo-auto-export-mode when I open an Org file inside the website's directory.

(("content-org"
  . ((org-mode . ((eval . (org-hugo-auto-export-mode)))))))

org-hugo-auto-export-mode is responsible to automatically export the article I'm editing to the content directory as a Markdown file on each save I do, allowing me to use Hugo's auto-reload feature.

This was the trickiest part of the whole process. I ended up creating a file called export.el with the function I found here to export all my files at once on CI. If you don't use Nix, all you need is a GNU Emacs with ox-hugo installed and then run this:

emacs $(pwd) --batch -load export.el
hugo

Now, if you're a Nix person, you can easily create a derivation to build everything with a custom GNU Emacs.

let
  customEmacs = (emacsPackagesFor emacs-nox).emacsWithPackages
    (epkgs: with epkgs.melpaPackages; [
      ox-hugo
    ]
    ++ (with epkgs.elpaPackages; [
      org
    ]));
in
stdenv.mkDerivation {
  name = "glorifiedgluercom";
  src = lib.cleanSource ./.;

  buildInputs = [
    customEmacs
    hugo
  ];

  configurePhase = ''
    emacs $(pwd) --batch -load export.el
  '';

  buildPhase = ''
    hugo
  '';

  installPhase = ''
    mkdir -p $out
    cp -r public/* $out
  '';
};