1 # Contributing to the Nixpkgs reference manual
3 This directory houses the sources files for the Nixpkgs reference manual.
5 Going forward, it should only contain [reference](https://nix.dev/contributing/documentation/diataxis#reference) documentation.
6 For tutorials, guides and explanations, contribute to <https://nix.dev/> instead.
8 For documentation only relevant for contributors, use Markdown files and code comments in the source code.
10 Rendered documentation:
11 - [Unstable (from master)](https://nixos.org/manual/nixpkgs/unstable/)
12 - [Stable (from latest release)](https://nixos.org/manual/nixpkgs/stable/)
14 The rendering tool is [nixos-render-docs](../pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs), sometimes abbreviated `nrd`.
16 ## Contributing to this documentation
18 You can quickly check your edits with `nix-build`:
25 If the build succeeds, the manual will be in `./result/share/doc/nixpkgs/manual.html`.
29 The shell in the manual source directory makes available a command, `devmode`.
31 1. watches the manual's source for changes and when they occur — rebuilds
32 2. HTTP serves the manual, injecting a script that triggers reload on changes
33 3. opens the manual in the default browser
37 As per [RFC 0072](https://github.com/NixOS/rfcs/pull/72), all new documentation content should be written in [CommonMark](https://commonmark.org/) Markdown dialect.
39 Additional syntax extensions are available, all of which can be used in NixOS option documentation. The following extensions are currently used:
43 Tables, using the [GitHub-flavored Markdown syntax](https://github.github.com/gfm/#tables-extension-).
47 Explicitly defined **anchors** on headings, to allow linking to sections. These should be always used, to ensure the anchors can be linked even when the heading text changes, and to prevent conflicts between [automatically assigned identifiers](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/auto_identifiers.md).
49 It uses the widely compatible [header attributes](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/attributes.md) syntax:
52 ## Syntax {#sec-contributing-markup}
56 > NixOS option documentation does not support headings in general.
60 Allow linking arbitrary place in the text (e.g. individual list items, sentences…).
62 They are defined using a hybrid of the link syntax with the attributes syntax known from headings, called [bracketed spans](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/bracketed_spans.md):
65 - []{#ssec-gnome-hooks-glib} `glib` setup hook will populate `GSETTINGS_SCHEMAS_PATH` and then `wrapGApps*` hook will prepend it to `XDG_DATA_DIRS`.
70 If you **omit a link text** for a link pointing to a section, the text will be substituted automatically. For example `[](#chap-contributing)`.
72 This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/using/syntax.html#targets-and-cross-referencing).
77 Inlining HTML is not allowed. Parts of the documentation gets rendered to various non-HTML formats, such as man pages in the case of NixOS manual.
81 If you want to link to a man page, you can use `` {manpage}`nix.conf(5)` ``. The references will turn into links when a mapping exists in [`doc/manpage-urls.json`](./manpage-urls.json).
83 A few markups for other kinds of literals are also available:
85 - `` {command}`rm -rfi` ``
86 - `` {env}`XDG_DATA_DIRS` ``
87 - `` {file}`/etc/passwd` ``
88 - `` {option}`networking.useDHCP` ``
89 - `` {var}`/etc/passwd` ``
91 These literal kinds are used mostly in NixOS option documentation.
93 This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html#roles-an-in-line-extension-point). Though, the feature originates from [reStructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-manpage) with slightly different syntax.
97 Set off from the text to bring attention to something.
99 It uses pandoc’s [fenced `div`s syntax](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/fenced_divs.md):
107 The following are supported:
116 Example admonitions require a title to work.
117 If you don't provide one, the manual won't be built.
120 ::: {.example #ex-showing-an-example}
122 # Title for this example
124 Text for the example.
128 #### [Definition lists](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/definition_lists.md)
130 For defining a group of terms:
134 : green or yellow bulbous fruit
137 : green fruit with red flesh
140 ## Commit conventions
142 - Make sure you read about the [commit conventions](../CONTRIBUTING.md#commit-conventions) common to Nixpkgs as a whole.
144 - If creating a commit purely for documentation changes, format the commit message in the following way:
147 doc: (documentation summary)
149 (Motivation for change, relevant links, additional information.)
154 * doc: update the kernel config documentation to use `nix-shell`
155 * doc: add information about `nix-update-script`
159 - If the commit contains more than just documentation changes, follow the commit message format relevant for the rest of the changes.
161 ## Documentation conventions
163 In an effort to keep the Nixpkgs manual in a consistent style, please follow the conventions below, unless they prevent you from properly documenting something.
164 In that case, please open an issue about the particular documentation convention and tag it with a "needs: documentation" label.
165 When needed, each convention explain why it exists, so you can make a decision whether to follow it or not based on your particular case.
166 Note that these conventions are about the **structure** of the manual (and its source files), not about the content that goes in it.
167 You, as the writer of documentation, are still in charge of its content.
169 - Put each sentence in its own line.
170 This makes reviews and suggestions much easier, since GitHub's review system is based on lines.
171 It also helps identifying long sentences at a glance.
173 - Use the [admonition syntax](#admonitions) for callouts and examples.
175 - Provide at least one example per function, and make examples self-contained.
176 This is easier to understand for beginners.
177 It also helps with testing that it actually works – especially once we introduce automation.
179 Example code should be such that it can be passed to `pkgs.callPackage`.
180 Instead of something like:
183 pkgs.dockerTools.buildLayeredImage {
185 contents = [ pkgs.hello ];
189 Write something like:
192 { dockerTools, hello }:
193 dockerTools.buildLayeredImage {
195 contents = [ hello ];
199 - When showing inputs/outputs of any [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop), such as a shell or the Nix REPL, use a format as you'd see in the REPL, while trying to visually separate inputs from outputs.
200 This means that for a shell, you should use a format like the following:
202 $ nix-build -A hello '<nixpkgs>' \
203 --option require-sigs false \
204 --option trusted-substituters file:///tmp/hello-cache \
205 --option substituters file:///tmp/hello-cache
206 /nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1
208 Note how the input is preceded by `$` on the first line and indented on subsequent lines, and how the output is provided as you'd see on the shell.
210 For the Nix REPL, you should use a format like the following:
212 nix-repl> builtins.attrNames { a = 1; b = 2; }
215 Note how the input is preceded by `nix-repl>` and the output is provided as you'd see on the Nix REPL.
217 - When documenting functions or anything that has inputs/outputs and example usage, use nested headings to clearly separate inputs, outputs, and examples.
218 Keep examples as the last nested heading, and link to the examples wherever applicable in the documentation.
220 The purpose of this convention is to provide a familiar structure for navigating the manual, so any reader can expect to find content related to inputs in an "inputs" heading, examples in an "examples" heading, and so on.
225 Some explanation about the function here.
226 Describe a particular scenario, and point to [](#ex-dockerTools-buildImage), which is an example demonstrating it.
230 Documentation for the inputs of `buildImage`.
231 Perhaps even point to [](#ex-dockerTools-buildImage) again when talking about something specifically linked to it.
235 Documentation for any passthru outputs of `buildImage`.
239 Note that this is the last nested heading in the `buildImage` section.
241 :::{.example #ex-dockerTools-buildImage}
245 Example of how to use `buildImage` goes here.
250 - Use [definition lists](#definition-lists) to document function arguments, and the attributes of such arguments as well as their [types](https://nixos.org/manual/nix/stable/language/values).
254 # pkgs.coolFunction {#pkgs.coolFunction}
256 `pkgs.coolFunction` *`name`* *`config`*
258 Description of what `callPackage` does.
261 ## Inputs {#pkgs-coolFunction-inputs}
263 If something's special about `coolFunction`'s general argument handling, you can say so here.
264 Otherwise, just describe the single argument or start the arguments' definition list without introduction.
268 : The name of the resulting image.
270 *`config`* (Attribute set)
272 : Introduce the parameter. Maybe you have a test to make sure `{ }` is a sensible default; then you can say: these attributes are optional; `{ }` is a valid argument.
274 `outputHash` (String; _optional_)
276 : A brief explanation including when and when not to pass this attribute.
278 : _Default:_ the output path's hash.
282 - Start with a synopsis, to show the order of positional arguments.
283 - Metavariables are in emphasized code spans: ``` *`arg1`* ```. Metavariables are placeholders where users may write arbitrary expressions. This includes positional arguments.
284 - Attribute names are regular code spans: ``` `attr1` ```. These identifiers can _not_ be picked freely by users, so they are _not_ metavariables.
285 - _optional_ attributes have a _`Default:`_ if it's easily described as a value.
286 - _optional_ attributes have a _`Default behavior:`_ if it's not easily described using a value.
287 - Nix types aren't in code spans, because they are not code
288 - Nix types are capitalized, to distinguish them from the camelCase Module System types, which _are_ code and behave like functions.
292 To define a referenceable figure use the following fencing:
295 :::{.example #an-attribute-set-example}
296 # An attribute set example
298 You can add text before
304 and after code fencing
308 Defining examples through the `example` fencing class adds them to a "List of Examples" section after the Table of Contents.
309 Though this is not shown in the rendered documentation on nixos.org.
313 To define a referenceable figure use the following fencing:
316 ::: {.figure #nixos-logo}
318 ![NixOS logo](./nixos_logo.png)
322 Defining figures through the `figure` fencing class adds them to a `List of Figures` after the `Table of Contents`.
323 Though this is not shown in the rendered documentation on nixos.org.
327 To add a foonote explanation, use the following syntax:
330 Sometimes it's better to add context [^context] in a footnote.
332 [^context]: This explanation will be rendered at the end of the chapter.
337 Inline comments are supported with following syntax:
340 <!-- This is an inline comment -->
343 The comments will not be rendered in the rendered HTML.
345 #### Link reference definitions
347 Links can reference a label, for example, to make the link target reusable:
351 Reference links can also be used to [shorten URLs][url-id] and keep the markdown readable.
354 [url-id]: https://github.com/NixOS/nixpkgs/blob/19d4f7dc485f74109bd66ef74231285ff797a823/doc/README.md
357 This syntax is taken from [CommonMark](https://spec.commonmark.org/0.30/#link-reference-definitions).
359 #### Typographic replacements
361 Typographic replacements are enabled. Check the [list of possible replacement patterns check](https://github.com/executablebooks/markdown-it-py/blob/3613e8016ecafe21709471ee0032a90a4157c2d1/markdown_it/rules_core/replacements.py#L1-L15).
365 If you need documentation-specific help or reviews, ping [@NixOS/documentation-team](https://github.com/orgs/nixos/teams/documentation-team) on your pull request.