aboutsummaryrefslogblamecommitdiff
path: root/default.nix
blob: 6c8a56cee7cf31fac654fc9de9bbd6462e6d3911 (plain) (tree)
1
2
3
4
5
6

                                     



                                                                                                    














                                                                               




                                      
                                            


                                                                             


                                                                                                 
                      
 



                        






                                      
                                                                                                      


                   






                                                                    
            












                                                                     
     
 
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 pandoc ];
    buildPhase = ''
      export LOCALE_ARCHIVE="${pkgs.glibcLocales}/lib/locale/locale-archive";
      export LANG=en_US.UTF-8

      ls pastebin/*.org | awk -F. '{print $1}' | xargs -I{} pandoc -o {}.html {}.org --standalone

      build-site build

      mkdir $out
      cp -r _site/* $out
    '';
  };
  test = mkDerivation rec {
    name = "website-test";
    src = ./.;
    phases = "unpackPhase buildPhase";
    buildInputs = [perl];
    buildPhase = ''
      mkdir txt
      podchecker website pastebin/website-pastebin slides/website-slides 2>&1 | tee txt/podchecker.txt
      mv txt/ $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 ]))
      racket
    ];
  };
  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"
  '';
}