summaryrefslogtreecommitdiff
path: root/hakyll-nix/build.nix
blob: ba45ab8b725b7285a3a156c2a55f16ade00cabe8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{ pkgs ? import <nixpkgs> {}
# source of the site's files
, src ? ./defaultsite
# source of the hakyll script; will default
# to the site's source if set to null (default).
, hakyllSrc ? null
# name for the site's derivation
, name ? "hakyll-site"
# plug some other compiler in here if you want
, compiler ? "default"
}:

with pkgs;

let
  f = import ./default.nix
    (if hakyllSrc == null then src else hakyllSrc);

  haskellPackages = if compiler == "default"
                    then pkgs.haskellPackages
                    else pkgs.haskell.packages.${compiler};

  hakyll = haskellPackages.callPackage f {};

in stdenv.mkDerivation {
  inherit src name;

  # haskell reads in files with the character encoding
  # declared in an environment file; nix does not set this
  # by default, causing hakyll to fail on files containing
  # unicode.
  LC_ALL = "C.UTF-8";
  buildInputs = [ hakyll ];

  buildPhase = ''
    ${hakyll}/bin/site build
  '';

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