docs/packages/nixpkgs-manual/default.nix

105 lines
2.8 KiB
Nix
Raw Normal View History

2024-06-30 05:43:43 +00:00
{
lib,
2024-06-30 21:43:38 +00:00
pkgs,
2024-06-30 05:43:43 +00:00
nixos-render-docs,
python3,
perl,
stdenvNoCC,
inputs,
2024-06-30 21:43:38 +00:00
...
2024-06-30 05:43:43 +00:00
}:
2024-07-01 20:40:19 +00:00
let
optionsDoc = pkgs.nixosOptionsDoc {
inherit
(pkgs.lib.evalModules {
modules = [ "${inputs.nixpkgs.outPath}/pkgs/top-level/config.nix" ];
class = "nixpkgsConfig";
})
options
;
documentType = "none";
transformOptions =
opt:
opt
// {
declarations = map (
decl:
if lib.hasPrefix (toString ../..) (toString decl) then
let
subpath = lib.removePrefix "/" (lib.removePrefix (toString ../.) (toString decl));
in
{
url = "https://github.com/NixOS/nixpkgs/blob/master/${subpath}";
name = subpath;
}
else
decl
) opt.declarations;
};
};
in
2024-06-30 05:43:43 +00:00
stdenvNoCC.mkDerivation {
name = "nixpkgs-manual-md";
nativeBuildInputs = [
nixos-render-docs
python3
perl
];
src = inputs.nixpkgs;
postPatch = ''
2024-07-01 20:40:19 +00:00
cd doc
2024-06-30 05:43:43 +00:00
'';
2024-06-30 22:10:42 +00:00
pythonInterpreterTable = pkgs.callPackage ./python-interp-table.nix { };
2024-06-30 05:43:43 +00:00
passAsFile = [ "pythonInterpreterTable" ];
buildPhase = ''
2024-07-01 20:40:19 +00:00
nixos-render-docs -j $NIX_BUILD_CORES options commonmark \
--manpage-urls ./manpage-urls.json \
--revision ${inputs.nixpkgs.rev} \
${optionsDoc.optionsJSON}/share/doc/nixos/options.json ./options.md
2024-06-30 05:43:43 +00:00
substituteInPlace ./languages-frameworks/python.section.md --subst-var-by python-interpreter-table "$(<"$pythonInterpreterTablePath")"
2024-06-30 22:10:42 +00:00
mv ./functions/library.md.in ./functions/library.md
2024-06-30 05:43:43 +00:00
substitute ./manual.md.in ./manual.md \
--replace-fail '@MANUAL_VERSION@' '${lib.version}'
mkdir out
mv preface.chapter.md out/index.md
2024-07-01 20:40:19 +00:00
mv options.md out/
2024-06-30 05:43:43 +00:00
mv build-helpers out/build-helpers
mv build-helpers.md out/build-helpers/index.md
mv development out/development
mv development.md out/development/index.md
mv functions out/functions
mv functions.md out/functions/index.md
mv hooks out/hooks
2024-06-30 23:48:07 +00:00
mv languages-frameworks out/languages-and-frameworks
mkdir out/library-reference
cp ${pkgs.amg.lib-docs}/*.md out/library-reference/
2024-06-30 05:43:43 +00:00
mv module-system out/module-system
mv packages out/packages
mv stdenv out/stdenv
mv stdenv.md out/stdenv/index.md
2024-06-30 23:48:07 +00:00
mv using out/using-nixpkgs
mv using-nixpkgs.md out/using-nixpkgs/index.md
2024-06-30 05:43:43 +00:00
pushd out
find . -type f -exec perl -pi -e 's/\s*:::{.note}\n/!!! note\n\ \ /' {} \;
find . -type f -exec perl -pi -e 's/\s*:::{.warning}\n/!!! warning\n\ \ /' {} \;
find . -type f -exec perl -pi -e 's/\s*:::{.tip}\n/!!! tip\n\ \ \ \ /' {} \;
find . -type f -exec perl -pi -e 's/\s*:::{.example}\n/!!! example\n\ \ \ \ /' {} \;
find . -type f -exec sed -i 's/\s*::://g' {} \;
popd
'';
installPhase = ''
mkdir $out
mv out/* $out
'';
}