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





                                                                    






                                                                               
                 
                                                                         




                                                            


                              
                                                     
                         
    
                  
                                                             
                                               
                                                           




                                                                          
                                                         
                                           
                                                                     





                        
                                                                 
                                           
                                                           





                       
                                                              

                                          
                                                                             
                     

                                                       


                  
                                                     
                                      
                   
                                       


                                                                               
                        



                          
    
                     







                                                         
                            


                           

                                                                    

      



                                                  
 
let
  pkgsUnstable = import <nixpkgs> { };
  pkgsPinned = import (pkgsUnstable.fetchzip {
    url = "https://github.com/NixOS/nixpkgs/archive/18.03.zip";
    sha256 = "0hk4y2vkgm1qadpsm4b0q1vxq889jhxzjx3ragybrlwwg54mzp4f";
  }) { };
  pkgs = pkgsUnstable;

  # 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 =
      [ (pkgsPinned.haskellPackages.ghcWithPackages (p: [ p.hakyll ])) ];
    buildPhase = ''
      mkdir -p $out/bin
      ghc -O2 -dynamic --make Main.hs -o $out/bin/build-site
    '';
  };
in rec {
  utils = import ./utils.nix {
    pkgs = pkgs;
    src = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
    baseName = "website";
  };
  subtasks = rec {
    perlPodCheck = utils.baseTask.overrideAttrs (baseAttrs: {
      name = "${baseAttrs.name}-perl-podcheck";
      buildInputs = baseAttrs.buildInputs ++ [ pkgs.perl ];
      buildPhase = ''
        podchecker website pastebin/website-pastebin slides/website-slides
        touch $out
      '';
    });
    batsTest = utils.baseTask.overrideAttrs (baseAttrs: {
      name = "${baseAttrs.name}-bats-test";
      buildInputs = baseAttrs.buildInputs ++ [ pkgs.bats pkgs.perl ];
      buildPhase = ''
        patchShebangs .
        ./t/website.bats
        touch $out
      '';
    });
    perlInternalTest = utils.baseTask.overrideAttrs (baseAttrs: {
      name = "${baseAttrs.name}-perl-test";
      buildInputs = baseAttrs.buildInputs ++ [ pkgs.perl ];
      buildPhase = ''
        patchShebangs .
        ./website test
        touch $out
      '';
    });
    hunspellCheck = utils.baseTask.overrideAttrs (baseAttrs: {
      name = "${baseAttrs.name}-hunspell";
      buildInputs = baseAttrs.buildInputs
        ++ [ (pkgs.hunspellWithDicts (with pkgs.hunspellDicts; [ en-us ])) ];
      buildPhase = ''
        patchShebangs .
        ./spelling/check-spelling.sh "${subtasks.docs}"
        touch $out
      '';
    });
    docs = utils.baseTask.overrideAttrs (baseAttrs: {
      name = "${baseAttrs.name}-docs";
      src = ./site;
      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
      '';
    });
  };
  test = utils.test [
    utils.formatNix
    (utils.shellcheck null)
    (utils.fixme [ "pastebin/skeleton.org" "utils.nix" ])
    subtasks.perlPodCheck
    subtasks.batsTest
    subtasks.perlInternalTest
    subtasks.hunspellCheck
  ];
  shell = pkgs.mkShell rec {
    name = "website-shell";
    buildInputs = [
      websiteBuilder
      (pkgs.haskellPackages.ghcWithPackages (p: with p; [ hakyll ]))
      (pkgs.hunspellWithDicts (with pkgs.hunspellDicts; [ en-us ]))
    ];
  };
  publishScript = utils.overwritingPublishScript {
    docsDerivation = subtasks.docs;
    overwrite = false;
  };
}