Skip to content

Commit de1e3a0

Browse files
committed
docs: document home-manager module
1 parent b9664be commit de1e3a0

File tree

2 files changed

+86
-40
lines changed

2 files changed

+86
-40
lines changed

nix/devshells.nix

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,33 @@
3232
{
3333
name = "mkoptdocs";
3434
category = "maintenance";
35-
help = "Generate NixOS module options documentation";
35+
help = "Generate NixOS and Home Manager module options documentation";
3636
command = ''
37-
docs="$(${pkgs.nix}/bin/nix "$@" build --print-out-paths --no-link "''${PRJ_ROOT}#docs")" || exit
37+
install_docs() {
38+
local pkgname="$1"
39+
shift
3840
39-
seen=0
40-
while read -r path; do
41-
seen="$((seen + 1))"
42-
if [ "$seen" -gt 1 ]; then
43-
printf 1>&2 -- 'error: more than one output path...\n'
44-
exit 1
45-
fi
46-
install -Dm0644 "$path" "''${PRJ_ROOT}/doc/nixos-modules.md"
47-
done <<DOCS
41+
local output="$1"
42+
shift
43+
44+
docs="$(${pkgs.nix}/bin/nix "$@" build --print-out-paths --no-link "''${PRJ_ROOT}#''${pkgname}")" || exit
45+
46+
local path
47+
local seen=0
48+
while read -r path; do
49+
seen="$((seen + 1))"
50+
if [ "$seen" -gt 1 ]; then
51+
printf 1>&2 -- 'error: more than one output path...\n'
52+
exit 1
53+
fi
54+
install -Dm0644 "$path" "$output"
55+
done <<DOCS
4856
$docs
4957
DOCS
58+
}
59+
60+
install_docs nixosDocs "''${PRJ_ROOT}/doc/nixos-modules.md"
61+
install_docs homeManagerDocs "''${PRJ_ROOT}/doc/home-modules.md"
5062
'';
5163
}
5264
]

nix/packages.nix

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,41 @@
99
pkgs,
1010
system,
1111
...
12-
}: {
12+
}: let
13+
mkDocs = {
14+
loc,
15+
options,
16+
}:
17+
pkgs.nixosOptionsDoc {
18+
inherit options;
19+
20+
# Default is currently "appendix".
21+
documentType = "none";
22+
23+
# We only want Markdown
24+
allowDocBook = false;
25+
markdownByDefault = true;
26+
27+
# Only include our own options.
28+
transformOptions = let
29+
ourPrefix = "${toString self}/";
30+
link = {
31+
url = "/${loc}";
32+
name = loc;
33+
};
34+
in
35+
opt:
36+
opt
37+
// {
38+
visible = opt.visible && (lib.any (lib.hasPrefix ourPrefix) opt.declarations);
39+
declarations = map (decl:
40+
if lib.hasPrefix ourPrefix decl
41+
then link
42+
else decl)
43+
opt.declarations;
44+
};
45+
};
46+
in {
1347
packages = {
1448
default = config.packages.anything-sync-daemon;
1549

@@ -82,7 +116,7 @@
82116
};
83117
};
84118

85-
docs = let
119+
nixosDocs = let
86120
# Use a full NixOS system rather than (say) the result of
87121
# `lib.evalModules`. This is because our NixOS module refers to
88122
# `security.sudo`, which may itself refer to any number of other
@@ -96,38 +130,38 @@
96130
];
97131
};
98132

99-
allDocs = pkgs.nixosOptionsDoc {
133+
allDocs = mkDocs {
100134
inherit (eval) options;
135+
loc = "nix/nixos-modules.nix";
136+
};
137+
in
138+
allDocs.optionsCommonMark;
101139

102-
# Default is currently "appendix".
103-
documentType = "none";
104-
105-
# We only want Markdown
106-
allowDocBook = false;
107-
markdownByDefault = true;
140+
homeManagerDocs = let
141+
# Use a full Home Manager configuration for reasons similar to those
142+
# given above with respect to the NixOS module documentation.
143+
eval = inputs.home-manager.lib.homeManagerConfiguration {
144+
inherit pkgs;
145+
modules = [
146+
({config, ...}: {
147+
home.stateVersion = config.home.version.release;
148+
home.username = "ignored";
149+
home.homeDirectory = "/home/ignored";
150+
})
151+
self.homeModules.anything-sync-daemon
152+
];
153+
};
108154

109-
# Only include our own options.
110-
transformOptions = let
111-
ourPrefix = "${toString self}/";
112-
nixosModules = "nix/nixos-modules.nix";
113-
link = {
114-
url = "/${nixosModules}";
115-
name = nixosModules;
116-
};
117-
in
118-
opt:
119-
opt
120-
// {
121-
visible = opt.visible && (lib.any (lib.hasPrefix ourPrefix) opt.declarations);
122-
declarations = map (decl:
123-
if lib.hasPrefix ourPrefix decl
124-
then link
125-
else decl)
126-
opt.declarations;
127-
};
155+
allDocs = mkDocs {
156+
inherit (eval) options;
157+
loc = "nix/home-modules.nix";
128158
};
129159
in
130-
allDocs.optionsCommonMark;
160+
allDocs.optionsCommonMark // {
161+
passthru = (allDocs.OptionsCommonMark.passthru or {}) // {
162+
inherit eval;
163+
};
164+
};
131165
};
132166
};
133167
}

0 commit comments

Comments
 (0)