1# Writing NixOS Documentation {#sec-writing-documentation}
2
3As NixOS grows, so too does the need for a catalogue and explanation of
4its extensive functionality. Collecting pertinent information from
5disparate sources and presenting it in an accessible style would be a
6worthy contribution to the project.
7
8## Building the Manual {#sec-writing-docs-building-the-manual}
9
10The DocBook sources of the [](#book-nixos-manual) are in the
11[`nixos/doc/manual`](https://github.com/NixOS/nixpkgs/tree/master/nixos/doc/manual)
12subdirectory of the Nixpkgs repository.
13
14You can quickly validate your edits with `make`:
15
16```ShellSession
17$ cd /path/to/nixpkgs/nixos/doc/manual
18$ nix-shell
19nix-shell$ make
20```
21
22Once you are done making modifications to the manual, it's important to
23build it before committing. You can do that as follows:
24
25```ShellSession
26nix-build nixos/release.nix -A manual.x86_64-linux
27```
28
29When this command successfully finishes, it will tell you where the
30manual got generated. The HTML will be accessible through the `result`
31symlink at `./result/share/doc/nixos/index.html`.
32
33## Editing DocBook XML {#sec-writing-docs-editing-docbook-xml}
34
35For general information on how to write in DocBook, see [DocBook 5: The
36Definitive Guide](http://www.docbook.org/tdg5/en/html/docbook.html).
37
38Emacs nXML Mode is very helpful for editing DocBook XML because it
39validates the document as you write, and precisely locates errors. To
40use it, see [](#sec-emacs-docbook-xml).
41
42[Pandoc](http://pandoc.org) can generate DocBook XML from a multitude of
43formats, which makes a good starting point. Here is an example of Pandoc
44invocation to convert GitHub-Flavoured MarkDown to DocBook 5 XML:
45
46```ShellSession
47pandoc -f markdown_github -t docbook5 docs.md -o my-section.md
48```
49
50Pandoc can also quickly convert a single `section.xml` to HTML, which is
51helpful when drafting.
52
53Sometimes writing valid DocBook is simply too difficult. In this case,
54submit your documentation updates in a [GitHub
55Issue](https://github.com/NixOS/nixpkgs/issues/new) and someone will
56handle the conversion to XML for you.
57
58## Creating a Topic {#sec-writing-docs-creating-a-topic}
59
60You can use an existing topic as a basis for the new topic or create a
61topic from scratch.
62
63Keep the following guidelines in mind when you create and add a topic:
64
65- The NixOS [`book`](http://www.docbook.org/tdg5/en/html/book.html)
66 element is in `nixos/doc/manual/manual.xml`. It includes several
67 [`parts`](http://www.docbook.org/tdg5/en/html/book.html) which are in
68 subdirectories.
69
70- Store the topic file in the same directory as the `part` to which it
71 belongs. If your topic is about configuring a NixOS module, then the
72 XML file can be stored alongside the module definition `nix` file.
73
74- If you include multiple words in the file name, separate the words
75 with a dash. For example: `ipv6-config.xml`.
76
77- Make sure that the `xml:id` value is unique. You can use abbreviations
78 if the ID is too long. For example: `nixos-config`.
79
80- Determine whether your topic is a chapter or a section. If you are
81 unsure, open an existing topic file and check whether the main
82 element is chapter or section.
83
84## Adding a Topic to the Book {#sec-writing-docs-adding-a-topic}
85
86Open the parent CommonMark file and add a line to the list of
87chapters with the file name of the topic that you created. If you
88created a `section`, you add the file to the `chapter` file. If you created
89a `chapter`, you add the file to the `part` file.
90
91If the topic is about configuring a NixOS module, it can be
92automatically included in the manual by using the `meta.doc` attribute.
93See [](#sec-meta-attributes) for an explanation.