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 "--top-level-division=chapter"} \
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/node-packages/README.md;
65 outputFile = "languages-frameworks/node.xml";
66 }
67 + toDocbook {
68 inputFile = ../pkgs/development/r-modules/README.md;
69 outputFile = "languages-frameworks/r.xml";
70 }
71 + toDocbook {
72 inputFile = ./languages-frameworks/rust.md;
73 outputFile = "./languages-frameworks/rust.xml";
74 }
75 + toDocbook {
76 inputFile = ./languages-frameworks/vim.md;
77 outputFile = "./languages-frameworks/vim.xml";
78 }
79 + ''
80 echo ${lib.nixpkgsVersion} > .version
81
82 # validate against relaxng schema
83 xmllint --nonet --xinclude --noxincludenode manual.xml --output manual-full.xml
84 ${pkgs.jing}/bin/jing ${pkgs.docbook5}/xml/rng/docbook/docbook.rng manual-full.xml
85
86 dst=$out/share/doc/nixpkgs
87 mkdir -p $dst
88 xsltproc $xsltFlags --nonet --xinclude \
89 --output $dst/manual.html \
90 ${pkgs.docbook5_xsl}/xml/xsl/docbook/xhtml/docbook.xsl \
91 ./manual.xml
92
93 cp ${./style.css} $dst/style.css
94
95 mkdir -p $dst/images/callouts
96 cp "${pkgs.docbook5_xsl}/xml/xsl/docbook/images/callouts/"*.gif $dst/images/callouts/
97
98 mkdir -p $out/nix-support
99 echo "doc manual $dst manual.html" >> $out/nix-support/hydra-build-products
100
101 xsltproc $xsltFlags --nonet --xinclude \
102 --output $dst/epub/ \
103 ${pkgs.docbook5_xsl}/xml/xsl/docbook/epub/docbook.xsl \
104 ./manual.xml
105
106 cp -r $dst/images $dst/epub/OEBPS
107 echo "application/epub+zip" > mimetype
108 manual="$dst/nixpkgs-manual.epub"
109 zip -0Xq "$manual" mimetype
110 cd $dst/epub && zip -Xr9D "$manual" *
111 rm -rf $dst/epub
112 '';
113}