Skip to content

Commit

Permalink
doc: extract nixpkgs-manual into its own package
Browse files Browse the repository at this point in the history
Also, use `finalAttrs` style and pass through all the helper derivations.
  • Loading branch information
philiptaron committed Jul 26, 2024
1 parent 8bb7777 commit 4252286
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 98 deletions.
102 changes: 5 additions & 97 deletions doc/default.nix
Original file line number Diff line number Diff line change
@@ -1,98 +1,6 @@
{ pkgs ? (import ./.. { }), nixpkgs ? { }}:
let
inherit (pkgs) lib callPackage;
fs = lib.fileset;
{
pkgs ? (import ./.. { }),
nixpkgs ? { },
}:

common = import ./common.nix;

lib-docs = callPackage ./doc-support/lib-function-docs.nix {
inherit nixpkgs;
};

epub = callPackage ./doc-support/epub.nix { };

# NB: This file describes the Nixpkgs manual, which happens to use module docs infra originally developed for NixOS.
optionsDoc = callPackage ./doc-support/options-doc.nix { };

pythonInterpreterTable = pkgs.callPackage ./doc-support/python-interpreter-table.nix {};

in pkgs.stdenv.mkDerivation {
name = "nixpkgs-manual";

nativeBuildInputs = with pkgs; [
nixos-render-docs
];

src = fs.toSource {
root = ./.;
fileset = fs.unions [
(fs.fileFilter (file:
file.hasExt "md"
|| file.hasExt "md.in"
) ./.)
./style.css
./anchor-use.js
./anchor.min.js
./manpage-urls.json
];
};

postPatch = ''
ln -s ${optionsDoc.optionsJSON}/share/doc/nixos/options.json ./config-options.json
'';

buildPhase = ''
substituteInPlace ./languages-frameworks/python.section.md \
--subst-var-by python-interpreter-table "$(<"${pythonInterpreterTable}")"
cat \
./functions/library.md.in \
${lib-docs}/index.md \
> ./functions/library.md
substitute ./manual.md.in ./manual.md \
--replace-fail '@MANUAL_VERSION@' '${pkgs.lib.version}'
mkdir -p out/media
mkdir -p out/highlightjs
cp -t out/highlightjs \
${pkgs.documentation-highlighter}/highlight.pack.js \
${pkgs.documentation-highlighter}/LICENSE \
${pkgs.documentation-highlighter}/mono-blue.css \
${pkgs.documentation-highlighter}/loader.js
cp -t out ./style.css ./anchor.min.js ./anchor-use.js
nixos-render-docs manual html \
--manpage-urls ./manpage-urls.json \
--revision ${pkgs.lib.trivial.revisionWithDefault (pkgs.rev or "master")} \
--stylesheet style.css \
--stylesheet highlightjs/mono-blue.css \
--script ./highlightjs/highlight.pack.js \
--script ./highlightjs/loader.js \
--script ./anchor.min.js \
--script ./anchor-use.js \
--toc-depth 1 \
--section-toc-depth 1 \
manual.md \
out/index.html
'';

installPhase = ''
dest="$out/${common.outputPath}"
mkdir -p "$(dirname "$dest")"
mv out "$dest"
mv "$dest/index.html" "$dest/${common.indexPath}"
cp ${epub} "$dest/nixpkgs-manual.epub"
mkdir -p $out/nix-support/
echo "doc manual $dest ${common.indexPath}" >> $out/nix-support/hydra-build-products
echo "doc manual $dest nixpkgs-manual.epub" >> $out/nix-support/hydra-build-products
'';

passthru = {
inherit pythonInterpreterTable;
tests.manpage-urls = callPackage ./tests/manpage-urls.nix { };
};
}
pkgs.callPackage ./doc-support/package.nix { inherit nixpkgs; }
1 change: 1 addition & 0 deletions doc/doc-support/epub.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# To run this derivation, `nix-build -A nixpkgs-manual.epub`
{
lib,
runCommand,
Expand Down
2 changes: 1 addition & 1 deletion doc/doc-support/lib-function-docs.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generates the documentation for library functions via nixdoc.

# To run this derivation, `nix-build -A nixpkgs-manual.lib-docs`
{
lib,
stdenvNoCC,
Expand Down
1 change: 1 addition & 0 deletions doc/doc-support/options-doc.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# To run this derivation, `nix-build -A nixpkgs-manual.optionsDoc`
{ lib, nixosOptionsDoc }:

let
Expand Down
103 changes: 103 additions & 0 deletions doc/doc-support/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
lib,
stdenvNoCC,
callPackage,
documentation-highlighter,
nixos-render-docs,
nixpkgs ? { },
}:

let
common = import ../common.nix;
in

stdenvNoCC.mkDerivation (
finalAttrs:
let
inherit (finalAttrs.finalPackage.optionsDoc) optionsJSON;
inherit (finalAttrs.finalPackage) epub lib-docs pythonInterpreterTable;
in
{
name = "nixpkgs-manual";

nativeBuildInputs = [ nixos-render-docs ];

src = lib.fileset.toSource {
root = ../.;
fileset = lib.fileset.unions [
(lib.fileset.fileFilter (file: file.hasExt "md" || file.hasExt "md.in") ../.)
../style.css
../anchor-use.js
../anchor.min.js
../manpage-urls.json
];
};

postPatch = ''
ln -s ${optionsJSON}/share/doc/nixos/options.json ./config-options.json
'';

buildPhase = ''
substituteInPlace ./languages-frameworks/python.section.md \
--subst-var-by python-interpreter-table "$(<"${pythonInterpreterTable}")"
cat \
./functions/library.md.in \
${lib-docs}/index.md \
> ./functions/library.md
substitute ./manual.md.in ./manual.md \
--replace-fail '@MANUAL_VERSION@' '${lib.version}'
mkdir -p out/media
mkdir -p out/highlightjs
cp -t out/highlightjs \
${documentation-highlighter}/highlight.pack.js \
${documentation-highlighter}/LICENSE \
${documentation-highlighter}/mono-blue.css \
${documentation-highlighter}/loader.js
cp -t out ./style.css ./anchor.min.js ./anchor-use.js
nixos-render-docs manual html \
--manpage-urls ./manpage-urls.json \
--revision ${lib.trivial.revisionWithDefault (nixpkgs.rev or "master")} \
--stylesheet style.css \
--stylesheet highlightjs/mono-blue.css \
--script ./highlightjs/highlight.pack.js \
--script ./highlightjs/loader.js \
--script ./anchor.min.js \
--script ./anchor-use.js \
--toc-depth 1 \
--section-toc-depth 1 \
manual.md \
out/index.html
'';

installPhase = ''
dest="$out/${common.outputPath}"
mkdir -p "$(dirname "$dest")"
mv out "$dest"
mv "$dest/index.html" "$dest/${common.indexPath}"
cp ${epub} "$dest/nixpkgs-manual.epub"
mkdir -p $out/nix-support/
echo "doc manual $dest ${common.indexPath}" >> $out/nix-support/hydra-build-products
echo "doc manual $dest nixpkgs-manual.epub" >> $out/nix-support/hydra-build-products
'';

passthru = {
lib-docs = callPackage ./lib-function-docs.nix { inherit nixpkgs; };

epub = callPackage ./epub.nix { };

# NB: This file describes the Nixpkgs manual, which happens to use module docs infra originally developed for NixOS.
optionsDoc = callPackage ./options-doc.nix { };

pythonInterpreterTable = callPackage ./python-interpreter-table.nix { };

tests.manpage-urls = callPackage ../tests/manpage-urls.nix { };
};
}
)
1 change: 1 addition & 0 deletions doc/tests/manpage-urls.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# To run this derivation, `nix-build -A nixpkgs-manual.tests.manpage-urls`
{
lib,
runCommand,
Expand Down

1 comment on commit 4252286

@nixos-discourse
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/suppress-warnings-for-a-derivation/49271/6

Please sign in to comment.