nix-community / nixdoc

Tool to generate documentation for Nix library functions [maintainer=@infinisil]
GNU General Public License v3.0
119 stars 14 forks source link

Export function location #128

Open infinisil opened 1 month ago

infinisil commented 1 month ago

Nixpkgs currently uses some hacky Nix code to figure out the locations of functions, when nixdoc would have a really easy time to export this information, which would then allow removing the hacks.

hsjobeki commented 1 month ago

A 100% correct solution needs access to the evaluator and the ast including the comments.

(At least i am not aware how a generic solution that doesnt predict the structure of i.e. nixpkgs/lib/*.nix files)

A solution that works with "file convention" may work with static analysis only. But nixpkgs isnt that strict (yet).

An example:

let
  /** Documentation is here */
  result = { myFunction = x: x; };
in
 mapAttrs' (name: value: nameValuePair ("foo_" + name) value ) result

In nixpkgs we sometimes have wrapping functions, and sometimes we dynamically create the binding.