-
Notifications
You must be signed in to change notification settings - Fork 0
/
options-document.nix
94 lines (92 loc) · 2.91 KB
/
options-document.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
topLevel @ {
inputs,
lib,
flake-parts-lib,
...
}: {
imports = [
./shell
inputs.flake-parts.flakeModules.flakeModules
];
flake.flakeModules.optionsDocument = flakeModule: {
imports = [
topLevel.config.flake.flakeModules.shell
];
options.perSystem = flake-parts-lib.mkPerSystemOption (
perSystem @ {
pkgs,
system,
inputs',
self',
...
}: {
snow-blower = {
scripts = {
"generate-docs" = {
just.enable = true;
description = "Generate option docs.";
exec = ''
set -e
nix build .#options-document
nix build .#copy-options-document-to-current-directory
./result/bin/nixago_shell_hook
'';
};
};
};
packages = rec {
copy-options-document-to-current-directory =
(inputs.nixago.lib.${system}.make {
output = options-document.name;
data = options-document;
engine = {data, ...}: data;
hook.mode = "copy";
})
.install;
options-document =
(pkgs.nixosOptionsDoc {
options =
(
inputs.flake-parts.lib.evalFlakeModule
{inherit inputs;}
{
imports = [topLevel.config.flake.flakeModules.default];
options.perSystem = flake-parts-lib.mkPerSystemOption {
config._module.args = {
# Generate document for Linux so that the document includes CUDA related options, which are not available on Darwin.
system = lib.mkDefault "x86_64-linux";
pkgs = lib.mkDefault pkgs;
inputs' = lib.mkDefault inputs';
self' = lib.mkDefault self';
};
};
}
)
.options;
documentType = "none";
markdownByDefault = true;
warningsAreErrors = false;
transformOptions = option:
option
// rec {
declarations =
lib.concatMap
(declaration:
if lib.hasPrefix "${flakeModule.self}/modules/" declaration
then [
rec {
name = lib.removePrefix "${flakeModule.self}/modules/" declaration;
url = "modules/${builtins.head (builtins.split "," name)}";
}
]
else [])
option.declarations;
visible = declarations != [];
};
})
.optionsCommonMark;
};
}
);
};
}