Initial commit
This commit is contained in:
commit
53433866bb
74
flake.lock
generated
Normal file
74
flake.lock
generated
Normal file
@ -0,0 +1,74 @@
|
||||
{
|
||||
"nodes": {
|
||||
"example-nix-minecraft": {
|
||||
"inputs": {
|
||||
"mcversions": "mcversions",
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1655551827,
|
||||
"narHash": "sha256-sUdTici3FjWTMvfKtW+h9R6LFvdWrlWub/SI5pAdkAI=",
|
||||
"owner": "12Boti",
|
||||
"repo": "nix-minecraft",
|
||||
"rev": "a2c657b54d86bc1c912ce99597253cfdb4042010",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "12Boti",
|
||||
"repo": "nix-minecraft",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"mcversions": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1648176147,
|
||||
"narHash": "sha256-9xqPSKlSDZZx3z683ZoMhR6jyRd1eS6L+mIdjnqu6Cw=",
|
||||
"owner": "yushijinhun",
|
||||
"repo": "minecraft-version-json-history",
|
||||
"rev": "a8487697562bf897d0688f4edb9f9fc4b2b4bbfb",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "yushijinhun",
|
||||
"repo": "minecraft-version-json-history",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1648097358,
|
||||
"narHash": "sha256-GMoTKP/po2Nbkh1tvPvP8Ww6NyFW8FFst1Z3nfzffZc=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "4d60081494259c0785f7e228518fee74e0792c1b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1687829761,
|
||||
"narHash": "sha256-QRe1Y8SS3M4GeC58F/6ajz6V0ZLUVWX3ZAMgov2N3/g=",
|
||||
"path": "/nix/store/mz6lqpbsp4h36kgahvwfrgdjzz042hpn-source",
|
||||
"rev": "9790f3242da2152d5aa1976e3e4b8b414f4dd206",
|
||||
"type": "path"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"example-nix-minecraft": "example-nix-minecraft",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
35
flake.nix
Normal file
35
flake.nix
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
description = "Generate documentation for NixOS modules.";
|
||||
|
||||
inputs.example-nix-minecraft.url = "github:12Boti/nix-minecraft";
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
... } @ inputs:
|
||||
let
|
||||
forAllSystems = f: nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system: f {
|
||||
inherit system;
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
lib = nixpkgs.legacyPackages.${system}.lib;
|
||||
doc = self.lib.${system};
|
||||
});
|
||||
in {
|
||||
inherit inputs;
|
||||
|
||||
lib = forAllSystems ({ pkgs, ...}: pkgs.callPackage ./lib.nix { });
|
||||
|
||||
packages = forAllSystems ({ pkgs, lib, doc, ...}: let
|
||||
mkJSON = name: modules: lib.pipe modules [
|
||||
doc.modules2options
|
||||
builtins.toJSON
|
||||
(pkgs.writeText "${name}.json")
|
||||
];
|
||||
in {
|
||||
example-nix-minecraft-json = mkJSON "nix-minecraft" inputs.example-nix-minecraft.lib.baseModules;
|
||||
example-nix-minecraft-html = doc.mkHTML "nix-minecraft" inputs.example-nix-minecraft inputs.example-nix-minecraft.lib.baseModules;
|
||||
#example-nix-minecraft = ;
|
||||
});
|
||||
|
||||
};
|
||||
}
|
13
j2_environ.py
Normal file
13
j2_environ.py
Normal file
@ -0,0 +1,13 @@
|
||||
# https://github.com/kolypto/j2cli#customization
|
||||
|
||||
# http://jinja.pocoo.org/docs/2.10/api/#jinja2.Environment
|
||||
def j2_environment_params(): return dict(
|
||||
autoescape = True,
|
||||
trim_blocks = True,
|
||||
lstrip_blocks = True,
|
||||
keep_trailing_newline = True,
|
||||
extensions = (
|
||||
"jinja2.ext.do",
|
||||
"jinja2.ext.loopcontrols"
|
||||
),
|
||||
)
|
33
lib.nix
Normal file
33
lib.nix
Normal file
@ -0,0 +1,33 @@
|
||||
{ lib, pkgs }:
|
||||
|
||||
rec {
|
||||
|
||||
modules2options = modules': let
|
||||
eval = lib.evalModules {
|
||||
modules = [{ _module.check = false; }] ++ modules';
|
||||
};
|
||||
options = lib.optionAttrSetToDocList eval.options;
|
||||
in builtins.filter (x: x.visible && !x.internal) options;
|
||||
|
||||
mkHTML = name: source: modules: let
|
||||
options = modules2options modules;
|
||||
declarations = lib.pipe options [
|
||||
(builtins.map (option: option.declarations))
|
||||
lib.flatten
|
||||
];
|
||||
in pkgs.runCommand "${name}-html" {
|
||||
nativeBuildInputs = with pkgs; [ aha bat j2cli ];
|
||||
passAsFile = [ "jsonData" ];
|
||||
jsonData = builtins.toJSON { inherit name options source; };
|
||||
} (''
|
||||
mkdir $out
|
||||
j2 --customize ${./j2_environ.py} -f json ${./template.html.j2} $jsonDataPath > $out/index.html
|
||||
# ${source} # just here to make declarations available
|
||||
'' + lib.concatStrings (lib.forEach declarations (declaration: with lib; ''
|
||||
BASE="$(basename ${lib.escapeShellArg declaration})"
|
||||
DIR="$(dirname ${lib.escapeShellArg declaration} | cut -d/ -f5-)"
|
||||
mkdir -p $out/sources/"$DIR"
|
||||
bat --color always --style plain ${escapeShellArg declaration} | aha --black --title "$BASE" > $out/sources/"$DIR"/"$BASE".html
|
||||
'')));
|
||||
|
||||
}
|
52
template.html.j2
Normal file
52
template.html.j2
Normal file
@ -0,0 +1,52 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset='utf-8' />
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1' />
|
||||
<title>{{ name }}</title>
|
||||
|
||||
<style media="screen">
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
{% macro show_value(val) %}
|
||||
{% if val._type == "literalExpression" %}
|
||||
<pre>{{ val.text }}</pre>
|
||||
{% else %}
|
||||
<pre>{{ val.text }}</pre>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% for option in options %}
|
||||
<details id="{{ option.name }}">
|
||||
<summary>
|
||||
<code>{{ option.name }}</code>
|
||||
</summary>
|
||||
|
||||
<div>Desc:</div>
|
||||
<div>{{ option.description | safe }}</div>
|
||||
|
||||
<div>Type:</div>
|
||||
<div>{{ option.type }}</div>
|
||||
|
||||
{% if option.default is defined %}
|
||||
<div>Type:</div>
|
||||
<div>{{ show_value(option.default) }}</div>
|
||||
{% endif %}
|
||||
|
||||
{% if option.example is defined %}
|
||||
<div>example:</div>
|
||||
<div>{{ show_value(option.example) }}</div>
|
||||
{% endif %}
|
||||
|
||||
{% for declaration in option.declarations %}
|
||||
<div>Source:</div>
|
||||
<div>
|
||||
<a href="{{ declaration.replace(source, "sources") }}.html">
|
||||
<code>{{ declaration.replace(source, "<%s>" % name) }}</code>
|
||||
</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
</details>
|
||||
{% endfor %}
|
Loading…
Reference in New Issue
Block a user