NixOS, Pandoc and Hakyll

Posted on October 27, 2015

My setup

Since Hakyll sites are generated by Haskell programs, I thought I would just use the Haskell ecosystem in NixOS to build my program, and then override the installPhase with something that executes the program and copies the site files to the correct location. Following the instructions in the NixOS User Guide, I generate the main nix file with cabal2nix and manually add the default.nix and shell.nix files. I then make a small change to the themk.net.nix file generated by cabal2nix.

themk.net.nix

{ mkDerivation, base, hakyll, stdenv }:
mkDerivation {
  pname = "themk-net";
  version = "0.1.0.0";
  src = ./.;
  isLibrary = false;
  isExecutable = true;
  executableHaskellDepends = [ base hakyll ];
  license = stdenv.lib.licenses.bsd3;

  # ------- Change is here -------------------
  # Override the installPhase to execute the
  # program, and copy the results to $out
  installPhase = ''
    mkdir -p $out
    ./dist/build/site/site build
    cp -a _site/* $out
  '';
}

We can now use this package from within configuration.nix to set up httpd to point to our new derivation. In order to do this we need to determine the sha256 hash of the commit we are interested in. To do this, use the command

nix-prefetch-git <git url> <commit hash>

Here are the relevant parts of my configuration.nix

configuration.nix

let
  sitesrc = pkgs.fetchgit {
    url = https://github.com/luke-clifton/themk.net.git; 
    rev = "623f2e60193d0351234df1a3a6a4161badffd668"; 
    sha256 = "1cb0f50c085ec2d25231992799a29c5d15c4ebae6da8e3ef3cf5abe0f5d80d84"; 
  }; 
  site = pkgs.callPackage "${sitesrc}" {}
in {
  # ...
 
  services.httpd = {
      adminAddr = "webmaster@themk.net";
      enable = true;
      hostName = "themk.net";
      documentRoot = "${site}";
    };

  # ...
}