-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkdocs.nix
124 lines (109 loc) · 3.05 KB
/
mkdocs.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
112
113
114
115
116
117
118
119
120
121
122
123
124
{
perSystem = {
lib,
pkgs,
...
}: let
inherit (pkgs) stdenv mdbook;
# Options needed by other modules for defaults.
# All options should be marked as hidden from docs as they are properly documented seperately
baseOptionsModule = {
options.services.steam-servers = {
datadir = lib.mkOption {
type = lib.types.path;
default = "/var/lib/steam-servers";
visible = false;
};
};
};
eachOptions = with lib;
filterAttrs
(_: hasSuffix "options.nix")
(flattenTree {tree = rakeLeaves ./modules;});
book-summary = with lib; let
notTopLevel = filterAttrs (n: _: n != "options") eachOptions;
modules =
mapAttrsToList
(n: _: {name = "${head (splitString "." n)}";})
notTopLevel;
in
templateFile pkgs "SUMMARY.md" ./docs/SUMMARY.md.mustache {
inherit modules;
};
options-doc = let
eachOptionsDoc = with lib;
mapAttrs' (
name: value: let
isTopLevel = name == "options";
trimmedName =
if isTopLevel
then "toplevel"
else (head (splitString "." name));
modules = (optionals (!isTopLevel) [baseOptionsModule]) ++ [value];
in
nameValuePair
trimmedName
# generate options doc
(pkgs.nixosOptionsDoc {options = evalModules {inherit modules;};})
)
eachOptions;
statements = with lib;
concatStringsSep "\n"
(mapAttrsToList (n: v: ''
path=$out/${n}.md
cat ${v.optionsCommonMark} >> $path
'')
eachOptionsDoc);
in
pkgs.runCommand "nixos-options" {} ''
mkdir $out
${statements}
'';
docsPath = "./docs/reference/module-options";
in {
packages.docs = stdenv.mkDerivation {
src = ./.;
name = "nix-steam-servers-docs";
buildInput = [options-doc];
nativeBuildInputs = [mdbook];
# Skip phases that don't matter
dontConfigure = true;
dontFixup = true;
buildPhase = ''
ln -s ${book-summary} ./docs/SUMMARY.md
ln -s ${options-doc} ${docsPath}
mdbook build
'';
installPhase = ''
mv book $out
'';
passthru = {
inherit options-doc;
serve = pkgs.writeShellScriptBin "server" ''
set -euo pipefail
# link in options reference
rm -f ${docsPath} ./docs/SUMMARY.md
ln -s ${book-summary} ./docs/SUMMARY.md
ln -s ${options-doc} ${docsPath} # TODO auto-update this somehow...
${mdbook}/bin/mdbook serve "$@"
'';
};
};
devshells.default.commands = let
category = "Docs";
in [
{
inherit category;
name = "docs-serve";
help = "Serve docs";
command = "nix run .#docs.serve -- \"$@\"";
}
{
inherit category;
name = "docs-build";
help = "Build docs";
command = "nix build .#docs";
}
];
};
}