nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix

doc/packages/treefmt: add option reference docs

Add a `treefmt.optionsDoc` passthru, which is included on the treefmt
section of the nixpkgs manual.

This generates reference docs for options declared in
`treefmt.evalConfig`.

authored by

Matt Sturgeon and committed by
Valentin Gagarin
4c638c27 96f04172

+56 -11
+1
doc/doc-support/package.nix
··· 49 49 postPatch = '' 50 50 ln -s ${optionsJSON}/share/doc/nixos/options.json ./config-options.json 51 51 ln -s ${treefmt.functionsDoc.markdown} ./packages/treefmt-functions.section.md 52 + ln -s ${treefmt.optionsDoc.optionsJSON}/share/doc/nixos/options.json ./treefmt-options.json 52 53 ''; 53 54 54 55 buildPhase = ''
+12 -1
doc/packages/treefmt.section.md
··· 3 3 [treefmt](https://github.com/numtide/treefmt) streamlines the process of applying formatters to your project, making it a breeze with just one command line. 4 4 5 5 The [`treefmt` package](https://search.nixos.org/packages?channel=unstable&show=treefmt) 6 - provides functions for configuring treefmt using the module system, which are [documented below](#sec-functions-library-treefmt). 6 + provides functions for configuring treefmt using the module system, which are [documented below](#sec-functions-library-treefmt), along with [their options](#sec-treefmt-options-reference). 7 7 8 8 Alternatively, treefmt can be configured using [treefmt-nix](https://github.com/numtide/treefmt-nix). 9 9 10 10 ```{=include=} sections auto-id-prefix=auto-generated-treefmt-functions 11 11 treefmt-functions.section.md 12 12 ``` 13 + 14 + ## Options Reference {#sec-treefmt-options-reference} 15 + 16 + The following attributes can be passed to [`withConfig`](#pkgs.treefmt.withConfig) or [`evalConfig`](#pkgs.treefmt.evalConfig): 17 + 18 + ```{=include=} options 19 + id-prefix: opt-treefmt- 20 + list-id: configuration-variable-list 21 + source: ../treefmt-options.json 22 + ``` 23 +
+3
doc/redirects.json
··· 420 420 "sec-tools-of-stdenv": [ 421 421 "index.html#sec-tools-of-stdenv" 422 422 ], 423 + "sec-treefmt-options-reference": [ 424 + "index.html#sec-treefmt-options-reference" 425 + ], 423 426 "ssec-cosmic-common-issues": [ 424 427 "index.html#ssec-cosmic-common-issues" 425 428 ],
+6 -10
pkgs/by-name/tr/treefmt/lib.nix
··· 15 15 16 16 # Inputs 17 17 18 - `module` 19 - : A treefmt module, configuring options that include: 20 - - `name`: `String` (default `"treefmt-with-config"`) 21 - - `settings`: `Module` (default `{ }`) 22 - - `runtimeInputs`: `[Derivation]` (default `[ ]`) 18 + : A treefmt module. See [options reference]. 19 + 20 + [options reference]: https://nixos.org/manual/nixpkgs/unstable#sec-treefmt-options-reference 23 21 */ 24 22 evalConfig = 25 23 module: ··· 49 51 50 52 # Inputs 51 53 52 - `module` 53 - : A treefmt module, configuring options that include: 54 - - `name`: `String` (default `"treefmt-with-config"`) 55 - - `settings`: `Module` (default `{ }`) 56 - - `runtimeInputs`: `[Derivation]` (default `[ ]`) 54 + : A treefmt module. See [options reference]. 55 + 56 + [options reference]: https://nixos.org/manual/nixpkgs/unstable#sec-treefmt-options-reference 57 57 */ 58 58 withConfig = 59 59 module:
+31
pkgs/by-name/tr/treefmt/options-doc.nix
··· 1 + # To build this derivation, run `nix-build -A treefmt.optionsDoc` 2 + { 3 + lib, 4 + treefmt, 5 + nixosOptionsDoc, 6 + }: 7 + 8 + let 9 + configuration = treefmt.evalConfig [ ]; 10 + 11 + root = toString configuration._module.specialArgs.modulesPath; 12 + revision = lib.trivial.revisionWithDefault "master"; 13 + removeRoot = file: lib.removePrefix "/" (lib.removePrefix root file); 14 + 15 + transformDeclaration = 16 + file: 17 + let 18 + fileStr = toString file; 19 + subpath = "pkgs/by-name/tr/treefmt/modules/" + removeRoot fileStr; 20 + in 21 + assert lib.hasPrefix root fileStr; 22 + { 23 + url = "https://github.com/NixOS/nixpkgs/blob/${revision}/${subpath}"; 24 + name = subpath; 25 + }; 26 + in 27 + nixosOptionsDoc { 28 + documentType = "none"; 29 + options = builtins.removeAttrs configuration.options [ "_module" ]; 30 + transformOptions = opt: opt // { declarations = map transformDeclaration opt.declarations; }; 31 + }
+3
pkgs/by-name/tr/treefmt/package.nix
··· 39 39 40 40 # Documentation for functions defined in `./lib.nix` 41 41 functionsDoc = callPackages ./functions-doc.nix { }; 42 + 43 + # Documentation for options declared in `treefmt.evalConfig` configurations 44 + optionsDoc = callPackages ./options-doc.nix { }; 42 45 }; 43 46 44 47 meta = {