nvf/docs/manual.nix

113 lines
3.5 KiB
Nix
Raw Normal View History

2023-12-09 19:03:58 +00:00
{
lib,
2024-04-18 18:07:19 +00:00
stdenvNoCC,
2024-11-09 21:45:41 +00:00
fetchzip,
runCommandLocal,
2024-04-18 18:07:19 +00:00
# build inputs
nixos-render-docs,
2023-12-09 19:03:58 +00:00
documentation-highlighter,
2024-11-08 09:19:19 +00:00
dart-sass,
path,
2024-04-18 18:07:19 +00:00
# nrd configuration
release,
optionsJSON,
} @ args: let
manual-release = args.release or "unstable";
2024-11-09 21:45:41 +00:00
scss-reset = fetchzip {
url = "https://github.com/Frontend-Layers/scss-reset/archive/refs/tags/1.4.2.zip";
hash = "sha256-cif5Sx8Ca5vxdw/mNAgpulLH15TwmzyJFNM7JURpoaE=";
};
compileStylesheet = runCommandLocal "compile-nvf-stylesheet" {} ''
mkdir -p $out
tmpfile=$(mktemp -d)
trap "rm -r $tmpfile" EXIT
ln -s "${scss-reset}/build" "$tmpfile/scss-reset"
${dart-sass}/bin/sass --load-path "$tmpfile" \
${./static/style.scss} "$out/style.css"
echo "Generated styles"
'';
in
stdenvNoCC.mkDerivation {
name = "nvf-manual";
src = builtins.path {
name = "nvf-manual-${manual-release}";
path = lib.sourceFilesBySuffices ./manual [".md" ".md.in"];
};
2024-11-08 09:19:19 +00:00
strictDependencies = true;
nativeBuildInputs = [nixos-render-docs];
postPatch = ''
ln -s ${optionsJSON}/share/doc/nixos/options.json ./config-options.json
'';
buildPhase = ''
dest="$out/share/doc/nvf"
mkdir -p "$(dirname "$dest")"
mkdir -p $dest/{highlightjs,script}
# Copy highlight scripts to /highlights in document root.
cp -vt $dest/highlightjs \
${documentation-highlighter}/highlight.pack.js \
${documentation-highlighter}/LICENSE \
${documentation-highlighter}/mono-blue.css \
${documentation-highlighter}/loader.js
2024-11-08 09:19:19 +00:00
# Copy anchor scripts to the script directory in document root.
2024-11-09 21:45:41 +00:00
cp -vt "$dest"/script \
${./static/script}/anchor-min.js \
${./static/script}/anchor-use.js
substituteInPlace ./options.md \
--subst-var-by OPTIONS_JSON ./config-options.json
substituteInPlace ./manual.md \
2024-11-08 09:19:19 +00:00
--subst-var-by NVF_VERSION ${manual-release}
2024-11-08 09:19:19 +00:00
substituteInPlace ./hacking/additional-plugins.md \
2024-11-08 09:20:16 +00:00
--subst-var-by NVF_REPO "https://github.com/notashelf/nvf/blob/${manual-release}"
2024-11-09 21:45:41 +00:00
# Move compiled stylesheet
cp -vt $dest \
${compileStylesheet}/style.css
2024-11-08 09:19:19 +00:00
# Move release notes
cp -vr ${./release-notes} release-notes
# Generate final manual from a set of parameters. Explanation of the CLI flags are
# as follows:
#
# 1. --manpage-urls will allow you to use manual pages as they are defined in
# the nixpkgs documentation.
# 2. --revision is the project revision as it is defined in 'release.json' in the
# repository root
# 3. --script will inject a given Javascript file into the resulting pages inside
# the <script> tag.
# 4. --toc-depth will determine the depth of the initial Table of Contents while
# --section-toc-depth will determine the depth of per-section Table of Contents
# sections.
nixos-render-docs manual html \
--manpage-urls ${path + "/doc/manpage-urls.json"} \
--revision ${lib.trivial.revisionWithDefault manual-release} \
2024-11-09 21:45:41 +00:00
--stylesheet "$dest"/style.css \
--script ./highlightjs/highlight.pack.js \
--script ./highlightjs/loader.js \
--script script/anchor-use.js \
--script script/anchor-min.js \
--toc-depth 2 \
--section-toc-depth 1 \
manual.md \
"$dest/index.xhtml"
2024-11-08 09:19:19 +00:00
# Hydra support. Probably not necessary.
mkdir -p $out/nix-support/
echo "doc manual $dest index.html" >> $out/nix-support/hydra-build-products
'';
}