anchor.diff:        </toc>
       '';
   
  +  manualXsltprocOptions = toString [
  +    "--param section.autolabel 1"
  +    "--param section.label.includes.component.label 1"
  +    "--stringparam html.stylesheet style.css"
  +    "--param xref.with.number.and.title 1"
  +    "--param toc.section.depth 3"
  +    "--stringparam admon.style ''"
  +    "--stringparam callout.graphics.extension .gif"
  +    "--stringparam current.docid manual"
  +    "--param chunk.section.depth 0"
  +    "--param chunk.first.sections 1"
  +    "--param use.id.as.filename 1"
  +    "--stringparam generate.toc 'book toc appendix toc'"
  +    "--stringparam chunk.toc ${toc}"
  +  ];
  +
  +  olinkDB = stdenv.mkDerivation {
  +    name = "manual-olinkdb";
  +
  +    inherit sources;
  +
  +    buildInputs = [ libxml2 libxslt ];
  +
  +    buildCommand = ''
  +      ${copySources}
  +
  +      xsltproc \
  +        ${manualXsltprocOptions} \
  +        --stringparam collect.xref.targets only \
  +        --stringparam targets.filename "$out/manual.db" \
  +        --nonet --xinclude \
  +        ${docbook5_xsl}/xml/xsl/docbook/xhtml/chunktoc.xsl \
  +        ./manual.xml
  +
  +      # Check the validity of the man pages sources.
  +      xmllint --noout --nonet --xinclude --noxincludenode \
  +        --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \
  +        ./man-pages.xml
  +
  +      cat > "$out/olinkdb.xml" <<EOF
  +      <?xml version="1.0" encoding="utf-8"?>
  +      <!DOCTYPE targetset SYSTEM
  +        "file://${docbook5_xsl}/xml/xsl/docbook/common/targetdatabase.dtd" [
  +        <!ENTITY manualtargets SYSTEM "file://$out/manual.db">
  +      ]>
  +      <targetset>
  +        <targetsetinfo>
  +            Allows for cross-referencing olinks between the manpages
  +            and the HTML/PDF manuals.
  +        </targetsetinfo>
  +
  +        <document targetdoc="manual">&manualtargets;</document>
  +      </targetset>
  +      EOF
  +    '';
  +  };
  +
   in rec {
   
     # The NixOS options in JSON format.
  
positive.code:       dst=$out/share/doc/nixos
        mkdir -p $dst
        xsltproc \
          --param section.autolabel 1 \
          --param section.label.includes.component.label 1 \
          --stringparam html.stylesheet style.css \
          --param xref.with.number.and.title 1 \
          --param toc.section.depth 3 \
          --stringparam admon.style "" \
          --stringparam callout.graphics.extension .gif \
          --param chunk.section.depth 0 \
          --param chunk.first.sections 1 \
          --param use.id.as.filename 1 \
          --stringparam generate.toc "book toc appendix toc" \
          --stringparam chunk.toc ${toc} \
          --nonet --xinclude --output $dst/ \
          ${docbook5_xsl}/xml/xsl/docbook/xhtml/chunktoc.xsl ./manual.xml
  
  
negative.code:       dst=$out/share/doc/nixos
        mkdir -p $dst
        xmllint --xinclude manual.xml | dblatex -o $dst/manual.pdf - \
          -P target.database.document="${olinkDB}/olinkdb.xml" \
          -P doc.collab.show=0 \
          -P latex.output.revhistory=0
  
  