1# Contributing to this manual {#chap-contributing} 2 3The sources of the NixOS manual are in the [nixos/doc/manual](https://github.com/NixOS/nixpkgs/tree/master/nixos/doc/manual) subdirectory of the [Nixpkgs](https://github.com/NixOS/nixpkgs) repository. 4This manual uses the [Nixpkgs manual syntax](https://nixos.org/manual/nixpkgs/unstable/#sec-contributing-markup). 5 6You can quickly check your edits with the following: 7 8```ShellSession 9$ cd /path/to/nixpkgs 10$ $EDITOR doc/nixos/manual/... # edit the manual 11$ nix-build nixos/release.nix -A manual.x86_64-linux 12``` 13 14If the build succeeds, the manual will be in `./result/share/doc/nixos/index.html`. 15 16There's also [a convenient development daemon](https://nixos.org/manual/nixpkgs/unstable/#sec-contributing-devmode). 17 18The above instructions don't deal with the appendix of available `configuration.nix` options, and the manual pages related to NixOS. These are built, and written in a different location and in a different format, as explained in the next sections. 19 20## Development environment {#sec-contributing-development-env} 21 22In order to reduce repetition, consider using tools from the provided development environment: 23 24Load it from the NixOS documentation directory with 25 26```ShellSession 27$ cd /path/to/nixpkgs/nixos/doc/manual 28$ nix-shell 29``` 30 31To load the development utilities automatically when entering that directory, [set up `nix-direnv`](https://nix.dev/guides/recipes/direnv). 32 33Make sure that your local files aren't added to Git history by adding the following lines to `.git/info/exclude` at the root of the Nixpkgs repository: 34 35``` 36/**/.envrc 37/**/.direnv 38``` 39 40### `devmode` {#sec-contributing-devmode} 41 42Use [`devmode`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/de/devmode/README.md) for a live preview when editing the manual. 43 44## Testing redirects {#sec-contributing-redirects} 45 46Once you have a successful build, you can open the relevant HTML (path mentioned above) in a browser along with the anchor, and observe the redirection. 47 48Note that if you already loaded the page and *then* input the anchor, you will need to perform a reload. This is because browsers do not re-run client JS code when only the anchor has changed. 49 50## Contributing to the `configuration.nix` options documentation {#sec-contributing-options} 51 52The documentation for all the different `configuration.nix` options is automatically generated by reading the `description`s of all the NixOS options defined at `nixos/modules/`. If you want to improve such `description`, find it in the `nixos/modules/` directory, and edit it and open a pull request. 53 54To see how your changes render on the web, run again: 55 56```ShellSession 57$ nix-build nixos/release.nix -A manual.x86_64-linux 58``` 59 60And you'll see the changes to the appendix in the path `result/share/doc/nixos/options.html`. 61 62You can also build only the `configuration.nix(5)` manual page, via: 63 64```ShellSession 65$ cd /path/to/nixpkgs 66$ nix-build nixos/release.nix -A nixos-configuration-reference-manpage.x86_64-linux 67``` 68 69And observe the result via: 70 71```ShellSession 72$ man --local-file result/share/man/man5/configuration.nix.5 73``` 74 75If you're on a different architecture that's supported by NixOS (check file `nixos/release.nix` on Nixpkgs' repository) then replace `x86_64-linux` with the architecture. `nix-build` will complain otherwise, but should also tell you which architecture you have + the supported ones. 76 77## Contributing to `nixos-*` tools' manpages {#sec-contributing-nixos-tools} 78 79The manual pages for the tools available in the installation image can be found in Nixpkgs by running (e.g for `nixos-rebuild`): 80 81```ShellSession 82$ git ls | grep nixos-rebuild.8 83``` 84 85Man pages are written in [`mdoc(7)` format](https://mandoc.bsd.lv/man/mdoc.7.html) and should be portable between mandoc and groff for rendering (except for minor differences, notably different spacing rules.) 86 87For a preview, run `man --local-file path/to/file.8`. 88 89Being written in `mdoc`, these manpages use semantic markup. This following subsections provides a guideline on where to apply which semantic elements. 90 91### Command lines and arguments {#ssec-contributing-nixos-tools-cli-and-args} 92 93In any manpage, commands, flags and arguments to the *current* executable should be marked according to their semantics. Commands, flags and arguments passed to *other* executables should not be marked like this and should instead be considered as code examples and marked with `Ql`. 94 95- Use `Fl` to mark flag arguments, `Ar` for their arguments. 96- Repeating arguments should be marked by adding an ellipsis (spelled with periods, `...`). 97- Use `Cm` to mark literal string arguments, e.g. the `boot` command argument passed to `nixos-rebuild`. 98- Optional flags or arguments should be marked with `Op`. This includes optional repeating arguments. 99- Required flags or arguments should not be marked. 100- Mutually exclusive groups of arguments should be enclosed in curly brackets, preferably created with `Bro`/`Brc` blocks. 101 102When an argument is used in an example it should be marked up with `Ar` again to differentiate it from a constant. For example, a command with a `--host name` option that calls ssh to retrieve the host's local time would signify this thusly: 103``` 104This will run 105.Ic ssh Ar name Ic time 106to retrieve the remote time. 107``` 108 109### Paths, NixOS options, environment variables {#ssec-contributing-nixos-tools-options-and-environment} 110 111Constant paths should be marked with `Pa`, NixOS options with `Va`, and environment variables with `Ev`. 112 113Generated paths, e.g. `result/bin/run-hostname-vm` (where `hostname` is a variable or arguments) should be marked as `Ql` inline literals with their variable components marked appropriately. 114 115 - When `hostname` refers to an argument, it becomes `.Ql result/bin/run- Ns Ar hostname Ns -vm` 116 - When `hostname` refers to a variable, it becomes `.Ql result/bin/run- Ns Va hostname Ns -vm` 117 118### Code examples and other commands {#ssec-contributing-nixos-tools-code-examples} 119 120In free text names and complete invocations of other commands (e.g. `ssh` or `tar -xvf src.tar`) should be marked with `Ic`, fragments of command lines should be marked with `Ql`. 121 122Larger code blocks or those that cannot be shown inline should use indented literal display block markup for their contents, i.e. 123 124``` 125.Bd -literal -offset indent 126... 127.Ed 128``` 129 130Contents of code blocks may be marked up further, e.g. if they refer to arguments that will be substituted into them: 131 132``` 133.Bd -literal -offset indent 134{ 135 config.networking.hostname = "\c 136.Ar hostname Ns \c 137"; 138} 139.Ed 140```