Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Doxygen Docs for Nixpkgs Internals #34558

Closed
wants to merge 13 commits into from

Conversation

lukeadams
Copy link
Contributor

@lukeadams lukeadams commented Feb 3, 2018

Motivation for this change

This PR demonstrates a low friction way to autogenerate documentation for Nixpkgs lib functions.
Doxygen does a pretty decent job picking up the correct function name (although it thinks they are variables) under the C++ generator.

A demo can be seen here.

I haven't converted all of strings.nix, but the functions with code-formatted examples have been converted.
screen shot 2018-02-03 at 9 50 08 am

TODO

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@FRidh
Copy link
Member

FRidh commented Feb 3, 2018

Very nice! I have a personal preference for Sphinx, but regardless I think this is very good to have and we should get this in. I wonder though what others think of changing the format of the docstrings.

@grahamc
Copy link
Member

grahamc commented Feb 3, 2018

(I added the python tag to check a hypothesis w.r.t. the incorrect label added by ofborg. I'll remove it shortly, sorry for the noise)

@GrahamcOfBorg eval

@vcunat
Copy link
Member

vcunat commented Feb 3, 2018

I had thought about this long ago, but I didn't realize it could work to use a different language ❤️

Sphinx takes data via doxygen, at least in projects I know about.

@lukeadams
Copy link
Contributor Author

@FRidh I totally agree! Sphinx definitely has a nicer looking theme by default. Doxygen lets you create a custom template, so I was thinking of mimicking the NixOS.org styling. I've got the header on the demo page here.

@vcunat Sort of a happy accident that it works since Doxygen is in c++ mode. Other modes may work better, although the "best" would be to write a Nix language definition. Glad you like it!

@FRidh
Copy link
Member

FRidh commented Feb 6, 2018

Sphinx takes data via doxygen, at least in projects I know about.

Right. That's still an option then.

@lukeadams could you look how to integrate this in the Nixpkgs manual? Doxygen supports docbook output. http://doxygen.nl/manual/config.html#cfg_generate_docbook

When we have that available, we could consider looking further than just lib, like also the trivial-builders and shell scripts like makeWrapper.

@FRidh FRidh added this to the 18.03 milestone Feb 6, 2018
@lukeadams lukeadams changed the title Doxygen Docs for Nixpkgs Internals [WIP] Doxygen Docs for Nixpkgs Internals Feb 8, 2018
@lukeadams
Copy link
Contributor Author

@FRidh With that option enabled, I just have to add Doxygen generation to doc/default.nix and tell the docstring builder to look at its output.

I've now labelled strings.nix as a member of lib so it shows up here. All functions in other files will show up there as long as they are marked as members of lib. I'm not sure how to get Doxygen to generate docs from .sh files, but it would be trivial to create a markdown file for each one and document it that way

@lukeadams
Copy link
Contributor Author

(Sorta) got it linked into the manual here.

Needs some massaging to make it look good though.

@lexleogryfon
Copy link

I've been looking for such documentation and happy that someone finally commits to writing it.
All Nixpkgs builtin functions should have clear API documentation reference like standard libraries in other languages, specifying type of arguments, type of return, usage example. Syntax highlight would be nice.
Will appreciate to see project alive and completed, even if it will not be merged yet to master.

@oxij
Copy link
Member

oxij commented Feb 10, 2018 via email

@lukeadams
Copy link
Contributor Author

lukeadams commented Feb 10, 2018

@oxij I'll look into it! Doxygen was just for proof of concept since I was already familiar with it.
I agree – Javadoc is obscenely verbose (but works well when using non D-gen supported languages for the same reason).

Oh yeah not sure if you noticed but in many cases I had to wrap lib code with /** @cond EXCLUDE */ as Doxygen would get confused by the syntax, which adds a source of potential document breakage if changes are made to lib functions. The whole thing is messy.

@lukeadams
Copy link
Contributor Author

lukeadams commented Feb 12, 2018

@FRidh Honestly I think Sphinx would be the best option with a custom domain (link up top) which would add Nix support to it. Additionally, the inbuilt sphinx.Napoleon extension supports a docstring style similar to what we already have in-tree. Doxygen requires too much hacking to work reliably and its Docbook output requires quite a bit of massaging to embed in the manual.

Thoughts?

@vcunat vcunat removed this from the 18.03 milestone Feb 13, 2018
@lukeadams
Copy link
Contributor Author

lukeadams commented Jul 17, 2018

I'm going to close this as I no longer have the time to work on it.
May pursue it in the future by using the Nix Lex/Yacc {see parser.y, lexer.l} parser to write a frontend for Sphinx, or maybe create a standalone tool "NixDoc" in the same vein as rustdoc

@lukeadams lukeadams closed this Jul 17, 2018
@lukeadams lukeadams deleted the doxygen-nixpkgs branch May 26, 2021 21:50
@lukeadams lukeadams restored the doxygen-nixpkgs branch May 26, 2021 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants