2023-02-01 20:11:37 +01:00
|
|
|
{
|
2024-04-09 09:02:58 +02:00
|
|
|
inputs,
|
2023-02-01 20:11:37 +01:00
|
|
|
pkgs,
|
2024-07-12 00:49:44 +02:00
|
|
|
lib,
|
2024-04-18 20:07:19 +02:00
|
|
|
manpageUrls ? pkgs.path + "/doc/manpage-urls.json",
|
2023-12-09 20:03:58 +01:00
|
|
|
...
|
2023-02-01 20:11:37 +01:00
|
|
|
}: let
|
2024-04-09 10:16:23 +02:00
|
|
|
inherit (lib.modules) mkForce evalModules;
|
|
|
|
inherit (lib.strings) hasPrefix removePrefix;
|
|
|
|
inherit (lib.attrsets) isAttrs mapAttrs optionalAttrs recursiveUpdate isDerivation;
|
2024-04-18 20:07:19 +02:00
|
|
|
inherit (builtins) fromJSON readFile;
|
|
|
|
|
|
|
|
# release data
|
|
|
|
release-config = fromJSON (readFile ../release.json);
|
|
|
|
revision = release-config.release;
|
2024-04-09 10:16:23 +02:00
|
|
|
|
|
|
|
# From home-manager:
|
|
|
|
#
|
|
|
|
# Recursively replace each derivation in the given attribute set
|
|
|
|
# with the same derivation but with the `outPath` attribute set to
|
|
|
|
# the string `"\${pkgs.attribute.path}"`. This allows the
|
|
|
|
# documentation to refer to derivations through their values without
|
|
|
|
# establishing an actual dependency on the derivation output.
|
|
|
|
#
|
|
|
|
# This is not perfect, but it seems to cover a vast majority of use
|
|
|
|
# cases.
|
|
|
|
#
|
|
|
|
# Caveat: even if the package is reached by a different means, the
|
|
|
|
# path above will be shown and not e.g.
|
|
|
|
# `${config.services.foo.package}`.
|
|
|
|
scrubDerivations = prefixPath: attrs: let
|
|
|
|
scrubDerivation = name: value: let
|
|
|
|
pkgAttrName = prefixPath + "." + name;
|
|
|
|
in
|
|
|
|
if isAttrs value
|
|
|
|
then
|
|
|
|
scrubDerivations pkgAttrName value
|
|
|
|
// optionalAttrs (isDerivation value) {
|
|
|
|
outPath = "\${${pkgAttrName}}";
|
|
|
|
}
|
|
|
|
else value;
|
|
|
|
in
|
|
|
|
mapAttrs scrubDerivation attrs;
|
2023-09-27 15:06:12 +02:00
|
|
|
|
|
|
|
# Make sure the used package is scrubbed to avoid actually
|
|
|
|
# instantiating derivations.
|
2023-02-01 20:11:37 +01:00
|
|
|
scrubbedPkgsModule = {
|
|
|
|
imports = [
|
|
|
|
{
|
|
|
|
_module.args = {
|
2024-04-09 10:16:23 +02:00
|
|
|
pkgs = mkForce (scrubDerivations "pkgs" pkgs);
|
|
|
|
pkgs_i686 = mkForce {};
|
2023-02-01 20:11:37 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-04-09 10:16:23 +02:00
|
|
|
# Specify the path to the module entrypoint
|
2023-12-09 20:21:36 +01:00
|
|
|
nvimPath = toString ./..;
|
2023-11-04 12:30:04 +01:00
|
|
|
buildOptionsDocs = args @ {
|
|
|
|
modules,
|
2023-12-09 20:03:58 +01:00
|
|
|
includeModuleSystemOptions ? true,
|
2024-04-18 20:07:19 +02:00
|
|
|
warningsAreErrors ? true,
|
2023-11-04 12:30:04 +01:00
|
|
|
...
|
|
|
|
}: let
|
2024-04-09 10:16:23 +02:00
|
|
|
inherit ((evalModules {inherit modules;})) options;
|
|
|
|
|
|
|
|
# Declaration of the Github site URL.
|
2024-04-18 20:07:19 +02:00
|
|
|
# Takes a user, repo, and subpath, and returns a declaration site
|
|
|
|
# as a string.
|
2024-04-09 10:16:23 +02:00
|
|
|
githubDeclaration = user: repo: subpath: let
|
|
|
|
urlRef = "github.com";
|
|
|
|
branch = "main";
|
|
|
|
in {
|
|
|
|
url = "https://${urlRef}/${user}/${repo}/blob/${branch}/${subpath}";
|
|
|
|
name = "<${repo}/${subpath}>";
|
|
|
|
};
|
2023-11-04 12:30:04 +01:00
|
|
|
in
|
2023-12-09 20:03:58 +01:00
|
|
|
pkgs.buildPackages.nixosOptionsDoc ({
|
2024-04-18 20:07:19 +02:00
|
|
|
inherit warningsAreErrors;
|
|
|
|
|
2023-11-04 12:30:04 +01:00
|
|
|
options =
|
2023-12-09 20:03:58 +01:00
|
|
|
if includeModuleSystemOptions
|
2023-11-04 12:30:04 +01:00
|
|
|
then options
|
2023-12-09 20:03:58 +01:00
|
|
|
else builtins.removeAttrs options ["_module"];
|
2024-04-18 20:07:19 +02:00
|
|
|
|
2023-11-04 12:30:04 +01:00
|
|
|
transformOptions = opt:
|
2024-04-09 10:16:23 +02:00
|
|
|
recursiveUpdate opt {
|
2024-04-27 14:44:37 +02:00
|
|
|
# Clean up declaration sites to not refer to the nvf
|
2023-12-09 20:03:58 +01:00
|
|
|
# source tree.
|
|
|
|
declarations = map (decl:
|
2024-04-09 10:16:23 +02:00
|
|
|
if hasPrefix nvimPath (toString decl)
|
2023-12-09 20:03:58 +01:00
|
|
|
then
|
2024-04-27 14:44:37 +02:00
|
|
|
githubDeclaration "notashelf" "nvf"
|
2024-04-09 10:16:23 +02:00
|
|
|
(removePrefix "/" (removePrefix nvimPath (toString decl)))
|
2023-12-09 20:03:58 +01:00
|
|
|
else if decl == "lib/modules.nix"
|
|
|
|
then
|
|
|
|
# TODO: handle this in a better way (may require upstream
|
|
|
|
# changes to nixpkgs)
|
|
|
|
githubDeclaration "NixOS" "nixpkgs" decl
|
|
|
|
else decl)
|
|
|
|
opt.declarations;
|
2023-11-04 12:30:04 +01:00
|
|
|
};
|
|
|
|
}
|
2023-12-09 20:03:58 +01:00
|
|
|
// builtins.removeAttrs args ["modules" "includeModuleSystemOptions"]);
|
2023-11-04 12:30:04 +01:00
|
|
|
|
|
|
|
nvimModuleDocs = buildOptionsDocs {
|
2024-04-27 14:44:37 +02:00
|
|
|
variablelistId = "nvf-options";
|
2024-04-18 20:07:19 +02:00
|
|
|
|
2023-02-01 20:11:37 +01:00
|
|
|
modules =
|
2023-12-09 20:03:58 +01:00
|
|
|
import ../modules/modules.nix {
|
|
|
|
inherit lib pkgs;
|
2023-02-01 20:11:37 +01:00
|
|
|
check = false;
|
|
|
|
}
|
2023-11-04 12:30:04 +01:00
|
|
|
++ [scrubbedPkgsModule];
|
2023-02-01 20:11:37 +01:00
|
|
|
};
|
|
|
|
|
2023-12-09 20:03:58 +01:00
|
|
|
# Generate the `man home-configuration.nix` package
|
2023-12-09 20:28:52 +01:00
|
|
|
nvf-configuration-manual =
|
2024-04-27 14:44:37 +02:00
|
|
|
pkgs.runCommand "nvf-reference-manpage" {
|
2023-12-09 20:03:58 +01:00
|
|
|
nativeBuildInputs = [pkgs.buildPackages.installShellFiles pkgs.nixos-render-docs];
|
|
|
|
allowedReferences = ["out"];
|
|
|
|
} ''
|
|
|
|
# Generate manpages.
|
|
|
|
mkdir -p $out/share/man/man5
|
|
|
|
mkdir -p $out/share/man/man1
|
2024-04-09 10:16:23 +02:00
|
|
|
|
2023-12-09 20:03:58 +01:00
|
|
|
nixos-render-docs -j $NIX_BUILD_CORES options manpage \
|
|
|
|
--revision ${revision} \
|
2024-04-20 23:29:17 +02:00
|
|
|
--header ${./man/header.5} \
|
|
|
|
--footer ${./man/footer.5} \
|
2023-12-09 20:03:58 +01:00
|
|
|
${nvimModuleDocs.optionsJSON}/share/doc/nixos/options.json \
|
2024-04-27 14:44:37 +02:00
|
|
|
$out/share/man/man5/nvf.5
|
2024-04-09 10:16:23 +02:00
|
|
|
|
2024-04-27 14:44:37 +02:00
|
|
|
cp ${./man/nvf.1} $out/share/man/man1/nvf.1
|
2023-02-01 20:11:37 +01:00
|
|
|
'';
|
2024-04-09 10:16:23 +02:00
|
|
|
|
2023-12-09 20:03:58 +01:00
|
|
|
# Generate the HTML manual pages
|
2024-04-27 14:44:37 +02:00
|
|
|
nvf-manual = pkgs.callPackage ./manual.nix {
|
2024-04-18 20:07:19 +02:00
|
|
|
inherit revision manpageUrls;
|
2024-04-27 14:44:37 +02:00
|
|
|
outputPath = "share/doc/nvf";
|
2023-12-09 20:03:58 +01:00
|
|
|
options = {
|
2024-04-27 14:44:37 +02:00
|
|
|
nvf = nvimModuleDocs.optionsJSON;
|
2023-12-09 20:03:58 +01:00
|
|
|
};
|
2023-02-01 20:11:37 +01:00
|
|
|
};
|
2024-04-09 10:16:23 +02:00
|
|
|
|
2024-04-27 14:44:37 +02:00
|
|
|
html = nvf-manual;
|
2023-12-09 20:03:58 +01:00
|
|
|
htmlOpenTool = pkgs.callPackage ./html-open-tool.nix {} {inherit html;};
|
2023-02-01 20:11:37 +01:00
|
|
|
in {
|
2024-04-09 09:02:58 +02:00
|
|
|
inherit (inputs) nmd;
|
2023-11-04 12:30:04 +01:00
|
|
|
|
2023-12-09 20:03:58 +01:00
|
|
|
options = {
|
|
|
|
# TODO: Use `hmOptionsDocs.optionsJSON` directly once upstream
|
|
|
|
# `nixosOptionsDoc` is more customizable.
|
|
|
|
json =
|
|
|
|
pkgs.runCommand "options.json" {
|
2024-04-27 14:44:37 +02:00
|
|
|
meta.description = "List of nvf options in JSON format";
|
2023-12-09 20:03:58 +01:00
|
|
|
} ''
|
|
|
|
mkdir -p $out/{share/doc,nix-support}
|
2024-04-27 14:44:37 +02:00
|
|
|
cp -a ${nvimModuleDocs.optionsJSON}/share/doc/nixos $out/share/doc/nvf
|
2023-12-09 20:03:58 +01:00
|
|
|
substitute \
|
|
|
|
${nvimModuleDocs.optionsJSON}/nix-support/hydra-build-products \
|
|
|
|
$out/nix-support/hydra-build-products \
|
|
|
|
--replace \
|
|
|
|
'${nvimModuleDocs.optionsJSON}/share/doc/nixos' \
|
2024-04-27 14:44:37 +02:00
|
|
|
"$out/share/doc/nvf"
|
2023-12-09 20:03:58 +01:00
|
|
|
'';
|
|
|
|
};
|
2023-11-04 12:30:04 +01:00
|
|
|
|
2023-12-09 20:28:52 +01:00
|
|
|
manPages = nvf-configuration-manual;
|
2023-12-09 20:03:58 +01:00
|
|
|
manual = {inherit html htmlOpenTool;};
|
2023-02-01 20:11:37 +01:00
|
|
|
}
|