-
-
Notifications
You must be signed in to change notification settings - Fork 118
/
default.nix
104 lines (79 loc) · 2.99 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
{ pkgs ? import <nixpkgs> {} }:
{
html-split = pkgs.stdenvNoCC.mkDerivation {
name = "nix-pills";
src = ./.;
nativeBuildInputs = with pkgs; [
mdbook
mdbook-linkcheck
];
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
# 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"
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
'';
};
epub = pkgs.stdenvNoCC.mkDerivation {
name = "nix-pills-epub";
src = ./.;
nativeBuildInputs = with pkgs; [
mdbook-epub
unzip
zip
];
installCheckInputs = with pkgs; [
epubcheck
];
doInstallCheck = true;
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;" ""
zip -q "../book/epub/Nix Pills.epub" **/*
)
runHook postBuild
'';
installPhase = ''
runHook preInstall
# 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"
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
'';
};
}