Nixpkgs Library Function Documentation, Doc Tests


#1

Hey everyone,

Over the past couple weeks I have made some major progress in documenting the Nixpkgs standard library functions. It is slow work, but thus far I’ve added web-facing documentation for over 25 functions. I’m working on roughly one each day. In addition to adding these to the public docs, each documented function has a link to where its source can be found on GitHub. I encourage you to check out my progress: https://nixos.org/nixpkgs/manual/#sec-functions-library

However, this post is really more of a request for feedback. I found a fairly simple way to automatically test the docs too! It only took 50 lines of python to make a demo, and a bit over 100 lines to make a nice UX for the tool. Check it out over on my PR https://github.com/NixOS/nixpkgs/pull/48497

What do you think? Are these docs satisfying the need for a reference manual? Are these doc tests valuable?


#2

Great. Yes. Yes.

I was just excitedly talking to my co-worker about your work on documenting the nixpkgs standard library. I like doc tests, because they also can serve as examples for how to use the functions. I usually search through the nixpkgs source for example usages; I expect having some in the manual will be more accessible.


#3

About 3 years ago I first tried using NixOS and ultimately failed because I got lost in the documentation. Now trying NixOS about 6 months ago the situation has really changed and I’m hooked. I have to say thank you for emphasizing documentation!


#4

This is a welcome addition. While these functions are already properly documented in source files, having a central point for this documentation will certainly be useful.

Maybe we can help with this, to speed up the process? After all, the library functions are mostly simple and easy to understand.


#5

However, what I would like to see much more is documentation on pkgs functions. It can be really difficult to find out what they do, and how to properly use them!


#6

grahamc,

Thank you for your work on this. Documenting standard functions like this is really appreciated!


#7

Very cool! I’ve been hacking on a tool that I call nixdoc which can read the files in nixpkgs/lib and generate DocBook XML from them.

This already sort of works, but there are a few additional things that I’d like to add before looking into how to actually put it to use automatically.

Currently the doc comments contain significantly less information than what Graham has been writing manually, but I think it would be nice if the doc comments actually had that level of detail.

Check out this example for docs generated from strings.nix. If anybody wants to hack on this on the NixCon Hackday, ping me!

Edit: Progressing nicely, function arguments are now included, as are links to definition locations in the nixpkgs sources.


#8

@tazjin what’s the difference between your approach and @grahamc’s? Is @grahamc’s manual?


#9

He is generating the docs directly from the comments by converting the nix AST tree. Graham put in a lot of elbow grease instead.


#10

Is the plan to include this in the nixpkgs manual page at some point? That would be really awesome :slight_smile:


#11

@grahamc thanks for doing this. This documentation in particular is of great value.


#12

This made me think, is there a Nix repl available via an online evaluator in the style of https://repl.it/languages ? Having those examples with a link to play with them in an online evaluator, or inline, would be pretty nice for newcomers.


#13

Yes, there is https://nixcloud.io/tour/ which essentially compiles nix to javascript via emscripten.