2024-04-08 20:49:19 +00:00
{ pkgs ? import <nixpkgs> { } }:
2021-12-15 20:52:49 +00:00
2024-04-08 20:49:19 +00:00
{
html-split = pkgs . stdenvNoCC . mkDerivation {
2024-04-08 23:46:08 +00:00
name = " n i x - p i l l s " ;
2024-04-08 20:49:19 +00:00
src = ./. ;
2024-04-08 23:37:11 +00:00
2024-04-08 20:49:19 +00:00
nativeBuildInputs = with pkgs ; [
mdbook
mdbook-linkcheck
2024-04-08 23:46:08 +00:00
] ;
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
'' ;
2021-12-15 20:52:49 +00:00
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.
2021-12-15 20:52:49 +00:00
dst = $ out/share/doc/nix-pills
mkdir - p " $ d s t "
2024-04-08 20:49:19 +00:00
mv book/html /* " $ d s t " /
2021-12-15 20:52:49 +00:00
mkdir - p " $ o u t / n i x - s u p p o r t "
echo " n i x - b u i l d o u t $ o u t " > > " $ o u t / n i x - s u p p o r t / h y d r a - b u i l d - p r o d u c t s "
echo " d o c n i x - p i l l s $ d s t " > > " $ o u t / n i x - s u p p o r t / h y d r a - b u i l d - p r o d u c t s "
runHook postInstall
'' ;
} ;
2024-04-08 20:49:19 +00:00
epub = pkgs . stdenvNoCC . mkDerivation {
2021-12-15 20:52:49 +00:00
name = " n i x - p i l l s - e p u b " ;
2024-04-08 20:49:19 +00:00
src = ./. ;
2021-12-15 20:52:49 +00:00
2024-04-08 20:49:19 +00:00
nativeBuildInputs = with pkgs ; [
mdbook-epub
unzip
2021-12-15 20:52:49 +00:00
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 != " u n s t a b l e - 2 0 2 2 - 1 2 - 2 5 " ) " t r u e " }
# Work around bugs in mdbook-epub.
mkdir nix-pills . epub-fix
( cd nix-pills . epub-fix
unzip - q " . . / b o o k / e p u b / N i x P i l l s . e p u b "
# Fix invalid ids.
sed - Ei ' s / ( id ( ref ) ? = " ) ( [ 0 - 9 ] ) / \1 p \3 / g ' O E B P S / c o n t e n t . o p f
sed - Ei ' s / ( id = " | h r e f = " #)([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 - 9 a - z - ] + \. ) m d ( [ " #])/\1html\2/g' OEBPS/*.html
2024-04-06 21:42:05 +00:00
# Remove unnecessary page breaks, the sections are short.
substituteInPlace OEBPS/stylesheet.css - - replace-fail " p a g e - b r e a k - b e f o r e : a l w a y s ; " " "
2024-04-08 20:49:19 +00:00
zip - q " . . / b o o k / e p u b / N i x P i l l s . e p u b " * * /*
)
runHook postBuild
'' ;
2021-12-15 20:52:49 +00:00
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.
2021-12-15 20:52:49 +00:00
dst = $ out/share/doc/nix-pills
mkdir - p " $ d s t "
manual = " $ d s t / n i x - p i l l s . e p u b "
2024-04-08 20:49:19 +00:00
mv " b o o k / e p u b / N i x P i l l s . e p u b " " $ m a n u a l "
2021-12-15 20:52:49 +00:00
mkdir - p " $ o u t / n i x - s u p p o r t "
echo " n i x - b u i l d o u t $ o u t " > > " $ o u t / n i x - s u p p o r t / h y d r a - b u i l d - p r o d u c t s "
echo " d o c - e p u b n i x - p i l l s $ m a n u a l " > > " $ o u t / n i x - s u p p o r t / h y d r a - b u i l d - p r o d u c t s "
runHook postInstall
'' ;
installCheckPhase = ''
runHook preInstallCheck
epubcheck " $ m a n u a l "
runHook postInstallCheck
'' ;
} ;
2017-08-11 22:22:51 +00:00
}