# Generates redirect-targets.html containing all redirect targets for link checking.
# Used by: doc/manual/package.nix (passthru.tests.linkcheck)
{
stdenv,
lib,
jq,
}:
stdenv.mkDerivation {
name = "redirect-targets-html";
src = lib.fileset.toSource {
root = ./.;
fileset = ./redirects.json;
};
nativeBuildInputs = [ jq ];
installPhase = ''
mkdir -p $out
{
echo ''
echo '
Nix Manual Redirect Targets'
echo 'Redirect Targets to Check
'
echo 'This document contains all redirect targets from the Nix manual.
'
echo 'Client-side redirects (from redirects.json)
'
echo ''
# Extract all redirects with their source pages to properly resolve relative paths
jq -r 'to_entries[] | .key as $page | .value | to_entries[] | "\($page)\t\(.value)"' \
redirects.json | while IFS=$'\t' read -r page target; do
page_dir=$(dirname "$page")
# Handle fragment-only targets (e.g., #primitives)
if [[ "$target" == \#* ]]; then
# Fragment is on the same page
resolved="$page$target"
echo "- $resolved (fragment on $page)
"
continue
fi
# Resolve relative path based on the source page location
resolved="$page_dir/$target"
echo "- $resolved (from $page)
"
done
echo '
'
echo ''
} > $out/redirect-targets.html
echo "Generated redirect targets document with $(grep -c '' $out/redirect-targets.html) links"
'';
meta = {
description = "HTML document listing all Nix manual redirect targets for link checking";
};
}