-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathflake-docs-render.nix
111 lines (102 loc) · 3.42 KB
/
flake-docs-render.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{
perSystem = { config, pkgs, lib, ... }:
let
inherit (lib)
concatMap
hasPrefix
removePrefix
;
filterTransformOptions = { sourceName, sourcePath, baseUrl }:
let sourcePathStr = toString sourcePath;
in
opt:
let
declarations = concatMap
(decl:
if hasPrefix sourcePathStr (toString decl)
then
let subpath = removePrefix sourcePathStr (toString decl);
in [{ url = baseUrl + subpath; name = sourceName + subpath; }]
else [ ]
)
opt.declarations;
in
if declarations == [ ]
then opt // { visible = false; }
else opt // { inherit declarations; };
renderModule = { sourceName, sourcePath, modules }:
# TODO: use the render pipeline in flake-parts,
# which has support for things like {options}`foo`.
let
eval = lib.evalModules {
modules = [
{
options._module.args = lib.mkOption {
visible = false;
# type = lib.types.submodule;
};
}
./effects/effect/effect-module.nix
] ++ modules;
};
baseUrl =
"https://github.com/hercules-ci/hercules-ci-effects/blob/master"
+ lib.strings.removePrefix (toString ./.) (toString sourcePath);
in
(pkgs.nixosOptionsDoc
{
options = eval.options;
transformOptions = filterTransformOptions {
inherit sourceName baseUrl sourcePath;
};
documentType = "none";
warningsAreErrors = true;
}).optionsAsciiDoc;
in
{
packages.generated-option-doc-modularEffect =
renderModule {
sourceName = "effect";
sourcePath = ./effects/effect;
modules = [ ];
};
packages.generated-option-doc-gitWriteBranch =
renderModule {
sourceName = "write-branch";
sourcePath = ./effects/write-branch;
modules = [ ./effects/write-branch/effect-module.nix ];
};
packages.generated-option-doc-git-auth =
renderModule {
sourceName = "git-auth";
sourcePath = ./effects/modules/git-auth.nix;
modules = [ ./effects/modules/git-auth.nix ];
};
packages.generated-option-doc-git-update =
renderModule {
sourceName = "git-auth";
sourcePath = ./effects/modules/git-update.nix;
modules = [ ./effects/modules/git-update.nix ];
};
packages.generated-antora-files =
pkgs.runCommand "generated-antora-files"
{
# nativeBuildInputs = [ pkgs.pandoc ];
modularEffect = config.packages.generated-option-doc-modularEffect;
gitWriteBranch = config.packages.generated-option-doc-gitWriteBranch;
git_auth = config.packages.generated-option-doc-git-auth;
git_update = config.packages.generated-option-doc-git-update;
}
''
convert() {
# sed -e 's/^#/##/' $1 >$2
cat $1 >$2
}
mkdir -p $out/modules/ROOT/partials/options
convert $modularEffect $out/modules/ROOT/partials/options.adoc
convert $gitWriteBranch $out/modules/ROOT/partials/options/gitWriteBranch.adoc
convert $git_auth $out/modules/ROOT/partials/options/git-auth.adoc
convert $git_update $out/modules/ROOT/partials/options/git-update.adoc
'';
};
}