lol

nixos-render-docs: init from optionsToDocbook.py

this new package shall eventually contain the rendering code necessary
to produce the entirety of the nixos (not nixpkgs) manual, in all of its
various output formats.

pennae be6a2536 9ff98776

+128 -73
+2 -25
nixos/lib/make-options-doc/default.nix
··· 155 155 OTD_REVISION = revision; 156 156 157 157 nativeBuildInputs = [ 158 - (let 159 - # python3Minimal can't be overridden with packages on Darwin, due to a missing framework. 160 - # Instead of modifying stdenv, we take the easy way out, since most people on Darwin will 161 - # just be hacking on the Nixpkgs manual (which also uses make-options-doc). 162 - python = if pkgs.stdenv.isDarwin then pkgs.python3 else pkgs.python3Minimal; 163 - self = (python.override { 164 - inherit self; 165 - includeSiteCustomize = true; 166 - }); 167 - in self.withPackages (p: 168 - let 169 - # TODO add our own small test suite when rendering is split out into a new tool 170 - markdown-it-py = p.markdown-it-py.override { 171 - disableTests = true; 172 - }; 173 - mdit-py-plugins = p.mdit-py-plugins.override { 174 - inherit markdown-it-py; 175 - disableTests = true; 176 - }; 177 - in [ 178 - markdown-it-py 179 - mdit-py-plugins 180 - p.frozendict 181 - ])) 158 + pkgs.nixos-render-docs 182 159 ]; 183 160 } '' 184 - python ${./optionsToDocbook.py} \ 161 + nixos-render-docs \ 185 162 ${lib.optionalString markdownByDefault "--markdown-by-default"} \ 186 163 ${optionsJSON}/share/doc/nixos/options.json \ 187 164 > options.xml
+49 -48
nixos/lib/make-options-doc/optionsToDocbook.py pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/__init__.py
··· 344 344 print(f"""<member><filename{href}>{escape(loc['name'])}</filename></member>""") 345 345 print(f"""</simplelist>""") 346 346 347 - markdownByDefault = False 348 - optOffset = 0 349 - for arg in sys.argv[1:]: 350 - if arg == "--markdown-by-default": 351 - optOffset += 1 352 - markdownByDefault = True 347 + def main(): 348 + markdownByDefault = False 349 + optOffset = 0 350 + for arg in sys.argv[1:]: 351 + if arg == "--markdown-by-default": 352 + optOffset += 1 353 + markdownByDefault = True 353 354 354 - options = convertMD(json.load(open(sys.argv[1 + optOffset], 'r'))) 355 + options = convertMD(json.load(open(sys.argv[1 + optOffset], 'r'))) 355 356 356 - keys = list(options.keys()) 357 - keys.sort(key=lambda opt: [ (0 if p.startswith("enable") else 1 if p.startswith("package") else 2, p) 358 - for p in options[opt]['loc'] ]) 357 + keys = list(options.keys()) 358 + keys.sort(key=lambda opt: [ (0 if p.startswith("enable") else 1 if p.startswith("package") else 2, p) 359 + for p in options[opt]['loc'] ]) 359 360 360 - print(f"""<?xml version="1.0" encoding="UTF-8"?>""") 361 - if OTD_DOCUMENT_TYPE == 'appendix': 362 - print("""<appendix xmlns="http://docbook.org/ns/docbook" xml:id="appendix-configuration-options">""") 363 - print(""" <title>Configuration Options</title>""") 364 - print(f"""<variablelist xmlns:xlink="http://www.w3.org/1999/xlink" 365 - xmlns:nixos="tag:nixos.org" 366 - xmlns="http://docbook.org/ns/docbook" 367 - xml:id="{OTD_VARIABLE_LIST_ID}">""") 361 + print(f"""<?xml version="1.0" encoding="UTF-8"?>""") 362 + if OTD_DOCUMENT_TYPE == 'appendix': 363 + print("""<appendix xmlns="http://docbook.org/ns/docbook" xml:id="appendix-configuration-options">""") 364 + print(""" <title>Configuration Options</title>""") 365 + print(f"""<variablelist xmlns:xlink="http://www.w3.org/1999/xlink" 366 + xmlns:nixos="tag:nixos.org" 367 + xmlns="http://docbook.org/ns/docbook" 368 + xml:id="{OTD_VARIABLE_LIST_ID}">""") 368 369 369 - for name in keys: 370 - opt = options[name] 371 - id = OTD_OPTION_ID_PREFIX + name.translate(id_translate_table) 372 - print(f"""<varlistentry>""") 373 - # NOTE adding extra spaces here introduces spaces into xref link expansions 374 - print(f"""<term xlink:href={quoteattr("#" + id)} xml:id={quoteattr(id)}>""", end='') 375 - print(f"""<option>{escape(name)}</option>""", end='') 376 - print(f"""</term>""") 377 - print(f"""<listitem>""") 378 - print(opt['description']) 379 - if typ := opt.get('type'): 380 - print(typ) 381 - if default := opt.get('default'): 382 - print(default) 383 - if example := opt.get('example'): 384 - print(example) 385 - if related := opt.get('relatedPackages'): 386 - print(f"""<para>""") 387 - print(f""" <emphasis>Related packages:</emphasis>""") 388 - print(f"""</para>""") 389 - print(related) 390 - if decl := opt.get('declarations'): 391 - print_decl_def("Declared by", decl) 392 - if defs := opt.get('definitions'): 393 - print_decl_def("Defined by", defs) 394 - print(f"""</listitem>""") 395 - print(f"""</varlistentry>""") 370 + for name in keys: 371 + opt = options[name] 372 + id = OTD_OPTION_ID_PREFIX + name.translate(id_translate_table) 373 + print(f"""<varlistentry>""") 374 + # NOTE adding extra spaces here introduces spaces into xref link expansions 375 + print(f"""<term xlink:href={quoteattr("#" + id)} xml:id={quoteattr(id)}>""", end='') 376 + print(f"""<option>{escape(name)}</option>""", end='') 377 + print(f"""</term>""") 378 + print(f"""<listitem>""") 379 + print(opt['description']) 380 + if typ := opt.get('type'): 381 + print(typ) 382 + if default := opt.get('default'): 383 + print(default) 384 + if example := opt.get('example'): 385 + print(example) 386 + if related := opt.get('relatedPackages'): 387 + print(f"""<para>""") 388 + print(f""" <emphasis>Related packages:</emphasis>""") 389 + print(f"""</para>""") 390 + print(related) 391 + if decl := opt.get('declarations'): 392 + print_decl_def("Declared by", decl) 393 + if defs := opt.get('definitions'): 394 + print_decl_def("Defined by", defs) 395 + print(f"""</listitem>""") 396 + print(f"""</varlistentry>""") 396 397 397 - print("""</variablelist>""") 398 - if OTD_DOCUMENT_TYPE == 'appendix': 399 - print("""</appendix>""") 398 + print("""</variablelist>""") 399 + if OTD_DOCUMENT_TYPE == 'appendix': 400 + print("""</appendix>""")
+60
pkgs/tools/nix/nixos-render-docs/default.nix
··· 1 + { lib 2 + , stdenv 3 + , python3 4 + , python3Minimal 5 + }: 6 + 7 + let 8 + # python3Minimal can't be overridden with packages on Darwin, due to a missing framework. 9 + # Instead of modifying stdenv, we take the easy way out, since most people on Darwin will 10 + # just be hacking on the Nixpkgs manual (which also uses make-options-doc). 11 + python = ((if stdenv.isDarwin then python3 else python3Minimal).override { 12 + self = python; 13 + includeSiteCustomize = true; 14 + }); 15 + 16 + # TODO add our own small test suite, maybe add tests for these deps to channels? 17 + markdown-it-py-no-tests = python.pkgs.markdown-it-py.override { 18 + disableTests = true; 19 + }; 20 + mdit-py-plugins-no-tests = python.pkgs.mdit-py-plugins.override { 21 + markdown-it-py = markdown-it-py-no-tests; 22 + disableTests = true; 23 + }; 24 + in 25 + 26 + python.pkgs.buildPythonApplication { 27 + pname = "nixos-render-docs"; 28 + version = "0.0"; 29 + format = "pyproject"; 30 + 31 + src = lib.cleanSourceWith { 32 + filter = name: type: 33 + lib.cleanSourceFilter name type 34 + && ! (type == "directory" 35 + && builtins.elem 36 + (baseNameOf name) 37 + [ 38 + ".pytest_cache" 39 + ".mypy_cache" 40 + "__pycache__" 41 + ]); 42 + src = ./src; 43 + }; 44 + 45 + nativeBuildInputs = [ 46 + python.pkgs.setuptools 47 + ]; 48 + 49 + propagatedBuildInputs = [ 50 + markdown-it-py-no-tests 51 + mdit-py-plugins-no-tests 52 + python.pkgs.frozendict 53 + ]; 54 + 55 + meta = with lib; { 56 + description = "Renderer for NixOS manual and option docs"; 57 + license = licenses.mit; 58 + maintainers = [ ]; 59 + }; 60 + }
+15
pkgs/tools/nix/nixos-render-docs/src/pyproject.toml
··· 1 + [project] 2 + name = "nixos-render-docs" 3 + version = "0.0" 4 + description = "Renderer for NixOS manual and option docs" 5 + classifiers = [ 6 + "Programming Language :: Python :: 3", 7 + "License :: OSI Approved :: MIT License", 8 + "Operating System :: OS Independent", 9 + ] 10 + 11 + [project.scripts] 12 + nixos-render-docs = "nixos_render_docs:main" 13 + 14 + [build-system] 15 + requires = ["setuptools"]
+2
pkgs/top-level/all-packages.nix
··· 37557 37557 37558 37558 nixos-install-tools = callPackage ../tools/nix/nixos-install-tools { }; 37559 37559 37560 + nixos-render-docs = callPackage ../tools/nix/nixos-render-docs { }; 37561 + 37560 37562 nixdoc = callPackage ../tools/nix/nixdoc {}; 37561 37563 37562 37564 dnadd = callPackage ../tools/nix/dnadd { };