Skip to content

Commit 4c638c2

Browse files
MattSturgeonfricklerhandwerk
authored andcommitted
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`.
1 parent 96f0417 commit 4c638c2

File tree

6 files changed

+56
-11
lines changed

6 files changed

+56
-11
lines changed

doc/doc-support/package.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ stdenvNoCC.mkDerivation (
4949
postPatch = ''
5050
ln -s ${optionsJSON}/share/doc/nixos/options.json ./config-options.json
5151
ln -s ${treefmt.functionsDoc.markdown} ./packages/treefmt-functions.section.md
52+
ln -s ${treefmt.optionsDoc.optionsJSON}/share/doc/nixos/options.json ./treefmt-options.json
5253
'';
5354

5455
buildPhase = ''

doc/packages/treefmt.section.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@
33
[treefmt](https://github.com/numtide/treefmt) streamlines the process of applying formatters to your project, making it a breeze with just one command line.
44

55
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).
77

88
Alternatively, treefmt can be configured using [treefmt-nix](https://github.com/numtide/treefmt-nix).
99

1010
```{=include=} sections auto-id-prefix=auto-generated-treefmt-functions
1111
treefmt-functions.section.md
1212
```
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+

doc/redirects.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@
420420
"sec-tools-of-stdenv": [
421421
"index.html#sec-tools-of-stdenv"
422422
],
423+
"sec-treefmt-options-reference": [
424+
"index.html#sec-treefmt-options-reference"
425+
],
423426
"ssec-cosmic-common-issues": [
424427
"index.html#ssec-cosmic-common-issues"
425428
],

pkgs/by-name/tr/treefmt/lib.nix

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
1616
# Inputs
1717
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
2321
*/
2422
evalConfig =
2523
module:
@@ -51,11 +49,9 @@
5149
5250
# Inputs
5351
54-
`module`
55-
: A treefmt module, configuring options that include:
56-
- `name`: `String` (default `"treefmt-with-config"`)
57-
- `settings`: `Module` (default `{ }`)
58-
- `runtimeInputs`: `[Derivation]` (default `[ ]`)
52+
: A treefmt module. See [options reference].
53+
54+
[options reference]: https://nixos.org/manual/nixpkgs/unstable#sec-treefmt-options-reference
5955
*/
6056
withConfig =
6157
module:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}

pkgs/by-name/tr/treefmt/package.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ buildGoModule rec {
3939

4040
# Documentation for functions defined in `./lib.nix`
4141
functionsDoc = callPackages ./functions-doc.nix { };
42+
43+
# Documentation for options declared in `treefmt.evalConfig` configurations
44+
optionsDoc = callPackages ./options-doc.nix { };
4245
};
4346

4447
meta = {

0 commit comments

Comments
 (0)