aboutsummaryrefslogtreecommitdiff
path: root/default.nix
blob: 7b297d284c660056d305a38d9db2dffb504162c2 (about) (plain) (blame)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
let
  pkgsOriginal = import <nixpkgs> {};
  pkgs = import (pkgsOriginal.fetchzip {
      url = "https://github.com/NixOS/nixpkgs/archive/dd6b4b7078d89decabefc6b1a698327db132fbfe.zip";
      sha256 = "1cs5vibi2gab8i9m317v1b1spvmm2ppad8pxpkkp64fp1s3q6zy9";
  }) {};

  # Taken from:
  # http://www.cs.yale.edu/homes/lucas.paul/posts/2017-04-10-hakyll-on-nix.html
  websiteBuilder = pkgs.stdenv.mkDerivation {
    name = "website-builder";
    src = ./hakyll;
    phases = "unpackPhase buildPhase";
    buildInputs = [
      (pkgs.haskellPackages.ghcWithPackages (p: with p; [ hakyll ]))
    ];
    buildPhase = ''
      mkdir -p $out/bin
      ghc -O2 -dynamic --make Main.hs -o $out/bin/build-site
    '';
  };
in with pkgs; with pkgs.stdenv; rec {
  build = mkDerivation rec {
    name = "website";
    src = ./site;
    phases = "unpackPhase buildPhase";
    buildInputs = [ websiteBuilder ];
    buildPhase = ''
      export LOCALE_ARCHIVE="${pkgs.glibcLocales}/lib/locale/locale-archive";
      export LANG=en_US.UTF-8
      build-site build

      mkdir $out
      cp -r _site/* $out
    '';
  };
  shell = mkShell rec {
    # See also the reference documentation:
    # https://nixos.org/nixpkgs/manual/#sec-pkgs-mkShell
    name = "website-shell";
    buildInputs = [
      websiteBuilder
      (pkgs.haskellPackages.ghcWithPackages (p: with p; [ hakyll ]))
    ];
  };
  publishScript = pkgs.writeShellScriptBin "publish.sh" ''
    set -euo pipefail
    ${pkgs.rsync}/bin/rsync --verbose                               \
                            --copy-links                            \
                            --progress                              \
                            --stats                                 \
                            --update                                \
                            --recursive                             \
                            --rsh="ssh -o StrictHostKeyChecking=no" \
                            ${build}/                               \
                            "$SERVER_URL:$DOCS_SERVER_PATH"
  '';
}