NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.16k stars 14.19k forks source link

doc: Explain how to link to options in the manual #102246

Open nh2 opened 4 years ago

nh2 commented 4 years ago

I'm trying to write a release notes entry and spending an unjustified amount of time trying to make the hyperlink to a NixOS option documentation work.

I want to link to systemd.services.<name>.unitConfig.

Searching in the existing release notes code, I found repeated usage of at least the following patterns, out of which only one works:

Thus, only few people seem to know how to link to a NixOS option, so the manual is full of non-working links.

Proposed solution


CC a somwhat arbitrary list of contributers that might be interested/knowledgeable in this: @edolstra @jonringer @jtojnar @doronbehar

nh2 commented 4 years ago

I cannot figure out how https://github.com/NixOS/rfcs/pull/72 would affect or improve this.

In the example from there, the services.xserver.libinput.enable from the code listing links to the NixOS option correctly, but I don't know how they do it or where the sources for that are.

Can you tell me @mboes?

jonringer commented 4 years ago

A lot of this might change with the common mark rfc

jtojnar commented 4 years ago

DocBook elements have semantic definitions but not really a prescribed rendering. You can read their definitions in the DocBook documentation:

Yeah, according to the specification <option> is for command options and we are overloading the meaning. I guess <varname> is the most correct choice but <option> sounds a lot nicer so it gets used most often :woman_shrugging:

In the default stylesheet we use for rendering DocBook to HTML, the elements are simply rendered as <code> or something similar, with class attribute to distinguish them for styling with CSS. If we want links, we need to add them separately.

We render the Options appendix as <variablelist>. Each entry is assigned an xml:id generated from its name like this:

https://github.com/NixOS/nixpkgs/blob/eaaf9254aafe298dbb9168ac051738a820f644a6/nixos/lib/make-options-doc/options-to-docbook.xsl#L23

The ID then can be used across the whole document by either:

There are other options for linking, including a cross-document linking using olink but the two options above are the most relevant.

We could also add a rule to the stylesheet, that would linkify all <option>s that contain a string matching an existing NixOS option. Not sure how it would affect performance, though. A custom element would be easier in that regard since we could just replace it with <xref /> without any set up.

With the impending doom port to CommonMark, I am not sure if it is worth it to spend any time on this, though.

FRidh commented 3 years ago

I cannot figure out how NixOS/rfcs#72 would affect or improve this.

In the example from there, the services.xserver.libinput.enable from the code listing links to the NixOS option correctly, but I don't know how they do it or where the sources for that are.

Can you tell me @mboes?

I found the link to the sources https://github.com/NixOS/rfcs/pull/72#issuecomment-738901308. As mentioned there, only a single file was markdown, the rest was actually the result of a docbook to restructuredtext conversion. Restructuredtext has a lot more metadata.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

jonringer commented 3 years ago

the 21.11 release notes will be written in markdown. Going to close as linking to options (at least in context of dockbook) is no longer relevant.

jtojnar commented 3 years ago

We still need to link to options and I have seen someone suggest the incorrect syntax on Matrix yesterday.

Currently, it is [`enable`](#opt-services.xserver.libinput.enable) for options with custom label and <xref linkend="opt-services.xserver.libinput.enable"/> for automatic label. Using the anchor format is important since otherwise (e.g. using options.html#hash) will cause the link not to be checked.

Linking options in submodules also is not trivial (replace <, > and * for _ in the anchor). Or just copy the anchor from the option link on the options page.

Eventually, I want to use empty links for the automatic anchors (e.g. [](#opt-services.xserver.libinput.enable)), which has precedent in MyST but we are not there yet.

nixos-discourse commented 2 years ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2022-10-22-documentation-team-meeting-notes-12-nixcon-edition/22689/1