at master 2.1 kB view raw
1#!/usr/bin/env bash 2 3cd -- "$(dirname -- "${BASH_SOURCE[0]}")" 4 5TYPES="html pdf-a4 pdf-letter text texinfo" 6URL=http://www.python.org/ftp/python/doc/VERSION/python-VERSION-docs-TYPE.tar.bz2 7VERSIONS=$(for major in 2 3; do curl https://docs.python.org/$major/archives/ 2>/dev/null | perl -l -n -e'/<a href="python-([23].[0-9]+.[0-9]+)-docs-html.tar.bz2/ && print $1' | tail -n 1; done) 8echo "Generating expressions for: 9${VERSIONS} 10" 11 12 13cat >default.nix <<EOF 14{ stdenv, fetchurl, lib }: 15 16let 17pythonDocs = { 18EOF 19 20for type in $TYPES; do 21 cat >>default.nix <<EOF 22 ${type/-/_} = { 23 recurseForDerivations = true; 24EOF 25 26 for version in $VERSIONS; do 27 major=$(echo -n ${version}| cut -d. -f1) 28 minor=$(echo -n ${version}| cut -d. -f2) 29 if [ "${type}" = "texinfo" ]; then 30 if [ "${major}" = "2" ]; then 31 # Python 2 doesn't have pregenerated texinfos available 32 continue 33 fi 34 template=template-info.nix 35 else 36 template=template.nix 37 fi 38 outfile=${major}.${minor}-${type}.nix 39 hash= 40 if [ -e ${outfile} ]; then 41 currentversion=$(grep "url =" ${outfile} |cut -d/ -f7) 42 if [ ${version} = ${currentversion} ]; then 43 hash=$(grep sha256 ${outfile} | cut -d'"' -f2) 44 fi 45 fi 46 echo "Generating ${outfile}" 47 url=$(echo -n $URL |sed -e "s,VERSION,${version},g" -e "s,TYPE,${type},") 48 sha=$(nix-prefetch-url ${url} ${hash}) 49 50 51 sed -e "s,VERSION,${version}," \ 52 -e "s,MAJOR,${major}," \ 53 -e "s,MINOR,${minor}," \ 54 -e "s,TYPE,${type}," \ 55 -e "s,URL,${url}," \ 56 -e "s,SHA,${sha}," < ${template} > ${outfile} 57 58 attrname=python${major}${minor} 59 cat >>default.nix <<EOF 60 ${attrname} = import ./${major}.${minor}-${type}.nix { 61 inherit stdenv fetchurl lib; 62 }; 63EOF 64 65 echo "done." 66 echo 67 done 68 echo " };" >> default.nix 69done 70 71echo "}; in pythonDocs" >> default.nix