mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-09-06 02:11:33 +00:00
lib.neovimConfiguration: deprecated extraModules and configuration (#377)
Some checks failed
Set up binary cache / cachix (default) (push) Has been cancelled
Set up binary cache / cachix (maximal) (push) Has been cancelled
Set up binary cache / cachix (nix) (push) Has been cancelled
Validate flake & check documentation / Validate Flake Documentation (docs) (push) Has been cancelled
Validate flake & check documentation / Validate Flake Documentation (docs-html) (push) Has been cancelled
Validate flake & check documentation / Validate Flake Documentation (docs-json) (push) Has been cancelled
Validate flake & check documentation / Validate Flake Documentation (docs-manpages) (push) Has been cancelled
Validate flake & check formatting / Validate Flake (push) Has been cancelled
Validate flake & check formatting / Formatting via Alejandra (push) Has been cancelled
Build and deploy documentation / Check latest commit (push) Has been cancelled
Build and deploy documentation / publish (push) Has been cancelled
Some checks failed
Set up binary cache / cachix (default) (push) Has been cancelled
Set up binary cache / cachix (maximal) (push) Has been cancelled
Set up binary cache / cachix (nix) (push) Has been cancelled
Validate flake & check documentation / Validate Flake Documentation (docs) (push) Has been cancelled
Validate flake & check documentation / Validate Flake Documentation (docs-html) (push) Has been cancelled
Validate flake & check documentation / Validate Flake Documentation (docs-json) (push) Has been cancelled
Validate flake & check documentation / Validate Flake Documentation (docs-manpages) (push) Has been cancelled
Validate flake & check formatting / Validate Flake (push) Has been cancelled
Validate flake & check formatting / Formatting via Alejandra (push) Has been cancelled
Build and deploy documentation / Check latest commit (push) Has been cancelled
Build and deploy documentation / publish (push) Has been cancelled
* lib.neovimConfiguration: deprecated extraModules and configuration * docs: various fixes
This commit is contained in:
parent
99ace503ad
commit
57be605ed4
9 changed files with 257 additions and 283 deletions
268
docs/default.nix
268
docs/default.nix
|
@ -2,131 +2,135 @@
|
|||
inputs,
|
||||
pkgs,
|
||||
lib,
|
||||
manpageUrls ? pkgs.path + "/doc/manpage-urls.json",
|
||||
...
|
||||
}: let
|
||||
inherit (lib.modules) mkForce evalModules;
|
||||
inherit (lib.strings) hasPrefix removePrefix;
|
||||
inherit (lib.attrsets) isAttrs mapAttrs optionalAttrs recursiveUpdate isDerivation;
|
||||
inherit (builtins) fromJSON readFile;
|
||||
inherit ((lib.importJSON ../release.json)) release;
|
||||
|
||||
# release data
|
||||
release-config = fromJSON (readFile ../release.json);
|
||||
revision = release-config.release;
|
||||
|
||||
# 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;
|
||||
|
||||
# Make sure the used package is scrubbed to avoid actually
|
||||
# instantiating derivations.
|
||||
scrubbedPkgsModule = {
|
||||
imports = [
|
||||
{
|
||||
_module.args = {
|
||||
pkgs = mkForce (scrubDerivations "pkgs" pkgs);
|
||||
pkgs_i686 = mkForce {};
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
# Specify the path to the module entrypoint
|
||||
nvimPath = toString ./..;
|
||||
buildOptionsDocs = args @ {
|
||||
modules,
|
||||
includeModuleSystemOptions ? true,
|
||||
warningsAreErrors ? true,
|
||||
...
|
||||
}: let
|
||||
inherit ((evalModules {inherit modules;})) options;
|
||||
|
||||
# Declaration of the Github site URL.
|
||||
# Takes a user, repo, and subpath, and returns a declaration site
|
||||
# as a string.
|
||||
githubDeclaration = user: repo: subpath: let
|
||||
urlRef = "github.com";
|
||||
branch = "main";
|
||||
in {
|
||||
url = "https://${urlRef}/${user}/${repo}/blob/${branch}/${subpath}";
|
||||
name = "<${repo}/${subpath}>";
|
||||
};
|
||||
in
|
||||
pkgs.buildPackages.nixosOptionsDoc ({
|
||||
inherit warningsAreErrors;
|
||||
|
||||
options =
|
||||
if includeModuleSystemOptions
|
||||
then options
|
||||
else builtins.removeAttrs options ["_module"];
|
||||
|
||||
transformOptions = opt:
|
||||
recursiveUpdate opt {
|
||||
# Clean up declaration sites to not refer to the nvf
|
||||
# source tree.
|
||||
declarations = map (decl:
|
||||
if hasPrefix nvimPath (toString decl)
|
||||
then
|
||||
githubDeclaration "notashelf" "nvf"
|
||||
(removePrefix "/" (removePrefix nvimPath (toString decl)))
|
||||
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;
|
||||
};
|
||||
}
|
||||
// builtins.removeAttrs args ["modules" "includeModuleSystemOptions"]);
|
||||
|
||||
nvimModuleDocs = buildOptionsDocs {
|
||||
nvimModuleDocs = pkgs.nixosOptionsDoc {
|
||||
variablelistId = "nvf-options";
|
||||
warningsAreErrors = true;
|
||||
|
||||
modules =
|
||||
import ../modules/modules.nix {
|
||||
inherit lib pkgs;
|
||||
check = false;
|
||||
}
|
||||
++ [scrubbedPkgsModule];
|
||||
inherit
|
||||
(
|
||||
(lib.evalModules {
|
||||
modules =
|
||||
import ../modules/modules.nix {
|
||||
inherit lib pkgs;
|
||||
}
|
||||
++ [
|
||||
(
|
||||
let
|
||||
# From nixpkgs:
|
||||
#
|
||||
# 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 = namePrefix: pkgSet:
|
||||
builtins.mapAttrs (
|
||||
name: value: let
|
||||
wholeName = "${namePrefix}.${name}";
|
||||
in
|
||||
if builtins.isAttrs value
|
||||
then
|
||||
scrubDerivations wholeName value
|
||||
// lib.optionalAttrs (lib.isDerivation value) {
|
||||
inherit (value) drvPath;
|
||||
outPath = "\${${wholeName}}";
|
||||
}
|
||||
else value
|
||||
)
|
||||
pkgSet;
|
||||
in {
|
||||
_module = {
|
||||
check = false;
|
||||
args.pkgs = lib.mkForce (scrubDerivations "pkgs" pkgs);
|
||||
};
|
||||
}
|
||||
)
|
||||
];
|
||||
})
|
||||
)
|
||||
options
|
||||
;
|
||||
|
||||
transformOptions = opt:
|
||||
opt
|
||||
// {
|
||||
declarations =
|
||||
map (
|
||||
decl:
|
||||
if lib.hasPrefix (toString ../.) (toString decl)
|
||||
then
|
||||
lib.pipe decl [
|
||||
toString
|
||||
(lib.removePrefix (toString ../.))
|
||||
(lib.removePrefix "/")
|
||||
(x: {
|
||||
url = "https://github.com/NotAShelf/nvf/blob/main/${decl}";
|
||||
name = "<nvf/${x}>";
|
||||
})
|
||||
]
|
||||
else if decl == "lib/modules.nix"
|
||||
then {
|
||||
url = "https://github.com/NixOS/nixpkgs/blob/master/${decl}";
|
||||
name = "<nixpkgs/lib/modules.nix>";
|
||||
}
|
||||
else decl
|
||||
)
|
||||
opt.declarations;
|
||||
};
|
||||
};
|
||||
|
||||
# Generate the HTML manual pages
|
||||
html = pkgs.callPackage ./manual.nix {
|
||||
inherit release;
|
||||
inherit (nvimModuleDocs) optionsJSON;
|
||||
};
|
||||
in {
|
||||
inherit (inputs) nmd;
|
||||
|
||||
# TODO: Use `hmOptionsDocs.optionsJSON` directly once upstream
|
||||
# `nixosOptionsDoc` is more customizable.
|
||||
options.json =
|
||||
pkgs.runCommand "options.json"
|
||||
{
|
||||
meta.description = "List of nvf options in JSON format";
|
||||
}
|
||||
''
|
||||
mkdir -p $out/{share/doc,nix-support}
|
||||
cp -a ${nvimModuleDocs.optionsJSON}/share/doc/nixos $out/share/doc/nvf
|
||||
substitute \
|
||||
${nvimModuleDocs.optionsJSON}/nix-support/hydra-build-products \
|
||||
$out/nix-support/hydra-build-products \
|
||||
--replace \
|
||||
'${nvimModuleDocs.optionsJSON}/share/doc/nixos' \
|
||||
"$out/share/doc/nvf"
|
||||
'';
|
||||
|
||||
# Generate the `man home-configuration.nix` package
|
||||
nvf-configuration-manual =
|
||||
pkgs.runCommand "nvf-reference-manpage" {
|
||||
nativeBuildInputs = [pkgs.buildPackages.installShellFiles pkgs.nixos-render-docs];
|
||||
manPages =
|
||||
pkgs.runCommand "nvf-reference-manpage"
|
||||
{
|
||||
nativeBuildInputs = [
|
||||
pkgs.buildPackages.installShellFiles
|
||||
pkgs.nixos-render-docs
|
||||
];
|
||||
allowedReferences = ["out"];
|
||||
} ''
|
||||
}
|
||||
''
|
||||
# Generate manpages.
|
||||
mkdir -p $out/share/man/man5
|
||||
mkdir -p $out/share/man/man1
|
||||
mkdir -p $out/share/man/{man5,man1}
|
||||
|
||||
nixos-render-docs -j $NIX_BUILD_CORES options manpage \
|
||||
--revision ${revision} \
|
||||
--revision ${release} \
|
||||
--header ${./man/header.5} \
|
||||
--footer ${./man/footer.5} \
|
||||
${nvimModuleDocs.optionsJSON}/share/doc/nixos/options.json \
|
||||
|
@ -135,38 +139,8 @@
|
|||
cp ${./man/nvf.1} $out/share/man/man1/nvf.1
|
||||
'';
|
||||
|
||||
# Generate the HTML manual pages
|
||||
nvf-manual = pkgs.callPackage ./manual.nix {
|
||||
inherit revision manpageUrls;
|
||||
outputPath = "share/doc/nvf";
|
||||
options = {
|
||||
nvf = nvimModuleDocs.optionsJSON;
|
||||
};
|
||||
manual = {
|
||||
inherit html;
|
||||
htmlOpenTool = pkgs.callPackage ./html-open-tool.nix {inherit html;};
|
||||
};
|
||||
|
||||
html = nvf-manual;
|
||||
htmlOpenTool = pkgs.callPackage ./html-open-tool.nix {} {inherit html;};
|
||||
in {
|
||||
inherit (inputs) nmd;
|
||||
|
||||
options = {
|
||||
# TODO: Use `hmOptionsDocs.optionsJSON` directly once upstream
|
||||
# `nixosOptionsDoc` is more customizable.
|
||||
json =
|
||||
pkgs.runCommand "options.json" {
|
||||
meta.description = "List of nvf options in JSON format";
|
||||
} ''
|
||||
mkdir -p $out/{share/doc,nix-support}
|
||||
cp -a ${nvimModuleDocs.optionsJSON}/share/doc/nixos $out/share/doc/nvf
|
||||
substitute \
|
||||
${nvimModuleDocs.optionsJSON}/nix-support/hydra-build-products \
|
||||
$out/nix-support/hydra-build-products \
|
||||
--replace \
|
||||
'${nvimModuleDocs.optionsJSON}/share/doc/nixos' \
|
||||
"$out/share/doc/nvf"
|
||||
'';
|
||||
};
|
||||
|
||||
manPages = nvf-configuration-manual;
|
||||
manual = {inherit html htmlOpenTool;};
|
||||
}
|
||||
|
|
|
@ -2,13 +2,9 @@
|
|||
writeShellScriptBin,
|
||||
makeDesktopItem,
|
||||
symlinkJoin,
|
||||
}: {
|
||||
html,
|
||||
pathName ? "nvf",
|
||||
projectName ? pathName,
|
||||
name ? "${pathName}-help",
|
||||
}: let
|
||||
helpScript = writeShellScriptBin name ''
|
||||
helpScript = writeShellScriptBin "nvf-help" ''
|
||||
set -euo pipefail
|
||||
|
||||
if [[ ! -v BROWSER || -z $BROWSER ]]; then
|
||||
|
@ -24,20 +20,23 @@
|
|||
echo "$0: unable to start a web browser; please set \$BROWSER"
|
||||
exit 1
|
||||
else
|
||||
exec "$BROWSER" "${html}/share/doc/${pathName}/index.xhtml"
|
||||
exec "$BROWSER" "${html}/share/doc/nvf/index.xhtml"
|
||||
fi
|
||||
'';
|
||||
|
||||
desktopItem = makeDesktopItem {
|
||||
name = "${pathName}-manual";
|
||||
desktopName = "${projectName} Manual";
|
||||
genericName = "View ${projectName} documentation in a web browser";
|
||||
name = "nvf-manual";
|
||||
desktopName = "nvf Manual";
|
||||
genericName = "View nvf documentation in a web browser";
|
||||
icon = "nix-snowflake";
|
||||
exec = "${helpScript}/bin/${name}";
|
||||
exec = "${helpScript}/bin/nvf-help";
|
||||
categories = ["System"];
|
||||
};
|
||||
in
|
||||
symlinkJoin {
|
||||
inherit name;
|
||||
paths = [helpScript desktopItem];
|
||||
name = "nvf-help";
|
||||
paths = [
|
||||
helpScript
|
||||
desktopItem
|
||||
];
|
||||
}
|
||||
|
|
|
@ -4,11 +4,10 @@
|
|||
# build inputs
|
||||
nixos-render-docs,
|
||||
documentation-highlighter,
|
||||
path,
|
||||
# nrd configuration
|
||||
manpageUrls,
|
||||
revision,
|
||||
options,
|
||||
outputPath ? "share/doc/nvf",
|
||||
release,
|
||||
optionsJSON,
|
||||
}:
|
||||
stdenvNoCC.mkDerivation {
|
||||
name = "nvf-manual";
|
||||
|
@ -20,9 +19,11 @@ stdenvNoCC.mkDerivation {
|
|||
nativeBuildInputs = [nixos-render-docs];
|
||||
|
||||
buildPhase = ''
|
||||
mkdir -p out/{highlightjs,media}
|
||||
dest="$out/share/doc/nvf"
|
||||
mkdir -p "$(dirname "$dest")"
|
||||
mkdir -p $dest/{highlightjs,media}
|
||||
|
||||
cp -vt out/highlightjs \
|
||||
cp -vt $dest/highlightjs \
|
||||
${documentation-highlighter}/highlight.pack.js \
|
||||
${documentation-highlighter}/LICENSE \
|
||||
${documentation-highlighter}/mono-blue.css \
|
||||
|
@ -31,38 +32,32 @@ stdenvNoCC.mkDerivation {
|
|||
substituteInPlace ./options.md \
|
||||
--subst-var-by \
|
||||
OPTIONS_JSON \
|
||||
${options.nvf}/share/doc/nixos/options.json
|
||||
${optionsJSON}/share/doc/nixos/options.json
|
||||
|
||||
substituteInPlace ./manual.md \
|
||||
--subst-var-by \
|
||||
NVF_VERSION \
|
||||
${revision}
|
||||
${release}
|
||||
|
||||
# copy stylesheet
|
||||
cp ${./static/style.css} out/style.css
|
||||
cp ${./static/style.css} "$dest/style.css"
|
||||
|
||||
# copy release notes
|
||||
cp -vr ${./release-notes} release-notes
|
||||
|
||||
# generate manual from
|
||||
nixos-render-docs manual html \
|
||||
--manpage-urls ${manpageUrls} \
|
||||
--revision ${lib.trivial.revisionWithDefault revision} \
|
||||
--manpage-urls ${path + "/doc/manpage-urls.json"} \
|
||||
--revision ${lib.trivial.revisionWithDefault release} \
|
||||
--stylesheet style.css \
|
||||
--script highlightjs/highlight.pack.js \
|
||||
--script highlightjs/loader.js \
|
||||
--toc-depth 2 \
|
||||
--section-toc-depth 1 \
|
||||
manual.md \
|
||||
out/index.xhtml
|
||||
'';
|
||||
"$dest/index.xhtml"
|
||||
|
||||
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
|
||||
mkdir -p $out/nix-support/
|
||||
echo "doc manual $dest index.html" >> $out/nix-support/hydra-build-products
|
||||
'';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue