1let
2 pkgs = import ./.. { };
3 lib = pkgs.lib;
4 sources = lib.sourceFilesBySuffices ./. [".xml"];
5 sources-langs = ./languages-frameworks;
6in
7pkgs.stdenv.mkDerivation {
8 name = "nixpkgs-manual";
9
10
11 buildInputs = with pkgs; [ pandoc libxml2 libxslt zip ];
12
13 xsltFlags = ''
14 --param section.autolabel 1
15 --param section.label.includes.component.label 1
16 --param html.stylesheet 'style.css'
17 --param xref.with.number.and.title 1
18 --param toc.section.depth 3
19 --param admon.style '''
20 --param callout.graphics.extension '.gif'
21 '';
22
23
24 buildCommand = let toDocbook = { useChapters ? false, inputFile, outputFile }:
25 let
26 extraHeader = ''xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" '';
27 in ''
28 {
29 pandoc '${inputFile}' -w docbook ${lib.optionalString useChapters "--chapters"} \
30 --smart \
31 | sed -e 's|<ulink url=|<link xlink:href=|' \
32 -e 's|</ulink>|</link>|' \
33 -e 's|<sect. id=|<section xml:id=|' \
34 -e 's|</sect[0-9]>|</section>|' \
35 -e '1s| id=| xml:id=|' \
36 -e '1s|\(<[^ ]* \)|\1${extraHeader}|'
37 } > '${outputFile}'
38 '';
39 in
40
41 ''
42 ln -s '${sources}/'*.xml .
43 mkdir ./languages-frameworks
44 cp -s '${sources-langs}'/* ./languages-frameworks
45 ''
46 + toDocbook {
47 inputFile = ./introduction.md;
48 outputFile = "introduction.xml";
49 useChapters = true;
50 }
51 + toDocbook {
52 inputFile = ./languages-frameworks/python.md;
53 outputFile = "./languages-frameworks/python.xml";
54 }
55 + toDocbook {
56 inputFile = ./languages-frameworks/haskell.md;
57 outputFile = "./languages-frameworks/haskell.xml";
58 }
59 + toDocbook {
60 inputFile = ../pkgs/development/idris-modules/README.md;
61 outputFile = "languages-frameworks/idris.xml";
62 }
63 + toDocbook {
64 inputFile = ../pkgs/development/r-modules/README.md;
65 outputFile = "languages-frameworks/r.xml";
66 }
67 + ''
68 echo ${lib.nixpkgsVersion} > .version
69
70 # validate against relaxng schema
71 xmllint --nonet --xinclude --noxincludenode manual.xml --output manual-full.xml
72 ${pkgs.jing}/bin/jing ${pkgs.docbook5}/xml/rng/docbook/docbook.rng manual-full.xml
73
74 dst=$out/share/doc/nixpkgs
75 mkdir -p $dst
76 xsltproc $xsltFlags --nonet --xinclude \
77 --output $dst/manual.html \
78 ${pkgs.docbook5_xsl}/xml/xsl/docbook/xhtml/docbook.xsl \
79 ./manual.xml
80
81 cp ${./style.css} $dst/style.css
82
83 mkdir -p $dst/images/callouts
84 cp "${pkgs.docbook5_xsl}/xml/xsl/docbook/images/callouts/"*.gif $dst/images/callouts/
85
86 mkdir -p $out/nix-support
87 echo "doc manual $dst manual.html" >> $out/nix-support/hydra-build-products
88
89 xsltproc $xsltFlags --nonet --xinclude \
90 --output $dst/epub/ \
91 ${pkgs.docbook5_xsl}/xml/xsl/docbook/epub/docbook.xsl \
92 ./manual.xml
93
94 cp -r $dst/images $dst/epub/OEBPS
95 echo "application/epub+zip" > mimetype
96 zip -0Xq "$dst/Nixpkgs Contributors Guide - NixOS community.epub" mimetype
97 zip -Xr9D "$dst/Nixpkgs Contributors Guide - NixOS community.epub" $dst/epub/*
98 '';
99}