{ 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 ''))); }