-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdocs.nix
92 lines (82 loc) · 2.73 KB
/
docs.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
{
pkgs,
...
}:
pkgs.mkShellNoCC {
packages =
let
inherit (pkgs) lib;
# Capture root so we can identify our store paths below
root = toString ./.;
snakeCase = with lib; replaceStrings upperChars (map (s: "_" + s) lowerChars);
# Eval Facter module
eval = lib.evalModules {
modules = [
# Load the root module
./modules/nixos/facter.nix
{
# Disable checks so it doesn't complain about NixOS related options which aren't available
config._module.check = false;
# Use the basic vm's report
config.facter.reportPath = ./hosts/basic/report.json;
}
];
};
# Convert `/nix/store/...` store paths in the option declarations into a repository link.
# NOTE: we point at the main branch, but for versioned docs this will be incorrect.
# It's still a good starting point though.
transformDeclaration =
decl:
let
declStr = toString decl;
subpath = lib.removePrefix "/" (lib.removePrefix root declStr);
in
assert lib.hasPrefix root declStr;
{
url = "https://github.com/numtide/nixos-facter-modules/blob/main/${subpath}";
name = subpath;
};
# Convert options into options doc, transforming declaration paths to point to the github repository.
nixosOptionsDoc =
_name: options:
pkgs.nixosOptionsDoc {
inherit options;
transformOptions =
opt:
opt
// {
declarations = map transformDeclaration opt.declarations;
};
};
# Take an options attr set and produce a markdown file.
mkMarkdown =
name: options:
let
optionsDoc = nixosOptionsDoc name options;
in
pkgs.runCommand "${name}-markdown" { } ''
mkdir $out
cat ${optionsDoc.optionsCommonMark} > $out/${snakeCase name}.md
'';
facterMarkdown = mkMarkdown "facter" eval.options.facter.detected;
otherMarkdown = lib.mapAttrsToList mkMarkdown (
lib.filterAttrs (n: _v: n != "detected") eval.options.facter
);
optionsMarkdown = pkgs.symlinkJoin {
name = "facter-module-markdown";
paths = [ facterMarkdown ] ++ otherMarkdown;
};
in
[
(pkgs.writeScriptBin "mkdocs" ''
# rsync in NixOS modules doc to avoid issues with symlinks being owned by root
rsync -aL --chmod=u+rw --delete-before ${optionsMarkdown}/ ./docs/content/reference/nixos_modules
# execute the underlying command
${pkgs.mkdocs}/bin/mkdocs "$@"
'')
]
++ (with pkgs.python3Packages; [
mike
mkdocs-material
]);
}