Hakyll + Nix Starter Template

Hi, Nix friends. I’ve used hakyll a few different ways over a couple of years and have written a bit about digging in to it and figuring things out (I have a section on the hakyll tutorials, for better or worse), and I’ve put together a hakyll + nix template repository for myself and others to use after experimenting a bit on my own site.

It does a lot of stuff for you that can be read on the readme.

Credits: I leveraged a ton of ideas to figure it out, namely from https://maybevoid.com for the “generator” organization concept, and tons of other blog posts, nixpkgs source code and github issues, etc., to get better at organizing such a project.

I hope it helps some folks,
Robert W. Pearce

p.s. Feedback is welcomed

3 Likes

Hi! I am struggling trying to run hakyll right now.

I tried to follow your tutorial, however you did not specify the commit hash of nixpkgs you are using and in the current nixpkgs-unstable the package haskellPackages.hakyll is marked as broken (and indead breaks when I allow broken builds). I had to pass the extra option

nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/release-20.09.tar.gz --pure -p haskellPackages.hakyll --run "hakyll-init ."

to do the bootstrapping… and make analogous changes for the call to niv:

niv update nixpkgs -o NixOS -r release-20.09 -b release-20.09

Thanks to that, I managed to go one step further and now I am stuck at:

$ nix-build --show-trace

building '/nix/store/ngkkipv39p0mcj5qsjw9vmrm4bqmr9k6-cabal2nix-website_perso_hs.drv'...
installing
cabal2nix: nix-prefetch-url: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)
builder for '/nix/store/ngkkipv39p0mcj5qsjw9vmrm4bqmr9k6-cabal2nix-website_perso_hs.drv' failed with exit code 1
error: while evaluating the attribute 'project' at /home/cyril/git/website_perso_hs/master/release.nix:31:10:
while evaluating the attribute 'website_perso_hs' at /home/cyril/git/website_perso_hs/master/release.nix:22:7:
while evaluating 'callCabal2nix' at /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/make-package-set.nix:216
:32, called from /home/cyril/git/website_perso_hs/master/release.nix:22:26:
while evaluating 'callCabal2nixWithOptions' at /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/make-package-
set.nix:201:66, called from /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/make-package-set.nix:216:38:
while evaluating 'overrideCabal' at /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/lib.nix:37:24, called fr
om /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/make-package-set.nix:212:10:
while evaluating 'callPackageKeepDeriver' at /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/make-package-se
t.nix:157:33, called from /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/make-package-set.nix:212:25:
while evaluating 'overrideCabal' at /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/lib.nix:37:24, called fr
om /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/make-package-set.nix:158:5:
while evaluating 'callPackage' at /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/make-package-set.nix:114:2
2, called from /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/make-package-set.nix:158:20:
while evaluating 'callPackageWithScope' at /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/make-package-set.
nix:74:37, called from /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/make-package-set.nix:114:28:
while evaluating 'makeOverridable' at /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/lib/customisation.nix:67:24, called from /nix/store/7sv
wiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/make-package-set.nix:97:8:
while evaluating 'drvScope' at /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/pkgs/development/haskell-modules/make-package-set.nix:87:18, c
alled from /nix/store/7svwiz67sghmhlpddsnarm0jhb5zvds3-nixpkgs-src/lib/customisation.nix:69:16:
build of '/nix/store/ngkkipv39p0mcj5qsjw9vmrm4bqmr9k6-cabal2nix-website_perso_hs.drv' failed

Still trying to understand this one.
Best,


Cyril

1 Like
cabal2nix: nix-prefetch-url: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)

This is saying that cabal2nix can’t find the nix-prefetch-url binary.

In theory, cabal2nix probably doesn’t need the nix-prefetch-url binary here, but without access to your actual Nix code, it is hard to see what exactly is going on.

Here’s an upstream issue where someone is running into something similar:

1 Like

Thanks I will look into it.
As for the core, I did follow Hakyll Pt. 6 – Pure Builds With Nix precisely except for four things:

  • I applied the fix of my previous post (adding -I nixpkgs=[...] as an option to the boostrapping nix shell)
  • I called niv with the release 20.09: niv update nixpkgs -o NixOS -r release-20.09 -b release-20.09
  • I renamed the folder website_perso_hs/master and
  • I substituted hakyll-nix-example for website_perso_hs in the release.nix file

Just for the record, I tried again with only the first two modifications and it goes through with no error. Then tried again from scratch with my renaming inside release.nix. So it seems the problem comes from my renamings (any of them apparently). I cannot see why though: I do not see where else the name hakyll-nix-example could be bound.

EDIT: I found the problem: underscores (_) are not allowed as haskell package names, but they get silently remapped to dashes (-) in the cabal file. Updating release.nix accordingly fixes the problem.

@CohenCyril

I tried to follow your tutorial, however you did not specify the commit hash of nixpkgs you are using

Is this what you’re looking for? https://github.com/rpearce/hakyll-nix-template/blob/20e9bb70ba3ac4c6ea2b1fed26f530e099c1a6a6/nix/sources.json#L14-L25

Given everything is pinned, this all should work without having to make all the changes you had to do.

Are you still having issues?

On a related note, I need to circle back to this and update it to use nix flakes, and this will make some of this a lot simpler.

1 Like

Thanks for pointing me towards this, I was following your tutorial which did not seem reproducible. The template looks better :slight_smile: thanks!

1 Like

Update: I’ve updated all the things and rewritten this to use nix flakes and leverage a lot of nice goodies! Check it out: GitHub - rpearce/hakyll-nix-template: Hakyll + Nix starter template

2 Likes

Update: I’ve updated how post titles are converted into URIs by including my new hackage project, slugger, which supports a good number of languages (and more soon). This means that you can have a post title written in any of these languages, and it’ll generate a good filename / URI slug for you!

  • Dansk (Danish)
  • Deutsch (German)
  • English
  • Español (Spanish)
  • Français (French)
  • Íslenska (Icelandic)
  • Italiano (Italian)
  • Polski (Polish)
  • Suomi (Finnish)
  • Svenska (Swedish)
  • Türkçe (Turkish)

This word describes the group of Germans, though I think you want to describe the name of the language, which would be “Deutsch”.

1 Like

Thank you for correcting me!