Need help building a project with Hakyll which can support unicode

Hello guys,

I am new to Nix (and to Haskell). I’ve been trying to learn Haskell on and off for some time. I am trying to build a static-site generator using Hakyll to build my blog; but the problem I am facing is that the executable built this way fails for unicode characters.

Here is the haskell project I am trying to build: github.com/channikhabra/brandi/

As per this issue: https://github.com/jaspervdj/hakyll/issues/614 (and some other similar issues), I have to set some environment variables to tell Hakyll (or haskell?) that it should support unicode.

Can you guys please help me with how I can set these env variables for building in my current setup? Or should I take some other approach to build my project? My current nix configuration is amalgamation of stuff I picked from here and there (sorry didn’t keep track of sources).

To save you guys a click, here is my release.nix:

let
  sources = import ./nix/sources.nix;
in
{ compiler ? "ghc883"
, pkgs ? import sources.nixpkgs { }
}:

let
  inherit (pkgs.haskell.lib) appendPatch appendConfigureFlags;

  haskellPackages = pkgs.haskell.packages.${compiler}.override {
    overrides = hpNew: hpOld: {
      hakyll = hpOld.hakyll.overrideAttrs(oldAttrs: {
        configureFlags = "-f watchServer -f previewServer";
        patches = [ ./hakyll.patch ];
      });

      brandi = hpNew.callCabal2nix "brandi" ./. { };

      niv = import sources.niv { };
    };
  };

  project = pkgs.haskell.lib.justStaticExecutables haskellPackages.brandi;

in
{
  project = project;

  shell = haskellPackages.shellFor {
    packages = p: with p; [
      brandi
    ];
    buildInputs = with haskellPackages; [
      brandi
    ];
    withHoogle = true;
  };

  dockerImage = pkgs.dockerTools.buildImage {
    name = "channikhabra/brandi";
    tag = "latest";

    config = {
      Cmd = [ "${project}/bin/brandi" "build" ];
      WorkingDir = "/app";
      Volumes = {
        "/app" = {};
      };
    };
  };
}

I believe one of the environment variables I want to set is LANG=en_US.UTF-8.

Thank you in advance!

How are running the program? In a ¿pure? nix-shell? On NixOS, or other Linux distro? What does locale command print?

In one of my Hakyll projects that I needed to run on Windows, I hard-set the encoding to UTF-8. That might work for you too as a last resort:

import qualified GHC.IO.Encoding as E
main = do
	E.setLocaleEncoding E.utf8
	hakyllWith config $ do
            …
1 Like

I am running it on Arch Linux; with result I got with nix-build, I run ~/brandi/result/bin/brandi build in my_blog directory.

Your suggestion worked. Thank you very much!