summaryrefslogtreecommitdiffstats
path: root/manpage.nix
diff options
context:
space:
mode:
Diffstat (limited to 'manpage.nix')
-rw-r--r--manpage.nix136
1 files changed, 136 insertions, 0 deletions
diff --git a/manpage.nix b/manpage.nix
new file mode 100644
index 0000000..bea6b25
--- /dev/null
+++ b/manpage.nix
@@ -0,0 +1,136 @@
1{ outputAttrPath, optionsAttrPath, optionsInternal ? true, }:
2
3{ config, lib, pkgs, ... }:
4
5with lib;
6
7let
8 cfg = getAttrFromPath (optionsAttrPath ++ [ "manpage" ]) config;
9in
10{
11 options = setAttrByPath optionsAttrPath {
12 manpage = {
13 name = mkOption {
14 type = types.str;
15 description = ''
16 Name of the generated manpage.
17 '';
18 internal = optionsInternal;
19 };
20
21 shortDescription = mkOption {
22 type = types.str;
23 description = ''
24 A short description of the generated manpage.
25 '';
26 internal = optionsInternal;
27 };
28
29 description = mkOption {
30 type = with types; nullOr lines;
31 description = ''
32 A long description of the generated manpage.
33 '';
34 default = null;
35 internal = optionsInternal;
36 };
37
38 section = mkOption {
39 type = types.int;
40 default = 5;
41 description = ''
42 The section number for the generated manpage.
43
44 The table below shows the section numbers of the manual followed by the types of pages they contain.
45
46 1. Executable programs or shell commands
47 2. System calls (functions provided by the kernel)
48 3. Library calls (functions within program libraries)
49 4. Special files (usually found in /dev)
50 5. File formats and conventions, e.g. /etc/passwd
51 6. Games
52 7. Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
53 8. System administration commands (usually only for root)
54 9. Kernel routines [Non standard]
55 '';
56 internal = optionsInternal;
57 };
58
59 file = mkOption {
60 type = types.str;
61 description = ''
62 The file containing the generated manpage.
63 '';
64 default = "${strings.sanitizeDerivationName cfg.name}.${toString cfg.section}";
65 defaultText = "\${lib.strings.sanitizeDerivationName cfg.name}.\${toString cfg.section}";
66 internal = optionsInternal;
67 };
68
69 title = mkOption {
70 type = types.str;
71 default = "${toUpper (strings.sanitizeDerivationName cfg.name)}(${toString cfg.section})";
72 defaultText = "\${toUpper cfg.name}(\${toString cfg.section})";
73 description = ''
74 Title of the generated manpage.
75 '';
76 internal = optionsInternal;
77 };
78
79 textBefore = mkOption {
80 type = types.lines;
81 description = ''
82 Some text to insert before the list of options.
83 '';
84 default = "";
85 internal = optionsInternal;
86 };
87
88 textAfter = mkOption {
89 type = types.lines;
90 description = ''
91 Some text to insert after the list of options.
92 '';
93 default = "";
94 internal = optionsInternal;
95 };
96
97 };
98 };
99
100 config = setAttrByPath outputAttrPath {
101 manpage = pkgs.runCommand cfg.file
102 {
103 src = pkgs.writeText "${cfg.file}.md" ''
104 % ${cfg.title}
105
106 # NAME
107
108 ${cfg.name} - ${cfg.shortDescription}
109
110
111 ${optionalString (cfg.description != null) ''
112 # DESCRIPTION
113
114 ${cfg.description}
115 ''}
116
117
118 ${cfg.textBefore}
119
120
121 # OPTIONS
122
123 You can use the following options:
124
125 ${readFile (getAttrFromPath (outputAttrPath ++ ["doc-options-md"]) config)}
126
127
128 ${cfg.textAfter}
129 '';
130
131 nativeBuildInputs = [ pkgs.pandoc ];
132 } ''
133 pandoc "$src" --from=markdown --to=man --standalone --output="$out"
134 '';
135 };
136}