1
0
Fork 0
selfhostblocks/docs/default.nix

198 lines
5.9 KiB
Nix
Raw Normal View History

# Taken nearly verbatim from https://github.com/nix-community/home-manager/pull/4673
{ pkgs
, buildPackages
, lib
, nmdsrc
, stdenv
, documentation-highlighter
, nixos-render-docs
, release
, allModules
}:
let
shbPath = toString ./..;
gitHubDeclaration = user: repo: subpath:
let urlRef = "main";
end = if subpath == "" then "" else "/" + subpath;
in {
url = "https://github.com/${user}/${repo}/blob/${urlRef}${end}";
name = "<${repo}${end}>";
};
ghRoot = (gitHubDeclaration "ibizaman" "selfhostblocks" "").url;
2024-09-08 08:33:22 +02:00
buildOptionsDocs = args@{ modules, ... }:
2023-12-08 19:44:47 +01:00
let
config = {
_module.check = false;
_module.args = {};
system.stateVersion = "22.11";
};
utils = import "${pkgs.path}/nixos/lib/utils.nix" {
inherit config lib;
pkgs = null;
};
eval = lib.evalModules {
inherit modules;
specialArgs = {
inherit utils;
};
};
2024-09-08 08:33:22 +02:00
options = lib.filterAttrs (name: v: name == "shb") eval.options;
in buildPackages.nixosOptionsDoc ({
2023-12-08 19:44:47 +01:00
inherit options;
transformOptions = opt:
opt // {
# Clean up declaration sites to not refer to the Home Manager
# source tree.
declarations = map (decl:
gitHubDeclaration "ibizaman" "selfhostblocks"
(lib.removePrefix "/" (lib.removePrefix shbPath (toString decl)))) opt.declarations;
};
} // builtins.removeAttrs args [ "modules" "includeModuleSystemOptions" ]);
scrubbedModule = {
_module.args.pkgs = lib.mkForce (nmd.scrubDerivations "pkgs" pkgs);
_module.check = false;
};
2024-09-08 08:33:22 +02:00
allOptionsDocs = paths: (buildOptionsDocs {
modules = paths ++ allModules ++ [ scrubbedModule ];
variablelistId = "selfhostblocks-options";
2024-09-08 08:33:22 +02:00
}).optionsJSON;
2024-09-08 08:33:22 +02:00
individualModuleOptionsDocs = paths: (buildOptionsDocs {
modules = paths ++ [ scrubbedModule ];
2023-12-24 07:50:22 +01:00
variablelistId = "selfhostblocks-options";
2024-01-12 08:22:46 +01:00
}).optionsJSON;
2023-12-24 07:50:22 +01:00
nmd = import nmdsrc {
inherit lib;
# The DocBook output of `nixos-render-docs` doesn't have the change
# `nmd` uses to work around the broken stylesheets in
# `docbook-xsl-ns`, so we restore the patched version here.
pkgs = pkgs // {
docbook-xsl-ns =
pkgs.docbook-xsl-ns.override { withManOptDedupPatch = true; };
};
};
outputPath = "share/doc/selfhostblocks";
manpage-urls = pkgs.writeText "manpage-urls.json" ''{}'';
in stdenv.mkDerivation {
name = "self-host-blocks-manual";
nativeBuildInputs = [ nixos-render-docs ];
2023-12-08 19:36:22 +01:00
# We include the parent so we get the documentation inside the root
# modules/ and demo/ folders.
src = ./..;
buildPhase = ''
cd docs
mkdir -p demo
cp -t . -r ../demo
2023-12-08 19:36:22 +01:00
cp -t . -r ../modules
mkdir -p out/media
mkdir -p out/highlightjs
mkdir -p out/static
cp -t out/highlightjs \
${documentation-highlighter}/highlight.pack.js \
${documentation-highlighter}/LICENSE \
${documentation-highlighter}/mono-blue.css \
${documentation-highlighter}/loader.js
cp -t out/static \
${nmdsrc}/static/style.css \
${nmdsrc}/static/highlightjs/tomorrow-night.min.css \
${nmdsrc}/static/highlightjs/highlight.min.js \
${nmdsrc}/static/highlightjs/highlight.load.js
substituteInPlace ./options.md \
--replace \
'@OPTIONS_JSON@' \
2024-09-08 08:33:22 +02:00
${allOptionsDocs [
(pkgs.path + "/nixos/modules/services/misc/forgejo.nix")
]}/share/doc/nixos/options.json
2024-01-12 08:22:46 +01:00
substituteInPlace ./modules/blocks/ssl/docs/default.md \
--replace \
'@OPTIONS_JSON@' \
2024-09-08 08:33:22 +02:00
${individualModuleOptionsDocs [ ../modules/blocks/ssl.nix ]}/share/doc/nixos/options.json
2024-01-12 08:22:46 +01:00
2024-08-20 07:09:10 +02:00
substituteInPlace ./modules/blocks/restic/docs/default.md \
--replace \
'@OPTIONS_JSON@' \
2024-09-08 08:33:22 +02:00
${individualModuleOptionsDocs [ ../modules/blocks/restic.nix ]}/share/doc/nixos/options.json
2023-12-24 07:50:22 +01:00
substituteInPlace ./modules/services/nextcloud-server/docs/default.md \
--replace \
'@OPTIONS_JSON@' \
2024-09-08 08:33:22 +02:00
${individualModuleOptionsDocs [ ../modules/services/nextcloud-server.nix ]}/share/doc/nixos/options.json
2023-12-24 07:50:22 +01:00
2024-08-12 04:34:01 +02:00
substituteInPlace ./modules/services/vaultwarden/docs/default.md \
--replace \
'@OPTIONS_JSON@' \
2024-09-08 08:33:22 +02:00
${individualModuleOptionsDocs [ ../modules/services/vaultwarden.nix ]}/share/doc/nixos/options.json
substituteInPlace ./modules/services/forgejo/docs/default.md \
--replace \
'@OPTIONS_JSON@' \
${individualModuleOptionsDocs [
../modules/services/forgejo.nix
(pkgs.path + "/nixos/modules/services/misc/forgejo.nix")
]}/share/doc/nixos/options.json
2024-08-12 04:34:01 +02:00
2024-08-20 07:09:10 +02:00
substituteInPlace ./modules/contracts/backup/docs/default.md \
--replace \
'@OPTIONS_JSON@' \
2024-09-08 08:33:22 +02:00
${individualModuleOptionsDocs [ ../modules/contracts/backup/dummyModule.nix ]}/share/doc/nixos/options.json
2024-08-20 07:09:10 +02:00
2024-04-15 00:21:20 +02:00
substituteInPlace ./modules/contracts/ssl/docs/default.md \
--replace \
'@OPTIONS_JSON@' \
2024-09-08 08:33:22 +02:00
${individualModuleOptionsDocs [ ../modules/contracts/ssl/dummyModule.nix ]}/share/doc/nixos/options.json
2024-04-15 00:21:20 +02:00
find . -name "*.md" -print0 | \
while IFS= read -r -d ''' f; do
substituteInPlace "''${f}" \
--replace \
'@REPO@' \
2024-01-12 08:22:46 +01:00
"${ghRoot}" 2>/dev/null
done
nixos-render-docs manual html \
--manpage-urls ${manpage-urls} \
--media-dir media \
--revision ${lib.trivial.revisionWithDefault release} \
--stylesheet static/style.css \
--stylesheet static/tomorrow-night.min.css \
--script static/highlight.min.js \
--script static/highlight.load.js \
--toc-depth 1 \
--section-toc-depth 1 \
manual.md \
out/index.html
'';
installPhase = ''
dest="$out/${outputPath}"
mkdir -p "$(dirname "$dest")"
mv out "$dest"
mkdir -p $out/nix-support/
echo "doc manual $dest index.html" >> $out/nix-support/hydra-build-products
'';
}