Hi there,
I’m fairly new to nix so bear with me. I try to build a general derivation to build a static page via hakyll. So far so good, this is my state:
When running nix-build
there is brings up an error:
Compiling
[ERROR] Hakyll.Core.Compiler.Require.load: templates/archive.html (snapshot _final) was not found in the cache, the cache might be corrupted or the item you are referring to might not exist
I guess there is a problem with the nix stages I currently don’t understand.
Some background how this logic should work:
- build the haskell hakyll binary which builds the static page from the templates and so on (its a buildInput then)
- execute the binary to actually generate the static page
but now there the actual problem:
hakyll uses a _cache
directory for intermediate build output. My assumption is the produced binary site
does not place the binary in a writable location.
What would be the ideal world nix solution to solve this? I’m calling a binary which produces “riot” some output to _cache
and _site
. How to redirect this without customizing the binary?
Greetings
Jan
Hey Jan,
welcome to this forum.
At first glance I’m unable to find the cause for your build failure, but I can show you my working setup for hakyll:
# file default.nix
# Some code copied and/or modified from
# https://utdemir.com/posts/hakyll-on-nixos.html
{stdenv, ghcWithPackages, glibcLocales}:
let
generator = stdenv.mkDerivation {
name = "example.org-generator";
src = ./generator;
phases = "unpackPhase buildPhase";
buildInputs = [
(ghcWithPackages (p: with p; [ hakyll ]))
];
buildPhase = ''
mkdir -p $out/bin
ghc -O2 -dynamic --make site.hs -o $out/bin/generate-site
'';
};
in
stdenv.mkDerivation rec {
name = "example.org";
src = ./.;
phases = "unpackPhase buildPhase";
buildInputs = [ generator ];
LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive";
LANG = "en_US.UTF-8";
buildPhase = ''
generate-site --verbose build
echo Copying
mkdir -p $out
cp -r _site/* $out
'';
meta = {
license = stdenv.lib.licenses.free;
};
}
# file release.nix
let
pkgs = import <nixpkgs> {};
stdenv = pkgs.stdenv;
glibcLocales = pkgs.glibcLocales;
in
{
public = import ./default.nix {
inherit stdenv glibcLocales;
inherit (pkgs.haskellPackages) ghcWithPackages;
};
}
To build: nix build -f release.nix
. My site.hs
resides in ./generator/site.hs
.
Good luck!
2 Likes
Thanks for your insight. Helped alot! I switched from having a builder
script for calling the generator binary to the inline buildPhase
script and somehow it worked.
My working solution can be found here at this commit: GitHub - MaxDaten/brutal-recipes at 10fecbe2a1fe70da37ce1c59caaebda9695984bd
2 Likes