-
-
Notifications
You must be signed in to change notification settings - Fork 347
docs: experimental re-write #2884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b9aec4f
6c42d5a
96d8873
5d4f54d
00d0676
83350c7
599441a
d6eafb1
f09ff46
ba77348
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ lib, ... }: | ||
let | ||
transformOption = | ||
let | ||
root = builtins.toString ../../.; | ||
mkGitHubDeclaration = user: repo: branch: subpath: { | ||
url = "https://github.com/${user}/${repo}/blob/${branch}/${subpath}"; | ||
name = "<${repo}/${subpath}>"; | ||
}; | ||
transformDeclaration = | ||
decl: | ||
if lib.hasPrefix root (builtins.toString decl) then | ||
mkGitHubDeclaration "nix-community" "nixvim" "main" ( | ||
lib.removePrefix "/" (lib.strings.removePrefix root (builtins.toString decl)) | ||
) | ||
else if decl == "lib/modules.nix" then | ||
mkGitHubDeclaration "NixOS" "nixpkgs" "master" decl | ||
else | ||
decl; | ||
in | ||
opt: opt // { declarations = builtins.map transformDeclaration opt.declarations; }; | ||
in | ||
{ | ||
options.docs._utils = lib.mkOption { | ||
type = with lib.types; lazyAttrsOf raw; | ||
description = "internal utils, modules, functions, etc"; | ||
default = { }; | ||
internal = true; | ||
visible = false; | ||
}; | ||
|
||
config.docs._utils = { | ||
/** | ||
Uses `lib.optionAttrSetToDocList` to produce a list of docs-options. | ||
|
||
A doc-option has the following attrs, as expected by `nixos-render-docs`: | ||
|
||
``` | ||
{ | ||
loc, | ||
name, # rendered with `showOption loc` | ||
description, | ||
declarations, | ||
internal, | ||
visible, # normalised to a boolean | ||
readOnly, | ||
type, # normalised to `type.description` | ||
default,? # rendered with `lib.options.renderOptionValue` | ||
example,? # rendered with `lib.options.renderOptionValue` | ||
relatedPackages,? | ||
} | ||
``` | ||
|
||
Additionally, sub-options are recursively flattened into the list, | ||
unless `visible == "shallow"` or `visible == false`. | ||
|
||
This function extends `lib.optionAttrSetToDocList` by also filtering out | ||
invisible and internal options, and by applying Nixvim's `transformOption` | ||
function. | ||
|
||
The implementation is based on `pkgs.nixosOptionsDoc`: | ||
https://github.com/NixOS/nixpkgs/blob/e2078ef3/nixos/lib/make-options-doc/default.nix#L117-L126 | ||
*/ | ||
mkOptionList = lib.flip lib.pipe [ | ||
(lib.flip builtins.removeAttrs [ "_module" ]) | ||
lib.optionAttrSetToDocList | ||
(builtins.map transformOption) | ||
(builtins.filter (opt: opt.visible && !opt.internal)) | ||
# TODO: consider supporting `relatedPackages` | ||
# See https://github.com/NixOS/nixpkgs/blob/61235d44/lib/options.nix#L103-L104 | ||
# and https://github.com/NixOS/nixpkgs/blob/61235d44/nixos/lib/make-options-doc/default.nix#L128-L165 | ||
]; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
lib, | ||
runCommandLocal, | ||
pages, | ||
}: | ||
# Implementation based on NixOS's /etc module | ||
runCommandLocal "docs-sources" { } '' | ||
set -euo pipefail | ||
|
||
makeEntry() { | ||
src="$1" | ||
target="$2" | ||
mkdir -p "$out/$(dirname "$target")" | ||
cp "$src" "$out/$target" | ||
} | ||
|
||
mkdir -p "$out" | ||
${lib.concatMapStringsSep "\n" ( | ||
{ target, source, ... }: | ||
lib.escapeShellArgs [ | ||
"makeEntry" | ||
# Force local source paths to be added to the store | ||
"${source}" | ||
target | ||
] | ||
) pages} | ||
'' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ lib, pkgs, ... }: | ||
let | ||
# Convert links relative to github -> relative to docs | ||
fixLinks = pkgs.callPackage ../../docs/fix-links { }; | ||
in | ||
{ | ||
options.enableMan = lib.mkOption { | ||
type = lib.types.bool; | ||
default = true; | ||
description = "Install the man pages for NixVim options."; | ||
}; | ||
|
||
imports = [ | ||
./_utils.nix | ||
./mdbook | ||
./menu | ||
./option-pages | ||
./pages.nix | ||
./platforms.nix | ||
./user-guide | ||
]; | ||
|
||
config.docs = { | ||
pages."" = { | ||
menu.section = "header"; | ||
menu.location = [ "Home" ]; | ||
source = pkgs.callPackage ./readme.nix { | ||
inherit fixLinks; | ||
# TODO: get `availableVersions` and `baseHref` from module options | ||
}; | ||
}; | ||
pages.contributing = { | ||
menu.section = "footer"; | ||
menu.location = [ "Contributing" ]; | ||
source = fixLinks ../../CONTRIBUTING.md; | ||
}; | ||
optionPages.docs = { | ||
optionScopes = [ "docs" ]; | ||
page.menu.location = [ "docs" ]; | ||
page.text = '' | ||
Internal options used to construct these docs. | ||
''; | ||
}; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
lib, | ||
config, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
settingsFormat = pkgs.formats.toml { }; | ||
defaultSettings = { | ||
book = { | ||
language = "en"; | ||
multilingual = false; | ||
title = "nixvim docs"; | ||
}; | ||
build.create-missing = false; | ||
output.html.site-url = "/"; | ||
output.html.fold = { | ||
enable = true; | ||
level = 0; | ||
}; | ||
preprocessor.alerts = { }; | ||
}; | ||
in | ||
{ | ||
options.docs.html = { | ||
site = lib.mkOption { | ||
type = lib.types.package; | ||
description = "HTML docs rendered by mdbook."; | ||
readOnly = true; | ||
}; | ||
settings = lib.mkOption { | ||
inherit (settingsFormat) type; | ||
description = '' | ||
Freeform settings written to `book.toml`. | ||
|
||
See MDBook's [Configuration](https://rust-lang.github.io/mdBook/format/configuration/index.html) docs. | ||
''; | ||
defaultText = defaultSettings; | ||
}; | ||
}; | ||
config.docs.html = { | ||
site = pkgs.callPackage ./package.nix { | ||
inherit (config.docs) src; | ||
inherit (config.docs.html) settings; | ||
menu = config.docs.menu.src; | ||
writeTOML = settingsFormat.generate; | ||
}; | ||
settings = defaultSettings; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
mdbook, | ||
mdbook-alerts, | ||
runCommand, | ||
writeTOML, | ||
menu, | ||
settings, | ||
src, | ||
}: | ||
runCommand "html-docs" | ||
{ | ||
inherit src; | ||
|
||
nativeBuildInputs = [ | ||
mdbook | ||
mdbook-alerts | ||
]; | ||
|
||
settings = writeTOML "book.toml" settings; | ||
menu = builtins.toFile "menu.md" (builtins.unsafeDiscardStringContext menu); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment would be nice to say what is discarded, I guess the why is that docs are "inert"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied this from the nixos docs impl, and there was no comment to copy. I'll try come up with something. However, yeah "string context" is how nix keeps track of a string's dependencies. E.g. if you do Using In the context of the docs, I believe this is mainly relevant for the "declared by" links, and maybe any |
||
} | ||
'' | ||
mkdir src | ||
for input in $src/*; do | ||
name=$(basename "$input") | ||
ln -s "$input" "src/$name" | ||
done | ||
ln -s $settings book.toml | ||
ln -s $menu src/SUMMARY.md | ||
|
||
# Build the website | ||
mdbook build --dest-dir $out | ||
'' |
Uh oh!
There was an error while loading. Please reload this page.