aboutsummaryrefslogblamecommitdiff
path: root/default.nix
blob: 2684ceaffd52902cbacdff89adfee1772d43eec3 (plain) (tree)
1
2
3
4
5
6
7
8
9
   

                                         


                                                
              

                     
                                                         
                                                          
 



                               
                              
    
 
                                                             







                                                                      
                            
             
                  
                   
          
        

                  
            
               
 

           
        
            

          
                         


              
                                                                
    





                                              
        
                      

                  

                      
              

              
                        
                        
                           
                  
                                         
                                                         
                                       
                                                                                 
 

                                  


                                   
                                 
                            
                                               


                 
       
    
                                                          
            
                            

                                              
                                                                 


                                                                     

                                                                     
     
 
let
  niv-sources = import ./nix/sources.nix;
  pkgs = import niv-sources.nixpkgs { };
  src = pkgs.nix-gitignore.gitignoreSourcePure [
    "/result*"
    "/_site/"
    "/public/"
    "/.jekyll-cache/"
  ] ./.;
  utils-i18n = pkgs.callPackage ./nix/utils-i18n.nix { };
  pkgs-next = pkgs.callPackage ./nix/nixpkgs-next.nix { };

  jekyllEnv = pkgs.bundlerEnv {
    name = "jekyll-env";
    gemfile = ./Gemfile;
    lockfile = ./Gemfile.lock;
    gemset = ./nix/gemset.nix;
  };

  mktorrent-newer = pkgs.mktorrent.overrideAttrs (oldAttrs: {
    src = pkgs.fetchFromGitHub {
      owner = "Rudde";
      repo = "mktorrent";
      rev = "ea1fbf29d19f34a93f7d984c1ac29d6d08f1f508";
      sha256 = "1cjq96qridpvqhphj3ljnhysnqkdck415wxaqy768r0rvzqq1ja4";
    };
  });

  buildInputs = with pkgs; [
    jekyllEnv
    pkgs-next.mdpo
    mktorrent-newer
    ffmpeg
    flac
    mediainfo
    mkvtoolnix-cli
    inkscape
    imagemagick

    pandoc
    gettext
    perl
    graphviz
    nixfmt
    git
    gitAndTools.git-annex
    shellcheck
    jq
    niv
    (hunspellWithDicts (with utils-i18n.dicts; [ en pt fr eo ]))
  ];
  drv = name: buildPhase:
    pkgs.stdenv.mkDerivation {
      inherit src buildInputs buildPhase;
      name = "website-${name}";
      phases = [ "unpackPhase" "buildPhase" ];
    };
in rec {
  site = drv "site" ''
    make public
    mv public $out
  '';
  test = drv "test" ''
    make check
    touch $out
  '';
  shell = pkgs.mkShell {
    inherit buildInputs;
    name = "website-shell";
    shellHook = ''
      echo 'Starting a live server with:'
      echo '  jekyll serve --future --livereload --trace'
      echo 'Server with feature flags:'
      echo '  jekyll serve --future --livereload --trace -c $(cfg podcast music)'

      export JEKYLL_ENV=production

      cfg() {
        T="$(mktemp --suffix .yml)"
        cp _config.yml "$T"
        printf '\nflags:' >> "$T"
        for flag in "$@"; do
          printf '\n  %s: true' "$flag" >> "$T"
        done
        echo "$T"
      }
    '';
  };
  publishScript = pkgs.writeShellScriptBin "publish.sh" ''
    set -eux
    SERVER_URL='euandre.org'
    REMOTE_PATH='/home/user-data/www/default/'
    OUT_DOCS='${site}'
    ${pkgs.openssh}/bin/ssh "$SERVER_URL" rm -rf "$REMOTE_PATH/*"
    ${pkgs.rsync}/bin/rsync -avzP                                   \
                            --rsh="ssh -o StrictHostKeyChecking=no" \
                            "$OUT_DOCS/"                            \
                            "$SERVER_URL:$REMOTE_PATH"              \
                            --delete
  '';
}