nix-pills/default.nix

105 lines
3 KiB
Nix
Raw Normal View History

2024-04-08 20:49:19 +00:00
{ pkgs ? import <nixpkgs> {} }:
2024-04-08 20:49:19 +00:00
{
html-split = pkgs.stdenvNoCC.mkDerivation {
name = "nix-pills";
2024-04-08 20:49:19 +00:00
src = ./.;
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 23:37:11 +00:00
2024-04-08 20:49:19 +00:00
nativeBuildInputs = with pkgs; [
mdbook
mdbook-linkcheck
];
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 23:37:11 +00:00
2024-04-08 20:49:19 +00:00
buildPhase = ''
runHook preBuild
# We can't check external links inside the sandbox, but it's good to check them outside the sandbox.
substituteInPlace book.toml --replace-fail 'follow-web-links = true' 'follow-web-links = false'
mdbook build
runHook postBuild
'';
installPhase = ''
runHook preInstall
2024-04-08 20:49:19 +00:00
# The nix pills were originally built into this directory, and consumers of the nix pills expect to find it there. Do not change unless you also change other code that depends on this directory structure.
dst=$out/share/doc/nix-pills
mkdir -p "$dst"
2024-04-08 20:49:19 +00:00
mv book/html/* "$dst"/
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
'';
};
2024-04-08 20:49:19 +00:00
epub = pkgs.stdenvNoCC.mkDerivation {
name = "nix-pills-epub";
2024-04-08 20:49:19 +00:00
src = ./.;
2024-04-08 20:49:19 +00:00
nativeBuildInputs = with pkgs; [
mdbook-epub
unzip
zip
];
installCheckInputs = with pkgs; [
epubcheck
];
doInstallCheck = true;
2024-04-08 20:49:19 +00:00
buildPhase = ''
runHook preBuild
mdbook-epub --standalone${pkgs.lib.optionalString (pkgs.mdbook-epub.version != "unstable-2022-12-25") " true"}
# Work around bugs in mdbook-epub.
mkdir nix-pills.epub-fix
( cd nix-pills.epub-fix
unzip -q "../book/epub/Nix Pills.epub"
# Fix invalid ids.
sed -Ei 's/(id(ref)?=")([0-9])/\1p\3/g' OEBPS/content.opf
sed -Ei 's/(id="|href="#)([0-9])/\1fn\2/g' OEBPS/20-basic-dependencies-and-hooks.html
# Fix anchors.
sed -Ei 's~(<h[1-6])(>.+) \{#([^\}]+)\}(</h[1-6]>)~\1 id="\3"\2\4~g' OEBPS/*.html
# Fix broken links in body.
sed -Ei 's/("[0-9a-z-]+\.)md(["#])/\1html\2/g' OEBPS/*.html
# Remove unnecessary page breaks, the sections are short.
substituteInPlace OEBPS/stylesheet.css --replace-fail "page-break-before: always;" ""
2024-04-08 20:49:19 +00:00
zip -q "../book/epub/Nix Pills.epub" **/*
)
runHook postBuild
'';
installPhase = ''
runHook preInstall
2024-04-08 20:49:19 +00:00
# The nix pills were originally built into this directory, and consumers of the nix pills expect to find it there. Do not change unless you also change other code that depends on this directory structure.
dst=$out/share/doc/nix-pills
mkdir -p "$dst"
manual="$dst/nix-pills.epub"
2024-04-08 20:49:19 +00:00
mv "book/epub/Nix Pills.epub" "$manual"
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 22:22:51 +00:00
}