1
0
Fork 0
mirror of https://github.com/NixOS/nix-pills synced 2024-09-19 04:00:13 -04:00
nix-pills/default.nix

150 lines
3.8 KiB
Nix
Raw Normal View History

{ pkgs ? import <nixpkgs> {}, revCount, shortRev }:
let
lib = pkgs.lib;
sources = let
# We want nix examples, but not the top level nix to build things
noTopLevelNix = path: type: let
relPath = lib.removePrefix (toString ./. + "/") (toString path);
in builtins.match "[^/]*\.nix" relPath == null;
extensions = [ ".xml" ".txt" ".nix" ".bash" ];
in lib.cleanSourceWith {
filter = noTopLevelNix;
src = lib.sourceFilesBySuffices ./. extensions;
};
combined = pkgs.runCommand "nix-pills-combined"
{
buildInputs = [ pkgs.libxml2 ];
meta.description = "Nix Pills with as a single docbook file";
inherit revCount shortRev;
}
''
cp -r ${sources} ./sources
chmod -R u+w ./sources
cd sources
printf "%s-%s" "$revCount" "$shortRev" > version
xmllint --xinclude --output "$out" ./book.xml
'';
toc = builtins.toFile "toc.xml"
''
<toc role="chunk-toc">
<d:tocentry xmlns:d="http://docbook.org/ns/docbook" linkend="book-nix-pills"><?dbhtml filename="index.html"?>
</d:tocentry>
</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 .svg"
"--stringparam current.docid nix-pills"
"--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}'"
];
in {
html-split = pkgs.stdenv.mkDerivation {
name = "nix-pills";
Convert from docbook to mdbook (#233) * Transform <xi:include> elements to include content * Remove 3 files which were not referenced The files were probably included in previous versions and weren't removed. * Automatic conversion using pandoc I just run `pandoc {fn} -f docbook -t markdown --wrap=none -s -o {fn.with_suffix(".md")}` over all .xml files in pills/, and on /book.xml I manually created SUMMARY.md based on the list in book.xml. * Remove front matter from 00-preface.md * Support "note" sections, fix inter-links * Fix code sections with highlighting, which pandoc missed * Replace `\'` with `'`. * Replace `\"` with `"`. * Replace `\...` with `...` * Format markdown with Prettier * Convert code section to fenced, with the appropriate syntax * Build the book with Nix * Add highlight.js which supports nix syntax highlighting * Add redirects from original paths to new paths * make prompts unselectable * README: Remove DocBook-specific instructions (cherry picked from commit 66936f15a573e36e7138fc93cecb8d2845296ace) * Re-add heading id It was removed in pandoc step for some reason. (cherry picked from commit cf39aa5ad95cf3d704ecd2aa4055e4c23e74fb6b) * Fix footnote rendering with mdbook-epub mdbook-epub 0.4.37 will collapse the second footnote into the first one. This does not happen with HTML output from plain mdbook. (cherry picked from commit bc9bd1384427a443dd12674c5ae2ae0c36ffc7ee) * Manually added backticks for <package> tags in original * Put «» around what was originally <replaceable> * epub: Remove extra page breaks before headings The sections are pretty short, leading to unnecessary pagination being required. --------- Co-authored-by: Noam Yorav-Raphael <noam.yoravraphael@mobileye.com> Co-authored-by: Jan Tojnar <jtojnar@gmail.com>
2024-04-08 19:37:11 -04:00
src = sources;
Convert from docbook to mdbook (#233) * Transform <xi:include> elements to include content * Remove 3 files which were not referenced The files were probably included in previous versions and weren't removed. * Automatic conversion using pandoc I just run `pandoc {fn} -f docbook -t markdown --wrap=none -s -o {fn.with_suffix(".md")}` over all .xml files in pills/, and on /book.xml I manually created SUMMARY.md based on the list in book.xml. * Remove front matter from 00-preface.md * Support "note" sections, fix inter-links * Fix code sections with highlighting, which pandoc missed * Replace `\'` with `'`. * Replace `\"` with `"`. * Replace `\...` with `...` * Format markdown with Prettier * Convert code section to fenced, with the appropriate syntax * Build the book with Nix * Add highlight.js which supports nix syntax highlighting * Add redirects from original paths to new paths * make prompts unselectable * README: Remove DocBook-specific instructions (cherry picked from commit 66936f15a573e36e7138fc93cecb8d2845296ace) * Re-add heading id It was removed in pandoc step for some reason. (cherry picked from commit cf39aa5ad95cf3d704ecd2aa4055e4c23e74fb6b) * Fix footnote rendering with mdbook-epub mdbook-epub 0.4.37 will collapse the second footnote into the first one. This does not happen with HTML output from plain mdbook. (cherry picked from commit bc9bd1384427a443dd12674c5ae2ae0c36ffc7ee) * Manually added backticks for <package> tags in original * Put «» around what was originally <replaceable> * epub: Remove extra page breaks before headings The sections are pretty short, leading to unnecessary pagination being required. --------- Co-authored-by: Noam Yorav-Raphael <noam.yoravraphael@mobileye.com> Co-authored-by: Jan Tojnar <jtojnar@gmail.com>
2024-04-08 19:37:11 -04:00
buildInputs = with pkgs; [
libxslt
];
Convert from docbook to mdbook (#233) * Transform <xi:include> elements to include content * Remove 3 files which were not referenced The files were probably included in previous versions and weren't removed. * Automatic conversion using pandoc I just run `pandoc {fn} -f docbook -t markdown --wrap=none -s -o {fn.with_suffix(".md")}` over all .xml files in pills/, and on /book.xml I manually created SUMMARY.md based on the list in book.xml. * Remove front matter from 00-preface.md * Support "note" sections, fix inter-links * Fix code sections with highlighting, which pandoc missed * Replace `\'` with `'`. * Replace `\"` with `"`. * Replace `\...` with `...` * Format markdown with Prettier * Convert code section to fenced, with the appropriate syntax * Build the book with Nix * Add highlight.js which supports nix syntax highlighting * Add redirects from original paths to new paths * make prompts unselectable * README: Remove DocBook-specific instructions (cherry picked from commit 66936f15a573e36e7138fc93cecb8d2845296ace) * Re-add heading id It was removed in pandoc step for some reason. (cherry picked from commit cf39aa5ad95cf3d704ecd2aa4055e4c23e74fb6b) * Fix footnote rendering with mdbook-epub mdbook-epub 0.4.37 will collapse the second footnote into the first one. This does not happen with HTML output from plain mdbook. (cherry picked from commit bc9bd1384427a443dd12674c5ae2ae0c36ffc7ee) * Manually added backticks for <package> tags in original * Put «» around what was originally <replaceable> * epub: Remove extra page breaks before headings The sections are pretty short, leading to unnecessary pagination being required. --------- Co-authored-by: Noam Yorav-Raphael <noam.yoravraphael@mobileye.com> Co-authored-by: Jan Tojnar <jtojnar@gmail.com>
2024-04-08 19:37:11 -04:00
installPhase = ''
runHook preInstall
# Generate the HTML manual.
dst=$out/share/doc/nix-pills
mkdir -p "$dst"
xsltproc \
${manualXsltprocOptions} \
--nonet --output "$dst/" \
"${pkgs.docbook-xsl-ns}/xml/xsl/docbook/xhtml/chunk.xsl" \
"${combined}"
mkdir -p "$dst/images/callouts"
cp -r "${pkgs.docbook-xsl-ns}/xml/xsl/docbook/images/callouts"/*.svg "$dst/images/callouts"
cp "${./style.css}" "$dst/style.css"
mkdir -p "$out/nix-support"
echo "nix-build out $out" >> "$out/nix-support/hydra-build-products"
echo "doc nix-pills $dst" >> "$out/nix-support/hydra-build-products"
runHook postInstall
'';
};
epub = pkgs.stdenv.mkDerivation {
name = "nix-pills-epub";
src = sources;
buildInputs = with pkgs; [
libxslt
zip
];
installCheckInputs = with pkgs; [
epubcheck
];
doInstallCheck = true;
installPhase = ''
runHook preInstall
# Generate the EPUB manual.
dst=$out/share/doc/nix-pills
mkdir -p "$dst"
xsltproc \
${manualXsltprocOptions} \
--nonet --output "$dst/epub/" \
"${pkgs.docbook-xsl-ns}/xml/xsl/docbook/epub3/chunk.xsl" \
"${combined}"
mkdir -p "$dst/epub/OEBPS/images/callouts"
cp -r "${pkgs.docbook-xsl-ns}/xml/xsl/docbook/images/callouts"/*.svg "$dst/epub/OEBPS/images/callouts"
cp "${./style.css}" "$dst/epub/OEBPS/style.css"
echo "application/epub+zip" > mimetype
manual="$dst/nix-pills.epub"
zip -0Xq "$manual" mimetype
pushd "$dst/epub" && zip -Xr9D "$manual" *
popd
rm -rf "$dst/epub"
mkdir -p "$out/nix-support"
echo "nix-build out $out" >> "$out/nix-support/hydra-build-products"
echo "doc-epub nix-pills $manual" >> "$out/nix-support/hydra-build-products"
runHook postInstall
'';
installCheckPhase = ''
runHook preInstallCheck
epubcheck "$manual"
runHook postInstallCheck
'';
};
2017-08-11 18:22:51 -04:00
}