blob: 2f3bb9a4d76e7672dc6e450b473b36f66f5e3c8a (
plain)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
{ config, lib, pkgs, baseModules, modules, ... }:
with lib;
let
cfg = config.documentation;
# To reference the regular configuration from inside the docs evaluation further down.
# While not strictly necessary, this extra binding avoids accidental name capture in
# the future.
regularConfig = config;
argsModule = {
config._module.args = regularConfig._module.args // {
modules = [ ];
};
};
/* For the purpose of generating docs, evaluate options with each derivation
in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}".
It isn't perfect, but it seems to cover a vast majority of use cases.
Caveat: even if the package is reached by a different means,
the path above will be shown and not e.g. `${config.services.foo.package}`. */
realManual = import ../../doc/manual {
inherit pkgs config;
version = config.system.darwinVersion;
revision = config.system.darwinRevision;
inherit (config.system) nixpkgsRevision;
options =
let
scrubbedEval = evalModules {
modules = baseModules ++ [ argsModule ];
specialArgs = { pkgs = scrubDerivations "pkgs" pkgs; };
};
scrubDerivations = namePrefix: pkgSet: mapAttrs
(name: value:
let wholeName = "${namePrefix}.${name}"; in
if isAttrs value then
scrubDerivations wholeName value
// (optionalAttrs (isDerivation value) { outPath = "\${${wholeName}}"; })
else value
)
pkgSet;
in scrubbedEval.options;
};
# TODO: Remove this when dropping 22.11 support.
manual = realManual //
lib.optionalAttrs (!pkgs.buildPackages ? nixos-render-docs) rec {
optionsJSON = pkgs.writeTextFile {
name = "options.json-stub";
destination = "/share/doc/darwin/options.json";
text = "{}";
};
manpages = pkgs.writeTextFile {
name = "darwin-manpages-stub";
destination = "/share/man/man5/configuration.nix.5";
text = ''
.TH "CONFIGURATION\&.NIX" "5" "01/01/1980" "Darwin" "Darwin Reference Pages"
.SH "NAME"
\fIconfiguration\&.nix\fP \- Darwin system configuration specification
.SH "DESCRIPTION"
.PP
The nix\-darwin documentation now requires nixpkgs 23.05 to build.
'';
};
manualHTML = pkgs.writeTextFile {
name = "darwin-manual-html-stub";
destination = "/share/doc/darwin/index.html";
text = ''
<!DOCTYPE html>
<title>Darwin Configuration Options</title>
The nix-darwin documentation now requires nixpkgs 23.05 to build.
'';
};
manualHTMLIndex = "${manualHTML}/share/doc/darwin/index.html";
};
helpScript = pkgs.writeScriptBin "darwin-help"
''
#! ${pkgs.stdenv.shell} -e
open ${manual.manualHTMLIndex}
'';
in
{
options = {
documentation.enable = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc ''
Whether to install documentation of packages from
{option}`environment.systemPackages` into the generated system path.
See "Multiple-output packages" chapter in the nixpkgs manual for more info.
'';
# which is at ../../../doc/multiple-output.xml
};
documentation.man.enable = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc ''
Whether to install manual pages and the {command}`man` command.
This also includes "man" outputs.
'';
};
documentation.info.enable = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc ''
Whether to install info pages and the {command}`info` command.
This also includes "info" outputs.
'';
};
documentation.doc.enable = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc ''
Whether to install documentation distributed in packages' `/share/doc`.
Usually plain text and/or HTML.
This also includes "doc" outputs.
'';
};
};
config = mkIf cfg.enable {
programs.man.enable = cfg.man.enable;
programs.info.enable = cfg.info.enable;
environment.systemPackages = mkMerge [
(mkIf cfg.man.enable [ manual.manpages ])
(mkIf cfg.doc.enable [ manual.manualHTML helpScript ])
];
system.build.manual = manual;
};
}
|