mirror of
https://github.com/nix-community/dream2nix.git
synced 2025-01-03 20:06:15 +03:00
add mkdocs-based docs site
This commit is contained in:
parent
2ab68c8d27
commit
7cb146701a
5
docs/mkdocs.yml
Normal file
5
docs/mkdocs.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
site_name: Dream2Nix
|
||||||
|
docs_dir: "src"
|
||||||
|
site_url: "https://nix-community.github.io/dream2nix"
|
||||||
|
site_dir: !ENV out
|
||||||
|
|
17
docs/package.nix
Normal file
17
docs/package.nix
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
python3,
|
||||||
|
}: let
|
||||||
|
package = python3.pkgs.buildPythonPackage {
|
||||||
|
name = "dream2nix_docs";
|
||||||
|
format = "pyproject";
|
||||||
|
src = ./.;
|
||||||
|
nativeBuildInputs = [
|
||||||
|
python3.pkgs.setuptools
|
||||||
|
];
|
||||||
|
propagatedBuildInputs = with python3.pkgs; [
|
||||||
|
mkdocs
|
||||||
|
];
|
||||||
|
};
|
||||||
|
in
|
||||||
|
package
|
11
docs/pyproject.toml
Normal file
11
docs/pyproject.toml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
[project]
|
||||||
|
name = "dream2nix_docs"
|
||||||
|
description = "documentation of dream2nix"
|
||||||
|
authors = [{ name = "David Hauer"}, {name = "Paul Haerle", email = "hello@phaer.org"}]
|
||||||
|
dynamic = ["version"]
|
||||||
|
dependencies = ["mkdocs"]
|
||||||
|
|
||||||
|
|
||||||
|
[tool.setuptools]
|
||||||
|
packages = [ "dream2nix_docs" ]
|
8
modules/dream2nix/pip/README.md
Normal file
8
modules/dream2nix/pip/README.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
state: released
|
||||||
|
maintainers: @phaer
|
||||||
|
---
|
||||||
|
|
||||||
|
# pip
|
||||||
|
|
||||||
|
Python packaging via [pip](https://pip.pypa.io/).
|
@ -9,39 +9,33 @@
|
|||||||
system,
|
system,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
modules' = self.modules.dream2nix;
|
|
||||||
modules = lib.filterAttrs (name: _: ! lib.elem name excludes) modules';
|
|
||||||
dream2nixRoot = ../../../.;
|
dream2nixRoot = ../../../.;
|
||||||
dream2nix = import dream2nixRoot;
|
dream2nix = import dream2nixRoot;
|
||||||
excludes = [
|
|
||||||
# NOT WORKING
|
|
||||||
# TODO: fix those
|
|
||||||
"core"
|
|
||||||
"ui"
|
|
||||||
"docs"
|
|
||||||
"assertions"
|
|
||||||
"nixpkgs-overrides"
|
|
||||||
|
|
||||||
# doesn't need to be rendered
|
|
||||||
"_template"
|
|
||||||
];
|
|
||||||
public = lib.genAttrs [
|
|
||||||
"nodejs-granular-v3"
|
|
||||||
"nodejs-package-lock-v3"
|
|
||||||
"php-composer-lock"
|
|
||||||
"php-granular"
|
|
||||||
"pip"
|
|
||||||
"rust-cargo-lock"
|
|
||||||
"rust-crane"
|
|
||||||
] (name: null);
|
|
||||||
|
|
||||||
# interface
|
|
||||||
sourcePathStr = toString dream2nix;
|
|
||||||
baseUrl = "https://github.com/nix-community/dream2nix/blob/master";
|
baseUrl = "https://github.com/nix-community/dream2nix/blob/master";
|
||||||
specialArgs = {
|
|
||||||
inherit dream2nix;
|
getOptions = {modules}: let
|
||||||
packageSets.nixpkgs = pkgs;
|
options = lib.flip lib.mapAttrs modules (
|
||||||
|
name: module: let
|
||||||
|
evaluated = lib.evalModules {
|
||||||
|
specialArgs = {
|
||||||
|
inherit dream2nix;
|
||||||
|
packageSets.nixpkgs = pkgs;
|
||||||
|
};
|
||||||
|
modules = [module];
|
||||||
|
};
|
||||||
|
in
|
||||||
|
evaluated.options
|
||||||
|
);
|
||||||
|
docs = lib.flip lib.mapAttrs options (name: options:
|
||||||
|
pkgs.nixosOptionsDoc {
|
||||||
|
inherit options;
|
||||||
|
inherit transformOptions;
|
||||||
|
warningsAreErrors = false;
|
||||||
|
});
|
||||||
|
in {
|
||||||
|
inherit options docs;
|
||||||
};
|
};
|
||||||
|
|
||||||
transformOptions = opt:
|
transformOptions = opt:
|
||||||
opt
|
opt
|
||||||
// {
|
// {
|
||||||
@ -49,7 +43,7 @@
|
|||||||
map
|
map
|
||||||
(
|
(
|
||||||
decl: let
|
decl: let
|
||||||
subpath = lib.removePrefix sourcePathStr (toString decl);
|
subpath = lib.removePrefix (toString dream2nix) (toString decl);
|
||||||
in {
|
in {
|
||||||
url = baseUrl + subpath;
|
url = baseUrl + subpath;
|
||||||
name = "dream2nix" + subpath;
|
name = "dream2nix" + subpath;
|
||||||
@ -57,144 +51,81 @@
|
|||||||
)
|
)
|
||||||
opt.declarations;
|
opt.declarations;
|
||||||
};
|
};
|
||||||
# 0 = no chapters, 1 = one level of chapters, 2 = two levels of chapters ...
|
|
||||||
chaptersNesting = 1;
|
|
||||||
# A tree where nodes are (sub)chapters and leafs are options.
|
|
||||||
# Nesting can be arbitrary
|
|
||||||
chaptersTree = {
|
|
||||||
"Modules" =
|
|
||||||
lib.filterAttrs (name: _: public ? ${name}) optionsTree;
|
|
||||||
"Modules (Internal + Experimental)" =
|
|
||||||
lib.filterAttrs (name: _: ! public ? ${name}) optionsTree;
|
|
||||||
};
|
|
||||||
optionsTree = lib.flip lib.mapAttrs modules (
|
|
||||||
name: module: let
|
|
||||||
evaluated = lib.evalModules {
|
|
||||||
inherit specialArgs;
|
|
||||||
modules = [module];
|
|
||||||
};
|
|
||||||
in
|
|
||||||
# lib.trace "Rendering Module ${name}"
|
|
||||||
(builtins.removeAttrs evaluated.options ["_module"])
|
|
||||||
);
|
|
||||||
|
|
||||||
# implementation
|
modules =
|
||||||
highlight-js = let
|
lib.filterAttrs (
|
||||||
highlight-core = pkgs.fetchurl {
|
name: _:
|
||||||
url = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js";
|
! lib.elem name
|
||||||
hash = "sha256-g3pvpbDHNrUrveKythkPMF2j/J7UFoHbUyFQcFe1yEY=";
|
[
|
||||||
};
|
# NOT WORKING
|
||||||
highlight-nix = pkgs.fetchurl {
|
# TODO: fix those
|
||||||
url = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/nix.min.js";
|
"core"
|
||||||
hash = "sha256-BLoZ+/OroDAxMsdZ4GFZtQfsg6ZJeLVNeBzN/82dYgk=";
|
"ui"
|
||||||
};
|
"docs"
|
||||||
in
|
"assertions"
|
||||||
pkgs.runCommand "highlight-js" {} ''
|
"nixpkgs-overrides"
|
||||||
cat ${highlight-core} > $out
|
# doesn't need to be rendered
|
||||||
cat ${highlight-nix} >> $out
|
"_template"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
dream2nix.modules.dream2nix;
|
||||||
|
|
||||||
|
options = getOptions {
|
||||||
|
inherit modules;
|
||||||
|
};
|
||||||
|
|
||||||
|
referenceDocs = let
|
||||||
|
publicModules =
|
||||||
|
lib.filterAttrs
|
||||||
|
(n: v: lib.pathExists (v + "/README.md"))
|
||||||
|
modules;
|
||||||
|
createReference = name: sourcePath: ''
|
||||||
|
target_dir="$out/${name}/"
|
||||||
|
mkdir -p "$target_dir"
|
||||||
|
ln -s ${sourcePath}/README.md "$target_dir"
|
||||||
|
ln -s ${options.docs.${name}.optionsJSON}/share/doc/nixos/options.json "$target_dir"
|
||||||
'';
|
'';
|
||||||
highlight-style = pkgs.fetchurl {
|
|
||||||
url = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/vs.min.css";
|
|
||||||
hash = "sha256-E1kfafj5iO+Tw/04hxdSG+OnvczojOXK2K0iCEYfzSw=";
|
|
||||||
};
|
|
||||||
optionsToMdFile = options: let
|
|
||||||
docs = pkgs.nixosOptionsDoc {
|
|
||||||
inherit options;
|
|
||||||
inherit transformOptions;
|
|
||||||
warningsAreErrors = false;
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
docs.optionsCommonMark;
|
pkgs.runCommand "reference" {
|
||||||
|
} ''
|
||||||
mdFiles = nesting: chapters:
|
${lib.concatStringsSep "\n" (lib.attrValues (lib.mapAttrs createReference publicModules))}
|
||||||
if nesting == 0
|
'';
|
||||||
then lib.mapAttrs (name: optionsToMdFile) chapters
|
|
||||||
else lib.concatMapAttrs (name: mdFiles (nesting - 1)) chapters;
|
|
||||||
|
|
||||||
mdFilesDir = pkgs.runCommand "md-files-dir" {} ''
|
|
||||||
mkdir -p $out
|
|
||||||
cp -r ${lib.concatStringsSep "\n cp -r " (lib.mapAttrsToList (name: file: "${file} $out/${name}.md") (mdFiles chaptersNesting chaptersTree))}
|
|
||||||
'';
|
|
||||||
|
|
||||||
spacing = depth:
|
|
||||||
if depth == 0
|
|
||||||
then "- "
|
|
||||||
else " " + spacing (depth - 1);
|
|
||||||
|
|
||||||
# returns "" for chapters with nesting or an md file for chapters with options
|
|
||||||
chapterUrl = nesting: name:
|
|
||||||
if nesting == 0
|
|
||||||
then "options/${name}.md"
|
|
||||||
else "";
|
|
||||||
|
|
||||||
renderChapters = depth: nesting: chapters:
|
|
||||||
lib.concatStringsSep "\n"
|
|
||||||
(lib.flip lib.mapAttrsToList chapters (
|
|
||||||
name: chapter:
|
|
||||||
"${spacing depth}[${name}](${chapterUrl nesting name})"
|
|
||||||
+ lib.optionalString (nesting > 0) (renderChapters (depth + 1) (nesting - 1) chapter)
|
|
||||||
));
|
|
||||||
|
|
||||||
summaryMdFile =
|
|
||||||
pkgs.writeText "summary.md"
|
|
||||||
(renderChapters 0 chaptersNesting chaptersTree);
|
|
||||||
|
|
||||||
mdBookSource = pkgs.runCommand "website-src" {} ''
|
|
||||||
mkdir -p $out/options
|
|
||||||
cp ${summaryMdFile} $out/SUMMARY.md
|
|
||||||
cp -r ${mdFilesDir}/* $out/options/
|
|
||||||
|
|
||||||
# add table of contents for each md file
|
|
||||||
for file in $out/options/*.md; do
|
|
||||||
name="$(basename "$file")"
|
|
||||||
name="''${name%.md}"
|
|
||||||
echo "# $name - options" > "$file.tmp"
|
|
||||||
echo '<!-- toc -->' | cat - "$file" >> "$file.tmp"
|
|
||||||
mv $file.tmp $file
|
|
||||||
done
|
|
||||||
'';
|
|
||||||
|
|
||||||
website =
|
website =
|
||||||
pkgs.runCommand "website" {
|
pkgs.runCommand "website" {
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
pkgs.mdbook
|
self.packages.${system}.mkdocs
|
||||||
pkgs.mdbook-linkcheck
|
referenceDocs
|
||||||
# This inserts a table of contents at each '<!-- toc -->'
|
|
||||||
inputs.mdbook-toc.defaultPackage.${system}
|
|
||||||
];
|
];
|
||||||
} ''
|
} ''
|
||||||
cp -rL --no-preserve=mode ${dream2nixRoot}/website/* ./
|
cp -rL --no-preserve=mode ${dream2nixRoot}/docs/* .
|
||||||
cp -r ${mdBookSource}/* src/
|
ln -s ${referenceDocs} ./src/reference
|
||||||
|
mkdocs build
|
||||||
# insert highlight.js
|
|
||||||
cp ${highlight-js} ./src/highlight.js
|
|
||||||
cp ${highlight-style} ./src/highlight.css
|
|
||||||
|
|
||||||
# merge original and generated SUMMARY.md
|
|
||||||
cp ${dream2nixRoot}/website/src/SUMMARY.md SUMMARY.md.orig
|
|
||||||
{
|
|
||||||
while read ln; do
|
|
||||||
case "$ln" in
|
|
||||||
"# Modules Reference")
|
|
||||||
echo "# Modules Reference"
|
|
||||||
cat ${mdBookSource}/SUMMARY.md
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "$ln"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
} < SUMMARY.md.orig > src/SUMMARY.md
|
|
||||||
|
|
||||||
# insert icon
|
|
||||||
mkdir -p ./theme
|
|
||||||
cp ${../../../modules/dream2nix/core/docs/theme/favicon.png} ./theme/favicon.png
|
|
||||||
|
|
||||||
${pkgs.mdbook}/bin/mdbook build --dest-dir out
|
|
||||||
mv out/html $out
|
|
||||||
'';
|
'';
|
||||||
in {
|
in {
|
||||||
|
packages.reference = referenceDocs;
|
||||||
packages.website = website;
|
packages.website = website;
|
||||||
packages.docs-generated-mdbook-src = mdBookSource;
|
devShells.mkdocs = let
|
||||||
|
package = self.packages.${system}.mkdocs;
|
||||||
|
pythonWithDeps = pkgs.python3.withPackages (
|
||||||
|
ps: [
|
||||||
|
package
|
||||||
|
ps.ipython
|
||||||
|
ps.black
|
||||||
|
ps.pytest
|
||||||
|
ps.pytest-cov
|
||||||
|
]
|
||||||
|
);
|
||||||
|
in
|
||||||
|
pkgs.mkShell {
|
||||||
|
packages = [
|
||||||
|
pythonWithDeps
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
packages.mkdocs = import ../../../docs/package.nix {
|
||||||
|
inherit lib;
|
||||||
|
inherit (pkgs) python3;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user